@commercetools/ts-client 3.2.2 → 3.3.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 +12 -0
- package/dist/commercetools-ts-client.browser.cjs.js +24 -10
- package/dist/commercetools-ts-client.browser.esm.js +24 -11
- package/dist/commercetools-ts-client.cjs.dev.js +24 -10
- package/dist/commercetools-ts-client.cjs.prod.js +24 -10
- package/dist/commercetools-ts-client.esm.js +24 -11
- package/dist/commercetools-ts-client.umd.js +1 -1
- package/dist/declarations/src/client/builder.d.ts +3 -1
- package/dist/declarations/src/client/builder.d.ts.map +1 -1
- package/dist/declarations/src/client/client.d.ts +1 -1
- package/dist/declarations/src/client/client.d.ts.map +1 -1
- package/dist/declarations/src/index.d.ts +1 -1
- package/dist/declarations/src/index.d.ts.map +1 -1
- package/dist/declarations/src/middleware/create-error-middleware.d.ts.map +1 -1
- package/dist/declarations/src/types/types.d.ts +29 -9
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @commercetools/ts-client
|
|
2
2
|
|
|
3
|
+
## 3.3.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#1066](https://github.com/commercetools/commercetools-sdk-typescript/pull/1066) [`3d61678`](https://github.com/commercetools/commercetools-sdk-typescript/commit/3d61678549f5a77690b330fac0b28012acbfbfb0) Thanks [@ajimae](https://github.com/ajimae)! - Improve typescript types definitions
|
|
8
|
+
|
|
9
|
+
## 3.3.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [#1044](https://github.com/commercetools/commercetools-sdk-typescript/pull/1044) [`29967a3`](https://github.com/commercetools/commercetools-sdk-typescript/commit/29967a3e5957bd2fc35d90ad95d8e8f2917565e4) Thanks [@ajimae](https://github.com/ajimae)! - add error handler middleware
|
|
14
|
+
|
|
3
15
|
## 3.2.2
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -909,21 +909,27 @@ function createCorrelationIdMiddleware$1(options) {
|
|
|
909
909
|
};
|
|
910
910
|
}
|
|
911
911
|
|
|
912
|
-
function createErrorMiddleware(options) {
|
|
912
|
+
function createErrorMiddleware$1(options = {}) {
|
|
913
913
|
return next => async request => {
|
|
914
914
|
const response = await next(request);
|
|
915
915
|
if (response.error) {
|
|
916
916
|
const {
|
|
917
917
|
error
|
|
918
918
|
} = response;
|
|
919
|
+
if (options.handler && typeof options.handler == 'function') {
|
|
920
|
+
return options.handler({
|
|
921
|
+
error,
|
|
922
|
+
request,
|
|
923
|
+
response,
|
|
924
|
+
next
|
|
925
|
+
});
|
|
926
|
+
}
|
|
919
927
|
return {
|
|
920
928
|
...response,
|
|
921
929
|
statusCode: error.statusCode || 0,
|
|
922
930
|
headers: error.headers || getHeaders({}),
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
body: error.data || error
|
|
926
|
-
}
|
|
931
|
+
body: error,
|
|
932
|
+
error
|
|
927
933
|
};
|
|
928
934
|
}
|
|
929
935
|
return response;
|
|
@@ -1169,7 +1175,7 @@ function createQueueMiddleware$1({
|
|
|
1169
1175
|
|
|
1170
1176
|
var packageJson = {
|
|
1171
1177
|
name: "@commercetools/ts-client",
|
|
1172
|
-
version: "3.
|
|
1178
|
+
version: "3.3.1",
|
|
1173
1179
|
engines: {
|
|
1174
1180
|
node: ">=18"
|
|
1175
1181
|
},
|
|
@@ -1217,9 +1223,9 @@ var packageJson = {
|
|
|
1217
1223
|
},
|
|
1218
1224
|
devDependencies: {
|
|
1219
1225
|
"common-tags": "1.8.2",
|
|
1220
|
-
dotenv: "16.
|
|
1226
|
+
dotenv: "16.5.0",
|
|
1221
1227
|
jest: "29.7.0",
|
|
1222
|
-
nock: "14.0.
|
|
1228
|
+
nock: "14.0.4",
|
|
1223
1229
|
"organize-imports-cli": "0.10.0"
|
|
1224
1230
|
},
|
|
1225
1231
|
scripts: {
|
|
@@ -1256,7 +1262,7 @@ var middleware = /*#__PURE__*/Object.freeze({
|
|
|
1256
1262
|
createAuthMiddlewareForRefreshTokenFlow: createAuthMiddlewareForRefreshTokenFlow$1,
|
|
1257
1263
|
createConcurrentModificationMiddleware: createConcurrentModificationMiddleware$1,
|
|
1258
1264
|
createCorrelationIdMiddleware: createCorrelationIdMiddleware$1,
|
|
1259
|
-
createErrorMiddleware: createErrorMiddleware,
|
|
1265
|
+
createErrorMiddleware: createErrorMiddleware$1,
|
|
1260
1266
|
createHttpMiddleware: createHttpMiddleware$1,
|
|
1261
1267
|
createLoggerMiddleware: createLoggerMiddleware$1,
|
|
1262
1268
|
createQueueMiddleware: createQueueMiddleware$1,
|
|
@@ -1427,7 +1433,8 @@ const {
|
|
|
1427
1433
|
createLoggerMiddleware,
|
|
1428
1434
|
createQueueMiddleware,
|
|
1429
1435
|
createUserAgentMiddleware,
|
|
1430
|
-
createConcurrentModificationMiddleware
|
|
1436
|
+
createConcurrentModificationMiddleware,
|
|
1437
|
+
createErrorMiddleware
|
|
1431
1438
|
} = middleware;
|
|
1432
1439
|
class ClientBuilder {
|
|
1433
1440
|
constructor() {
|
|
@@ -1442,6 +1449,7 @@ class ClientBuilder {
|
|
|
1442
1449
|
_defineProperty(this, "telemetryMiddleware", void 0);
|
|
1443
1450
|
_defineProperty(this, "beforeMiddleware", void 0);
|
|
1444
1451
|
_defineProperty(this, "afterMiddleware", void 0);
|
|
1452
|
+
_defineProperty(this, "errorMiddleware", void 0);
|
|
1445
1453
|
_defineProperty(this, "middlewares", []);
|
|
1446
1454
|
this.userAgentMiddleware = createUserAgentMiddleware({});
|
|
1447
1455
|
}
|
|
@@ -1469,6 +1477,10 @@ class ClientBuilder {
|
|
|
1469
1477
|
this.middlewares.push(middleware);
|
|
1470
1478
|
return this;
|
|
1471
1479
|
}
|
|
1480
|
+
withErrorMiddleware(options) {
|
|
1481
|
+
this.errorMiddleware = createErrorMiddleware(options);
|
|
1482
|
+
return this;
|
|
1483
|
+
}
|
|
1472
1484
|
withClientCredentialsFlow(options) {
|
|
1473
1485
|
return this.withAuthMiddleware(createAuthMiddlewareForClientCredentialsFlow({
|
|
1474
1486
|
host: options.host || CTP_AUTH_URL,
|
|
@@ -1597,6 +1609,7 @@ class ClientBuilder {
|
|
|
1597
1609
|
if (this.telemetryMiddleware) middlewares.push(this.telemetryMiddleware);
|
|
1598
1610
|
if (this.correlationIdMiddleware) middlewares.push(this.correlationIdMiddleware);
|
|
1599
1611
|
if (this.userAgentMiddleware) middlewares.push(this.userAgentMiddleware);
|
|
1612
|
+
if (this.errorMiddleware) middlewares.push(this.errorMiddleware);
|
|
1600
1613
|
if (this.authMiddleware) middlewares.push(this.authMiddleware);
|
|
1601
1614
|
if (this.beforeMiddleware) middlewares.push(this.beforeMiddleware);
|
|
1602
1615
|
if (this.queueMiddleware) middlewares.push(this.queueMiddleware);
|
|
@@ -1620,6 +1633,7 @@ exports.createAuthMiddlewareForRefreshTokenFlow = createAuthMiddlewareForRefresh
|
|
|
1620
1633
|
exports.createClient = createClient;
|
|
1621
1634
|
exports.createConcurrentModificationMiddleware = createConcurrentModificationMiddleware$1;
|
|
1622
1635
|
exports.createCorrelationIdMiddleware = createCorrelationIdMiddleware$1;
|
|
1636
|
+
exports.createErrorMiddleware = createErrorMiddleware$1;
|
|
1623
1637
|
exports.createHttpMiddleware = createHttpMiddleware$1;
|
|
1624
1638
|
exports.createLoggerMiddleware = createLoggerMiddleware$1;
|
|
1625
1639
|
exports.createQueueMiddleware = createQueueMiddleware$1;
|
|
@@ -905,21 +905,27 @@ function createCorrelationIdMiddleware$1(options) {
|
|
|
905
905
|
};
|
|
906
906
|
}
|
|
907
907
|
|
|
908
|
-
function createErrorMiddleware(options) {
|
|
908
|
+
function createErrorMiddleware$1(options = {}) {
|
|
909
909
|
return next => async request => {
|
|
910
910
|
const response = await next(request);
|
|
911
911
|
if (response.error) {
|
|
912
912
|
const {
|
|
913
913
|
error
|
|
914
914
|
} = response;
|
|
915
|
+
if (options.handler && typeof options.handler == 'function') {
|
|
916
|
+
return options.handler({
|
|
917
|
+
error,
|
|
918
|
+
request,
|
|
919
|
+
response,
|
|
920
|
+
next
|
|
921
|
+
});
|
|
922
|
+
}
|
|
915
923
|
return {
|
|
916
924
|
...response,
|
|
917
925
|
statusCode: error.statusCode || 0,
|
|
918
926
|
headers: error.headers || getHeaders({}),
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
body: error.data || error
|
|
922
|
-
}
|
|
927
|
+
body: error,
|
|
928
|
+
error
|
|
923
929
|
};
|
|
924
930
|
}
|
|
925
931
|
return response;
|
|
@@ -1165,7 +1171,7 @@ function createQueueMiddleware$1({
|
|
|
1165
1171
|
|
|
1166
1172
|
var packageJson = {
|
|
1167
1173
|
name: "@commercetools/ts-client",
|
|
1168
|
-
version: "3.
|
|
1174
|
+
version: "3.3.1",
|
|
1169
1175
|
engines: {
|
|
1170
1176
|
node: ">=18"
|
|
1171
1177
|
},
|
|
@@ -1213,9 +1219,9 @@ var packageJson = {
|
|
|
1213
1219
|
},
|
|
1214
1220
|
devDependencies: {
|
|
1215
1221
|
"common-tags": "1.8.2",
|
|
1216
|
-
dotenv: "16.
|
|
1222
|
+
dotenv: "16.5.0",
|
|
1217
1223
|
jest: "29.7.0",
|
|
1218
|
-
nock: "14.0.
|
|
1224
|
+
nock: "14.0.4",
|
|
1219
1225
|
"organize-imports-cli": "0.10.0"
|
|
1220
1226
|
},
|
|
1221
1227
|
scripts: {
|
|
@@ -1252,7 +1258,7 @@ var middleware = /*#__PURE__*/Object.freeze({
|
|
|
1252
1258
|
createAuthMiddlewareForRefreshTokenFlow: createAuthMiddlewareForRefreshTokenFlow$1,
|
|
1253
1259
|
createConcurrentModificationMiddleware: createConcurrentModificationMiddleware$1,
|
|
1254
1260
|
createCorrelationIdMiddleware: createCorrelationIdMiddleware$1,
|
|
1255
|
-
createErrorMiddleware: createErrorMiddleware,
|
|
1261
|
+
createErrorMiddleware: createErrorMiddleware$1,
|
|
1256
1262
|
createHttpMiddleware: createHttpMiddleware$1,
|
|
1257
1263
|
createLoggerMiddleware: createLoggerMiddleware$1,
|
|
1258
1264
|
createQueueMiddleware: createQueueMiddleware$1,
|
|
@@ -1423,7 +1429,8 @@ const {
|
|
|
1423
1429
|
createLoggerMiddleware,
|
|
1424
1430
|
createQueueMiddleware,
|
|
1425
1431
|
createUserAgentMiddleware,
|
|
1426
|
-
createConcurrentModificationMiddleware
|
|
1432
|
+
createConcurrentModificationMiddleware,
|
|
1433
|
+
createErrorMiddleware
|
|
1427
1434
|
} = middleware;
|
|
1428
1435
|
class ClientBuilder {
|
|
1429
1436
|
constructor() {
|
|
@@ -1438,6 +1445,7 @@ class ClientBuilder {
|
|
|
1438
1445
|
_defineProperty(this, "telemetryMiddleware", void 0);
|
|
1439
1446
|
_defineProperty(this, "beforeMiddleware", void 0);
|
|
1440
1447
|
_defineProperty(this, "afterMiddleware", void 0);
|
|
1448
|
+
_defineProperty(this, "errorMiddleware", void 0);
|
|
1441
1449
|
_defineProperty(this, "middlewares", []);
|
|
1442
1450
|
this.userAgentMiddleware = createUserAgentMiddleware({});
|
|
1443
1451
|
}
|
|
@@ -1465,6 +1473,10 @@ class ClientBuilder {
|
|
|
1465
1473
|
this.middlewares.push(middleware);
|
|
1466
1474
|
return this;
|
|
1467
1475
|
}
|
|
1476
|
+
withErrorMiddleware(options) {
|
|
1477
|
+
this.errorMiddleware = createErrorMiddleware(options);
|
|
1478
|
+
return this;
|
|
1479
|
+
}
|
|
1468
1480
|
withClientCredentialsFlow(options) {
|
|
1469
1481
|
return this.withAuthMiddleware(createAuthMiddlewareForClientCredentialsFlow({
|
|
1470
1482
|
host: options.host || CTP_AUTH_URL,
|
|
@@ -1593,6 +1605,7 @@ class ClientBuilder {
|
|
|
1593
1605
|
if (this.telemetryMiddleware) middlewares.push(this.telemetryMiddleware);
|
|
1594
1606
|
if (this.correlationIdMiddleware) middlewares.push(this.correlationIdMiddleware);
|
|
1595
1607
|
if (this.userAgentMiddleware) middlewares.push(this.userAgentMiddleware);
|
|
1608
|
+
if (this.errorMiddleware) middlewares.push(this.errorMiddleware);
|
|
1596
1609
|
if (this.authMiddleware) middlewares.push(this.authMiddleware);
|
|
1597
1610
|
if (this.beforeMiddleware) middlewares.push(this.beforeMiddleware);
|
|
1598
1611
|
if (this.queueMiddleware) middlewares.push(this.queueMiddleware);
|
|
@@ -1606,4 +1619,4 @@ class ClientBuilder {
|
|
|
1606
1619
|
}
|
|
1607
1620
|
}
|
|
1608
1621
|
|
|
1609
|
-
export { ClientBuilder, process$1 as Process, createAuthMiddlewareForAnonymousSessionFlow$1 as createAuthMiddlewareForAnonymousSessionFlow, createAuthMiddlewareForClientCredentialsFlow$1 as createAuthMiddlewareForClientCredentialsFlow, createAuthMiddlewareForExistingTokenFlow$1 as createAuthMiddlewareForExistingTokenFlow, createAuthMiddlewareForPasswordFlow$1 as createAuthMiddlewareForPasswordFlow, createAuthMiddlewareForRefreshTokenFlow$1 as createAuthMiddlewareForRefreshTokenFlow, createClient, createConcurrentModificationMiddleware$1 as createConcurrentModificationMiddleware, createCorrelationIdMiddleware$1 as createCorrelationIdMiddleware, createHttpMiddleware$1 as createHttpMiddleware, createLoggerMiddleware$1 as createLoggerMiddleware, createQueueMiddleware$1 as createQueueMiddleware, createUserAgentMiddleware$1 as createUserAgentMiddleware };
|
|
1622
|
+
export { ClientBuilder, process$1 as Process, createAuthMiddlewareForAnonymousSessionFlow$1 as createAuthMiddlewareForAnonymousSessionFlow, createAuthMiddlewareForClientCredentialsFlow$1 as createAuthMiddlewareForClientCredentialsFlow, createAuthMiddlewareForExistingTokenFlow$1 as createAuthMiddlewareForExistingTokenFlow, createAuthMiddlewareForPasswordFlow$1 as createAuthMiddlewareForPasswordFlow, createAuthMiddlewareForRefreshTokenFlow$1 as createAuthMiddlewareForRefreshTokenFlow, createClient, createConcurrentModificationMiddleware$1 as createConcurrentModificationMiddleware, createCorrelationIdMiddleware$1 as createCorrelationIdMiddleware, createErrorMiddleware$1 as createErrorMiddleware, createHttpMiddleware$1 as createHttpMiddleware, createLoggerMiddleware$1 as createLoggerMiddleware, createQueueMiddleware$1 as createQueueMiddleware, createUserAgentMiddleware$1 as createUserAgentMiddleware };
|
|
@@ -909,21 +909,27 @@ function createCorrelationIdMiddleware$1(options) {
|
|
|
909
909
|
};
|
|
910
910
|
}
|
|
911
911
|
|
|
912
|
-
function createErrorMiddleware(options) {
|
|
912
|
+
function createErrorMiddleware$1(options = {}) {
|
|
913
913
|
return next => async request => {
|
|
914
914
|
const response = await next(request);
|
|
915
915
|
if (response.error) {
|
|
916
916
|
const {
|
|
917
917
|
error
|
|
918
918
|
} = response;
|
|
919
|
+
if (options.handler && typeof options.handler == 'function') {
|
|
920
|
+
return options.handler({
|
|
921
|
+
error,
|
|
922
|
+
request,
|
|
923
|
+
response,
|
|
924
|
+
next
|
|
925
|
+
});
|
|
926
|
+
}
|
|
919
927
|
return {
|
|
920
928
|
...response,
|
|
921
929
|
statusCode: error.statusCode || 0,
|
|
922
930
|
headers: error.headers || getHeaders({}),
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
body: error.data || error
|
|
926
|
-
}
|
|
931
|
+
body: error,
|
|
932
|
+
error
|
|
927
933
|
};
|
|
928
934
|
}
|
|
929
935
|
return response;
|
|
@@ -1169,7 +1175,7 @@ function createQueueMiddleware$1({
|
|
|
1169
1175
|
|
|
1170
1176
|
var packageJson = {
|
|
1171
1177
|
name: "@commercetools/ts-client",
|
|
1172
|
-
version: "3.
|
|
1178
|
+
version: "3.3.1",
|
|
1173
1179
|
engines: {
|
|
1174
1180
|
node: ">=18"
|
|
1175
1181
|
},
|
|
@@ -1217,9 +1223,9 @@ var packageJson = {
|
|
|
1217
1223
|
},
|
|
1218
1224
|
devDependencies: {
|
|
1219
1225
|
"common-tags": "1.8.2",
|
|
1220
|
-
dotenv: "16.
|
|
1226
|
+
dotenv: "16.5.0",
|
|
1221
1227
|
jest: "29.7.0",
|
|
1222
|
-
nock: "14.0.
|
|
1228
|
+
nock: "14.0.4",
|
|
1223
1229
|
"organize-imports-cli": "0.10.0"
|
|
1224
1230
|
},
|
|
1225
1231
|
scripts: {
|
|
@@ -1256,7 +1262,7 @@ var middleware = /*#__PURE__*/Object.freeze({
|
|
|
1256
1262
|
createAuthMiddlewareForRefreshTokenFlow: createAuthMiddlewareForRefreshTokenFlow$1,
|
|
1257
1263
|
createConcurrentModificationMiddleware: createConcurrentModificationMiddleware$1,
|
|
1258
1264
|
createCorrelationIdMiddleware: createCorrelationIdMiddleware$1,
|
|
1259
|
-
createErrorMiddleware: createErrorMiddleware,
|
|
1265
|
+
createErrorMiddleware: createErrorMiddleware$1,
|
|
1260
1266
|
createHttpMiddleware: createHttpMiddleware$1,
|
|
1261
1267
|
createLoggerMiddleware: createLoggerMiddleware$1,
|
|
1262
1268
|
createQueueMiddleware: createQueueMiddleware$1,
|
|
@@ -1427,7 +1433,8 @@ const {
|
|
|
1427
1433
|
createLoggerMiddleware,
|
|
1428
1434
|
createQueueMiddleware,
|
|
1429
1435
|
createUserAgentMiddleware,
|
|
1430
|
-
createConcurrentModificationMiddleware
|
|
1436
|
+
createConcurrentModificationMiddleware,
|
|
1437
|
+
createErrorMiddleware
|
|
1431
1438
|
} = middleware;
|
|
1432
1439
|
class ClientBuilder {
|
|
1433
1440
|
constructor() {
|
|
@@ -1442,6 +1449,7 @@ class ClientBuilder {
|
|
|
1442
1449
|
_defineProperty(this, "telemetryMiddleware", void 0);
|
|
1443
1450
|
_defineProperty(this, "beforeMiddleware", void 0);
|
|
1444
1451
|
_defineProperty(this, "afterMiddleware", void 0);
|
|
1452
|
+
_defineProperty(this, "errorMiddleware", void 0);
|
|
1445
1453
|
_defineProperty(this, "middlewares", []);
|
|
1446
1454
|
this.userAgentMiddleware = createUserAgentMiddleware({});
|
|
1447
1455
|
}
|
|
@@ -1469,6 +1477,10 @@ class ClientBuilder {
|
|
|
1469
1477
|
this.middlewares.push(middleware);
|
|
1470
1478
|
return this;
|
|
1471
1479
|
}
|
|
1480
|
+
withErrorMiddleware(options) {
|
|
1481
|
+
this.errorMiddleware = createErrorMiddleware(options);
|
|
1482
|
+
return this;
|
|
1483
|
+
}
|
|
1472
1484
|
withClientCredentialsFlow(options) {
|
|
1473
1485
|
return this.withAuthMiddleware(createAuthMiddlewareForClientCredentialsFlow({
|
|
1474
1486
|
host: options.host || CTP_AUTH_URL,
|
|
@@ -1597,6 +1609,7 @@ class ClientBuilder {
|
|
|
1597
1609
|
if (this.telemetryMiddleware) middlewares.push(this.telemetryMiddleware);
|
|
1598
1610
|
if (this.correlationIdMiddleware) middlewares.push(this.correlationIdMiddleware);
|
|
1599
1611
|
if (this.userAgentMiddleware) middlewares.push(this.userAgentMiddleware);
|
|
1612
|
+
if (this.errorMiddleware) middlewares.push(this.errorMiddleware);
|
|
1600
1613
|
if (this.authMiddleware) middlewares.push(this.authMiddleware);
|
|
1601
1614
|
if (this.beforeMiddleware) middlewares.push(this.beforeMiddleware);
|
|
1602
1615
|
if (this.queueMiddleware) middlewares.push(this.queueMiddleware);
|
|
@@ -1620,6 +1633,7 @@ exports.createAuthMiddlewareForRefreshTokenFlow = createAuthMiddlewareForRefresh
|
|
|
1620
1633
|
exports.createClient = createClient;
|
|
1621
1634
|
exports.createConcurrentModificationMiddleware = createConcurrentModificationMiddleware$1;
|
|
1622
1635
|
exports.createCorrelationIdMiddleware = createCorrelationIdMiddleware$1;
|
|
1636
|
+
exports.createErrorMiddleware = createErrorMiddleware$1;
|
|
1623
1637
|
exports.createHttpMiddleware = createHttpMiddleware$1;
|
|
1624
1638
|
exports.createLoggerMiddleware = createLoggerMiddleware$1;
|
|
1625
1639
|
exports.createQueueMiddleware = createQueueMiddleware$1;
|
|
@@ -909,21 +909,27 @@ function createCorrelationIdMiddleware$1(options) {
|
|
|
909
909
|
};
|
|
910
910
|
}
|
|
911
911
|
|
|
912
|
-
function createErrorMiddleware(options) {
|
|
912
|
+
function createErrorMiddleware$1(options = {}) {
|
|
913
913
|
return next => async request => {
|
|
914
914
|
const response = await next(request);
|
|
915
915
|
if (response.error) {
|
|
916
916
|
const {
|
|
917
917
|
error
|
|
918
918
|
} = response;
|
|
919
|
+
if (options.handler && typeof options.handler == 'function') {
|
|
920
|
+
return options.handler({
|
|
921
|
+
error,
|
|
922
|
+
request,
|
|
923
|
+
response,
|
|
924
|
+
next
|
|
925
|
+
});
|
|
926
|
+
}
|
|
919
927
|
return {
|
|
920
928
|
...response,
|
|
921
929
|
statusCode: error.statusCode || 0,
|
|
922
930
|
headers: error.headers || getHeaders({}),
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
body: error.data || error
|
|
926
|
-
}
|
|
931
|
+
body: error,
|
|
932
|
+
error
|
|
927
933
|
};
|
|
928
934
|
}
|
|
929
935
|
return response;
|
|
@@ -1169,7 +1175,7 @@ function createQueueMiddleware$1({
|
|
|
1169
1175
|
|
|
1170
1176
|
var packageJson = {
|
|
1171
1177
|
name: "@commercetools/ts-client",
|
|
1172
|
-
version: "3.
|
|
1178
|
+
version: "3.3.1",
|
|
1173
1179
|
engines: {
|
|
1174
1180
|
node: ">=18"
|
|
1175
1181
|
},
|
|
@@ -1217,9 +1223,9 @@ var packageJson = {
|
|
|
1217
1223
|
},
|
|
1218
1224
|
devDependencies: {
|
|
1219
1225
|
"common-tags": "1.8.2",
|
|
1220
|
-
dotenv: "16.
|
|
1226
|
+
dotenv: "16.5.0",
|
|
1221
1227
|
jest: "29.7.0",
|
|
1222
|
-
nock: "14.0.
|
|
1228
|
+
nock: "14.0.4",
|
|
1223
1229
|
"organize-imports-cli": "0.10.0"
|
|
1224
1230
|
},
|
|
1225
1231
|
scripts: {
|
|
@@ -1256,7 +1262,7 @@ var middleware = /*#__PURE__*/Object.freeze({
|
|
|
1256
1262
|
createAuthMiddlewareForRefreshTokenFlow: createAuthMiddlewareForRefreshTokenFlow$1,
|
|
1257
1263
|
createConcurrentModificationMiddleware: createConcurrentModificationMiddleware$1,
|
|
1258
1264
|
createCorrelationIdMiddleware: createCorrelationIdMiddleware$1,
|
|
1259
|
-
createErrorMiddleware: createErrorMiddleware,
|
|
1265
|
+
createErrorMiddleware: createErrorMiddleware$1,
|
|
1260
1266
|
createHttpMiddleware: createHttpMiddleware$1,
|
|
1261
1267
|
createLoggerMiddleware: createLoggerMiddleware$1,
|
|
1262
1268
|
createQueueMiddleware: createQueueMiddleware$1,
|
|
@@ -1427,7 +1433,8 @@ const {
|
|
|
1427
1433
|
createLoggerMiddleware,
|
|
1428
1434
|
createQueueMiddleware,
|
|
1429
1435
|
createUserAgentMiddleware,
|
|
1430
|
-
createConcurrentModificationMiddleware
|
|
1436
|
+
createConcurrentModificationMiddleware,
|
|
1437
|
+
createErrorMiddleware
|
|
1431
1438
|
} = middleware;
|
|
1432
1439
|
class ClientBuilder {
|
|
1433
1440
|
constructor() {
|
|
@@ -1442,6 +1449,7 @@ class ClientBuilder {
|
|
|
1442
1449
|
_defineProperty(this, "telemetryMiddleware", void 0);
|
|
1443
1450
|
_defineProperty(this, "beforeMiddleware", void 0);
|
|
1444
1451
|
_defineProperty(this, "afterMiddleware", void 0);
|
|
1452
|
+
_defineProperty(this, "errorMiddleware", void 0);
|
|
1445
1453
|
_defineProperty(this, "middlewares", []);
|
|
1446
1454
|
this.userAgentMiddleware = createUserAgentMiddleware({});
|
|
1447
1455
|
}
|
|
@@ -1469,6 +1477,10 @@ class ClientBuilder {
|
|
|
1469
1477
|
this.middlewares.push(middleware);
|
|
1470
1478
|
return this;
|
|
1471
1479
|
}
|
|
1480
|
+
withErrorMiddleware(options) {
|
|
1481
|
+
this.errorMiddleware = createErrorMiddleware(options);
|
|
1482
|
+
return this;
|
|
1483
|
+
}
|
|
1472
1484
|
withClientCredentialsFlow(options) {
|
|
1473
1485
|
return this.withAuthMiddleware(createAuthMiddlewareForClientCredentialsFlow({
|
|
1474
1486
|
host: options.host || CTP_AUTH_URL,
|
|
@@ -1597,6 +1609,7 @@ class ClientBuilder {
|
|
|
1597
1609
|
if (this.telemetryMiddleware) middlewares.push(this.telemetryMiddleware);
|
|
1598
1610
|
if (this.correlationIdMiddleware) middlewares.push(this.correlationIdMiddleware);
|
|
1599
1611
|
if (this.userAgentMiddleware) middlewares.push(this.userAgentMiddleware);
|
|
1612
|
+
if (this.errorMiddleware) middlewares.push(this.errorMiddleware);
|
|
1600
1613
|
if (this.authMiddleware) middlewares.push(this.authMiddleware);
|
|
1601
1614
|
if (this.beforeMiddleware) middlewares.push(this.beforeMiddleware);
|
|
1602
1615
|
if (this.queueMiddleware) middlewares.push(this.queueMiddleware);
|
|
@@ -1620,6 +1633,7 @@ exports.createAuthMiddlewareForRefreshTokenFlow = createAuthMiddlewareForRefresh
|
|
|
1620
1633
|
exports.createClient = createClient;
|
|
1621
1634
|
exports.createConcurrentModificationMiddleware = createConcurrentModificationMiddleware$1;
|
|
1622
1635
|
exports.createCorrelationIdMiddleware = createCorrelationIdMiddleware$1;
|
|
1636
|
+
exports.createErrorMiddleware = createErrorMiddleware$1;
|
|
1623
1637
|
exports.createHttpMiddleware = createHttpMiddleware$1;
|
|
1624
1638
|
exports.createLoggerMiddleware = createLoggerMiddleware$1;
|
|
1625
1639
|
exports.createQueueMiddleware = createQueueMiddleware$1;
|
|
@@ -905,21 +905,27 @@ function createCorrelationIdMiddleware$1(options) {
|
|
|
905
905
|
};
|
|
906
906
|
}
|
|
907
907
|
|
|
908
|
-
function createErrorMiddleware(options) {
|
|
908
|
+
function createErrorMiddleware$1(options = {}) {
|
|
909
909
|
return next => async request => {
|
|
910
910
|
const response = await next(request);
|
|
911
911
|
if (response.error) {
|
|
912
912
|
const {
|
|
913
913
|
error
|
|
914
914
|
} = response;
|
|
915
|
+
if (options.handler && typeof options.handler == 'function') {
|
|
916
|
+
return options.handler({
|
|
917
|
+
error,
|
|
918
|
+
request,
|
|
919
|
+
response,
|
|
920
|
+
next
|
|
921
|
+
});
|
|
922
|
+
}
|
|
915
923
|
return {
|
|
916
924
|
...response,
|
|
917
925
|
statusCode: error.statusCode || 0,
|
|
918
926
|
headers: error.headers || getHeaders({}),
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
body: error.data || error
|
|
922
|
-
}
|
|
927
|
+
body: error,
|
|
928
|
+
error
|
|
923
929
|
};
|
|
924
930
|
}
|
|
925
931
|
return response;
|
|
@@ -1165,7 +1171,7 @@ function createQueueMiddleware$1({
|
|
|
1165
1171
|
|
|
1166
1172
|
var packageJson = {
|
|
1167
1173
|
name: "@commercetools/ts-client",
|
|
1168
|
-
version: "3.
|
|
1174
|
+
version: "3.3.1",
|
|
1169
1175
|
engines: {
|
|
1170
1176
|
node: ">=18"
|
|
1171
1177
|
},
|
|
@@ -1213,9 +1219,9 @@ var packageJson = {
|
|
|
1213
1219
|
},
|
|
1214
1220
|
devDependencies: {
|
|
1215
1221
|
"common-tags": "1.8.2",
|
|
1216
|
-
dotenv: "16.
|
|
1222
|
+
dotenv: "16.5.0",
|
|
1217
1223
|
jest: "29.7.0",
|
|
1218
|
-
nock: "14.0.
|
|
1224
|
+
nock: "14.0.4",
|
|
1219
1225
|
"organize-imports-cli": "0.10.0"
|
|
1220
1226
|
},
|
|
1221
1227
|
scripts: {
|
|
@@ -1252,7 +1258,7 @@ var middleware = /*#__PURE__*/Object.freeze({
|
|
|
1252
1258
|
createAuthMiddlewareForRefreshTokenFlow: createAuthMiddlewareForRefreshTokenFlow$1,
|
|
1253
1259
|
createConcurrentModificationMiddleware: createConcurrentModificationMiddleware$1,
|
|
1254
1260
|
createCorrelationIdMiddleware: createCorrelationIdMiddleware$1,
|
|
1255
|
-
createErrorMiddleware: createErrorMiddleware,
|
|
1261
|
+
createErrorMiddleware: createErrorMiddleware$1,
|
|
1256
1262
|
createHttpMiddleware: createHttpMiddleware$1,
|
|
1257
1263
|
createLoggerMiddleware: createLoggerMiddleware$1,
|
|
1258
1264
|
createQueueMiddleware: createQueueMiddleware$1,
|
|
@@ -1423,7 +1429,8 @@ const {
|
|
|
1423
1429
|
createLoggerMiddleware,
|
|
1424
1430
|
createQueueMiddleware,
|
|
1425
1431
|
createUserAgentMiddleware,
|
|
1426
|
-
createConcurrentModificationMiddleware
|
|
1432
|
+
createConcurrentModificationMiddleware,
|
|
1433
|
+
createErrorMiddleware
|
|
1427
1434
|
} = middleware;
|
|
1428
1435
|
class ClientBuilder {
|
|
1429
1436
|
constructor() {
|
|
@@ -1438,6 +1445,7 @@ class ClientBuilder {
|
|
|
1438
1445
|
_defineProperty(this, "telemetryMiddleware", void 0);
|
|
1439
1446
|
_defineProperty(this, "beforeMiddleware", void 0);
|
|
1440
1447
|
_defineProperty(this, "afterMiddleware", void 0);
|
|
1448
|
+
_defineProperty(this, "errorMiddleware", void 0);
|
|
1441
1449
|
_defineProperty(this, "middlewares", []);
|
|
1442
1450
|
this.userAgentMiddleware = createUserAgentMiddleware({});
|
|
1443
1451
|
}
|
|
@@ -1465,6 +1473,10 @@ class ClientBuilder {
|
|
|
1465
1473
|
this.middlewares.push(middleware);
|
|
1466
1474
|
return this;
|
|
1467
1475
|
}
|
|
1476
|
+
withErrorMiddleware(options) {
|
|
1477
|
+
this.errorMiddleware = createErrorMiddleware(options);
|
|
1478
|
+
return this;
|
|
1479
|
+
}
|
|
1468
1480
|
withClientCredentialsFlow(options) {
|
|
1469
1481
|
return this.withAuthMiddleware(createAuthMiddlewareForClientCredentialsFlow({
|
|
1470
1482
|
host: options.host || CTP_AUTH_URL,
|
|
@@ -1593,6 +1605,7 @@ class ClientBuilder {
|
|
|
1593
1605
|
if (this.telemetryMiddleware) middlewares.push(this.telemetryMiddleware);
|
|
1594
1606
|
if (this.correlationIdMiddleware) middlewares.push(this.correlationIdMiddleware);
|
|
1595
1607
|
if (this.userAgentMiddleware) middlewares.push(this.userAgentMiddleware);
|
|
1608
|
+
if (this.errorMiddleware) middlewares.push(this.errorMiddleware);
|
|
1596
1609
|
if (this.authMiddleware) middlewares.push(this.authMiddleware);
|
|
1597
1610
|
if (this.beforeMiddleware) middlewares.push(this.beforeMiddleware);
|
|
1598
1611
|
if (this.queueMiddleware) middlewares.push(this.queueMiddleware);
|
|
@@ -1606,4 +1619,4 @@ class ClientBuilder {
|
|
|
1606
1619
|
}
|
|
1607
1620
|
}
|
|
1608
1621
|
|
|
1609
|
-
export { ClientBuilder, process$1 as Process, createAuthMiddlewareForAnonymousSessionFlow$1 as createAuthMiddlewareForAnonymousSessionFlow, createAuthMiddlewareForClientCredentialsFlow$1 as createAuthMiddlewareForClientCredentialsFlow, createAuthMiddlewareForExistingTokenFlow$1 as createAuthMiddlewareForExistingTokenFlow, createAuthMiddlewareForPasswordFlow$1 as createAuthMiddlewareForPasswordFlow, createAuthMiddlewareForRefreshTokenFlow$1 as createAuthMiddlewareForRefreshTokenFlow, createClient, createConcurrentModificationMiddleware$1 as createConcurrentModificationMiddleware, createCorrelationIdMiddleware$1 as createCorrelationIdMiddleware, createHttpMiddleware$1 as createHttpMiddleware, createLoggerMiddleware$1 as createLoggerMiddleware, createQueueMiddleware$1 as createQueueMiddleware, createUserAgentMiddleware$1 as createUserAgentMiddleware };
|
|
1622
|
+
export { ClientBuilder, process$1 as Process, createAuthMiddlewareForAnonymousSessionFlow$1 as createAuthMiddlewareForAnonymousSessionFlow, createAuthMiddlewareForClientCredentialsFlow$1 as createAuthMiddlewareForClientCredentialsFlow, createAuthMiddlewareForExistingTokenFlow$1 as createAuthMiddlewareForExistingTokenFlow, createAuthMiddlewareForPasswordFlow$1 as createAuthMiddlewareForPasswordFlow, createAuthMiddlewareForRefreshTokenFlow$1 as createAuthMiddlewareForRefreshTokenFlow, createClient, createConcurrentModificationMiddleware$1 as createConcurrentModificationMiddleware, createCorrelationIdMiddleware$1 as createCorrelationIdMiddleware, createErrorMiddleware$1 as createErrorMiddleware, createHttpMiddleware$1 as createHttpMiddleware, createLoggerMiddleware$1 as createLoggerMiddleware, createQueueMiddleware$1 as createQueueMiddleware, createUserAgentMiddleware$1 as createUserAgentMiddleware };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var window;(window||={})["@commercetools/ts-client"]=(()=>{var ue=Object.defineProperty;var Fe=Object.getOwnPropertyDescriptor;var Ie=Object.getOwnPropertyNames;var Ne=Object.prototype.hasOwnProperty;var ce=(e,t)=>{for(var r in t)ue(e,r,{get:t[r],enumerable:!0})},Ue=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Ie(t))!Ne.call(e,i)&&i!==r&&ue(e,i,{get:()=>t[i],enumerable:!(o=Fe(t,i))||o.enumerable});return e};var je=e=>Ue(ue({},"__esModule",{value:!0}),e);var mt={};ce(mt,{ClientBuilder:()=>L,Process:()=>de,createAuthMiddlewareForAnonymousSessionFlow:()=>v,createAuthMiddlewareForClientCredentialsFlow:()=>H,createAuthMiddlewareForExistingTokenFlow:()=>_,createAuthMiddlewareForPasswordFlow:()=>B,createAuthMiddlewareForRefreshTokenFlow:()=>K,createClient:()=>P,createConcurrentModificationMiddleware:()=>z,createCorrelationIdMiddleware:()=>J,createHttpMiddleware:()=>V,createLoggerMiddleware:()=>G,createQueueMiddleware:()=>Y,createUserAgentMiddleware:()=>W});var Ae={};ce(Ae,{createAuthMiddlewareForAnonymousSessionFlow:()=>v,createAuthMiddlewareForClientCredentialsFlow:()=>H,createAuthMiddlewareForExistingTokenFlow:()=>_,createAuthMiddlewareForPasswordFlow:()=>B,createAuthMiddlewareForRefreshTokenFlow:()=>K,createConcurrentModificationMiddleware:()=>z,createCorrelationIdMiddleware:()=>J,createErrorMiddleware:()=>Re,createHttpMiddleware:()=>V,createLoggerMiddleware:()=>G,createQueueMiddleware:()=>Y,createUserAgentMiddleware:()=>W});function I(e){return e&&typeof e=="string"?new TextEncoder().encode(e).length.toString():e&&e instanceof Uint8Array?e.byteLength.toString():e&&typeof e=="object"?new TextEncoder().encode(JSON.stringify(e)).length.toString():"0"}var g={};ce(g,{CONCURRENCT_REQUEST:()=>He,CTP_API_URL:()=>_e,CTP_AUTH_URL:()=>Be,DEFAULT_HEADERS:()=>pe,HEADERS_CONTENT_TYPES:()=>ve});var ve=["application/json","application/graphql"],He=20,_e="https://api.europe-west1.gcp.commercetools.com",Be="https://auth.europe-west1.gcp.commercetools.com",pe=["content-type","access-control-allow-origin","access-control-allow-headers","access-control-allow-methods","access-control-expose-headers","access-control-max-ag","x-correlation-id","server-timing","date","server","transfer-encoding","access-control-max-age","content-encoding","x-envoy-upstream-service-time","via","alt-svc","connection"];function b(e,t,r={}){this.code=r.code??=this.constructor.name,this.statusCode=e,this.status=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 be(...e){b.call(this,0,...e)}function Te(...e){b.call(this,...e)}function Ke(...e){b.call(this,400,...e)}function Le(...e){b.call(this,401,...e)}function $e(...e){b.call(this,403,...e)}function De(...e){b.call(this,404,...e)}function Qe(...e){b.call(this,409,...e)}function ze(...e){b.call(this,500,...e)}function Je(...e){b.call(this,503,...e)}function he(e){switch(e){case 0:return be;case 400:return Ke;case 401:return Le;case 403:return $e;case 404:return De;case 409:return Qe;case 500:return ze;case 503:return Je;default:return}}function Ve({statusCode:e,message:t,...r}){let o=t||"Unexpected non-JSON error response";e===404&&(o=`URI not found: ${r.originalRequest?.uri||r.uri}`);let i=he(e);return i?new i(o,r):new Te(e,o,r)}var N=Ve;function Ge(e,t){return[503,...e].includes(t?.status||t?.statusCode)}async function Ye(e,t){async function r(){return await e({...t,headers:{...t.headers}})}return r().catch(o=>Promise.reject(o))}async function U(e){let{url:t,httpClient:r,...o}=e;return await Ye(async s=>{let{enableRetry:a,retryConfig:n,timeout:u,getAbortController:l}=o,{retryCodes:d=[],maxDelay:c=1/0,maxRetries:M=3,backoff:C=!0,retryDelay:p=200,retryOnAbort:S=!0}=n||{},h,w,f=0,q;we(d);async function x(){return r(t,{...s,...o,headers:{...o.headers},...o.body?{data:o.body}:{},withCredentials:s.credentialsMode==="include"})}function X(){let y=(l?l():null)||new AbortController;return o.abortController=y,o.signal=y.signal,y}async function F(){let y=async(ee,qe)=>{let D={};if(u){let O=X();q=setTimeout(()=>{O.abort(),O=X()},u)}try{if(D=await x(),D.status>399&&Ge(ee,D))return{_response:D,shouldRetry:!0}}catch(O){if((O.name.includes("AbortError")||O.name.includes("TimeoutError"))&&qe)return{_response:O,shouldRetry:!0};throw O}finally{clearTimeout(q)}return{_response:D,shouldRetry:!1}},{_response:$,shouldRetry:Z}=await y(d,S);for(;a&&Z&&f<M;){f++,await re(te({retryCount:f,retryDelay:p,maxRetries:M,backoff:C,maxDelay:c}));let ee=await y(d,S);$=ee._response,Z=ee.shouldRetry}return $}let m=await F();try{m.text&&typeof m.text=="function"?(h=await m.text()||JSON.stringify(m[Object.getOwnPropertySymbols(m)[1]]),w=JSON.parse(h)):w=m.data||m}catch(y){throw y}return{data:w,retryCount:f,statusCode:m.status||m.statusCode||w.statusCode,headers:m.headers}},{validateStatus:s=>!0})}function oe(){return("1000000-1000-4000-8000"+-1e11).replace(/[018]/g,e=>(parseInt(e)^Math.floor(Math.random()*256)&15>>parseInt(e)/4).toString(16))}function We(e){return pe.reduce((t,r)=>{let o=e[r]?e[r]:typeof e.get=="function"?e.get(r):null;return o&&(t[r]=o),t},{})}function T(e){if(!e)return null;if(e.raw&&typeof e.raw=="function")return e.raw();if(!e.forEach)return We(e);let t={};return e.forEach((r,o)=>t[o]=r),t}function Q(e){return e!=null&&e.constructor!=null&&typeof e.constructor.isBuffer=="function"&&e.constructor.isBuffer(e)}function k(e){let t=JSON.parse(JSON.stringify(e));return t?.headers&&(t.headers.Authorization&&(t.headers.Authorization="Bearer ********"),t.headers.authorization&&(t.headers.authorization="Bearer ********")),t}function j(e,t){return{...t,headers:{...t.headers,Authorization:`Bearer ${e}`}}}var fe=["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 te({retryCount:e,retryDelay:t,backoff:r,maxDelay:o}){return r&&e!==0?Math.min(Math.round((Math.random()+1)*t*2**e),o):t}Math.min(Math.round((Math.random()+1)*200*2**10),1/0);function re(e){return new Promise(t=>{setTimeout(t,e)})}function R(e){if(!e?.credentials?.clientId||!e.projectKey||!e.host)throw new Error("Missing required options.");return{clientId:e.credentials.clientId,host:e.host,projectKey:e.projectKey}}function ie(e){return Date.now()+e*1e3-5*60*1e3}function A(e){let t=e;return{get:r=>t,set:(r,o)=>{t=r}}}function xe(e){return typeof e<"u"&&e!==null}function Xe(e){return xe(e)?typeof e=="string"?e:Object.fromEntries(Object.entries(e).filter(([t,r])=>![null,void 0,""].includes(r))):""}function Ze(e){let t={},r=new URLSearchParams(e);for(let o of r.keys())r.getAll(o).length>1?t[o]=r.getAll(o):t[o]=r.get(o);return t}function et(e){if(e=Xe(e),!e)return"";let t=new URLSearchParams(e);for(let[r,o]of Object.entries(e))Array.isArray(o)&&(t.delete(r),o.filter(xe).forEach(i=>t.append(r,i)));return t.toString()}function me(e,t=Ze){return t(e)}function ne(e,t=et){return t(e)}var tt=()=>typeof window<"u"&&window.document&&window.document.nodeType===9;function rt(){if(tt())return window.navigator.userAgent;let e=process?.version?.slice(1)||"unknown",t=`(${process?.platform||""}; ${process?.arch||""})`;return`node.js/${e} ${t.trim()}`}function se(e){let t=null,r=null;if(!e)throw new Error("Missing required option `name`");let o=e.version?`${e.name}/${e.version}`:e.name;e.libraryName&&!e.libraryVersion?t=e.libraryName:e.libraryName&&e.libraryVersion&&(t=`${e.libraryName}/${e.libraryVersion}`),e.contactUrl&&!e.contactEmail?r=`(+${e.contactUrl})`:!e.contactUrl&&e.contactEmail?r=`(+${e.contactEmail})`:e.contactUrl&&e.contactEmail&&(r=`(+${e.contactUrl}; +${e.contactEmail})`);let i=rt(),s=e.customAgent||"";return[o,i,t,r,s].filter(Boolean).join(" ")}function ye(e){if(!e.host)throw new Error("Request `host` or `url` is missing or invalid, please pass in a valid host e.g `host: http://a-valid-host-url`");if(!e.httpClient&&typeof e.httpClient!="function")throw new Error("An `httpClient` is not available, please pass in a `fetch` or `axios` instance as an option or have them globally available.");if(e.httpClientOptions&&Object.prototype.toString.call(e.httpClientOptions)!=="[object Object]")throw new Error("`httpClientOptions` must be an object type")}function we(e){if(!Array.isArray(e))throw new Error("`retryCodes` option must be an array of retry status (error) codes and/or messages.")}function Me(e){if(!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")}function ae(e,t,r={allowedMethods:fe}){if(!t)throw new Error(`The "${e}" function requires a "Request" object as an argument. See https://commercetools.github.io/nodejs/sdk/Glossary.html#clientrequest`);if(typeof t.uri!="string")throw new Error(`The "${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 "${e}" Request object requires a valid method. See https://commercetools.github.io/nodejs/sdk/Glossary.html#clientrequest`)}function ge(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)");let{clientId:t,clientSecret:r}=e.credentials||{};if(!(t&&r))throw new Error("Missing required credentials (clientId, clientSecret)");let o=e.scopes?e.scopes.join(" "):void 0,i=btoa(`${t}:${r}`),s=e.oauthUri||"/oauth/token",a=e.host.replace(/\/$/,"")+s,n=`grant_type=client_credentials${o?`&scope=${o}`:""}`;return{url:a,body:n,basicAuth:i}}function Ee(e){if(!e)throw new Error("Missing required options");if(!e.projectKey)throw new Error("Missing required option (projectKey)");let t=e.projectKey;e.oauthUri=e.oauthUri||`/oauth/${t}/anonymous/token`;let r=ge(e);return e.credentials.anonymousId&&(r.body+=`&anonymous_id=${e.credentials.anonymousId}`),{...r}}function le(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)");let{clientId:t,clientSecret:r}=e.credentials;if(!(t&&r))throw new Error("Missing required credentials (clientId, clientSecret)");let o=btoa(`${t}:${r}`),i=e.oauthUri||"/oauth/token",s=e.host.replace(/\/$/,"")+i,a=`grant_type=refresh_token&refresh_token=${encodeURIComponent(e.refreshToken)}`;return{basicAuth:o,url:s,body:a}}function Oe(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)");let{clientId:t,clientSecret:r,user:o}=e.credentials,i=e.projectKey;if(!(t&&r&&o))throw new Error("Missing required credentials (clientId, clientSecret, user)");let{username:s,password:a}=o;if(!(s&&a))throw new Error("Missing required user credentials (username, password)");let n=(e.scopes||[]).join(" "),u=n?`&scope=${n}`:"",l=btoa(`${t}:${r}`),d=e.oauthUri||`/oauth/${i}/customers/token`,c=e.host.replace(/\/$/,"")+d,M=`grant_type=password&username=${encodeURIComponent(s)}&password=${encodeURIComponent(a)}${u}`;return{basicAuth:l,url:c,body:M}}async function Ce(e){let{httpClient:t,httpClientOptions:r,tokenCache:o,userOption:i,tokenCacheObject:s}=e,a=e.url,n=e.body,u=e.basicAuth;if(!t||typeof t!="function")throw new Error("an `httpClient` is not available, please pass in a `fetch` or `axios` instance as an option or have them globally available.");if(s&&s.refreshToken&&(!s.token||s.token&&Date.now()>s.expirationTime)){if(!i)throw new Error("Missing required options.");let d={...le({...i,refreshToken:s.refreshToken})};a=d.url,n=d.body,u=d.basicAuth}let l;try{if(l=await U({url:a,method:"POST",headers:{Authorization:`Basic ${u}`,"Content-Type":"application/x-www-form-urlencoded","Content-Length":I(n)},httpClient:t,httpClientOptions:r,body:n}),l.statusCode>=200&&l.statusCode<300){let{access_token:d,expires_in:c,refresh_token:M}=l?.data,C=ie(c);return o.set({token:d,expirationTime:C,refreshToken:M}),Promise.resolve(!0)}throw N({code:l.data.error,statusCode:l.data.statusCode,message:l.data.message,error:l.data.errors})}catch(d){throw d}}async function E(e,t=null,r,o,i,s,a,n){let u={request:e,tokenCache:i,httpClient:a.httpClient||fetch,httpClientOptions:a.httpClientOptions,...s(a),userOption:a,next:n},l=async d=>{let c=Object.assign({},d);return c.statusCode==401&&(t=Ce(u),await t,t=null,r=i.get(o),c=await n(j(r.token,e))),c};return e.headers&&(e.headers.Authorization||e.headers.authorization)?l(await n(e)):(r=i.get(o),r&&r.token&&Date.now()<r.expirationTime?l(await n(j(r.token,e))):(t?await t:(t=Ce(u),await t,t=null),r=i.get(o),n(j(r.token,e))))}function v(e){let t=e.tokenCache||A({token:"",expirationTime:-1}),r,o=null,i=R(e);return s=>async a=>E(a,o,r,i,t,Ee,e,s)}function H(e){let t=e.tokenCache||A({token:"",expirationTime:-1}),r,o=null,i=R(e);return s=>async a=>E(a,o,r,i,t,ge,e,s)}function _(e,t){return r=>async o=>{if(typeof e!="string")throw new Error("authorization must be a string");let i=t?.force===void 0?!0:t.force;if(!e||o.headers&&(o.headers.Authorization||o.headers.authorization)&&i===!1)return r(o);let s={...o,headers:{...o.headers,Authorization:e}};return r(s)}}function B(e){let t=e.tokenCache||A({token:"",expirationTime:-1}),r,o=null,i=R(e);return s=>async a=>E(a,o,r,i,t,Oe,e,s)}function K(e){let t=e.tokenCache||A({token:"",tokenCacheKey:null}),r,o=null,i=R(e);return s=>async a=>E(a,o,r,i,t,le,e,s)}function z(e){return t=>async r=>{let o=await t(r);if(o.statusCode==409){let i=o.error.body?.errors?.[0]?.currentVersion;if(i)return e&&typeof e=="function"?r.body=await e(i,r,o):r.body=typeof r.body=="string"?{...JSON.parse(r.body),version:i}:{...r.body,version:i},t(r)}return o}}function J(e){return t=>r=>{let o={...r,headers:{...r.headers,"X-Correlation-ID":e.generate&&typeof e.generate=="function"?e.generate():oe()}};return t(o)}}function Re(e){return t=>async r=>{let o=await t(r);if(o.error){let{error:i}=o;return{...o,statusCode:i.statusCode||0,headers:i.headers||T({}),error:{...i,body:i.data||i}}}return o}}async function ot({url:e,httpClient:t,clientOptions:r}){let{request:o,maskSensitiveHeaderData:i,includeRequestInErrorResponse:s,includeResponseHeaders:a}=r;try{let n=await U({url:e,...r,httpClient:t,method:r.method,...r.body?{body:r.body}:{}});if(a||(n.headers=null),n.statusCode>=200&&n.statusCode<300)return r.method=="HEAD"?{body:null,statusCode:n.statusCode,retryCount:n.retryCount,headers:T(n.headers)}:{body:n.data,statusCode:n.statusCode,retryCount:n.retryCount,headers:T(n.headers)};let u=N({code:n.data?.errors?.[0].code,message:n?.data?.message||n?.message,statusCode:n.statusCode||n?.data?.statusCode,method:r.method,headers:T(n.headers),body:n.data,error:n.data,retryCount:n.retryCount,...s?{originalRequest:i?k(o):o}:{uri:o.uri}});return{...u,error:u}}catch(n){let u=a?T(n.response?.headers):null,l=n.response?.status||n.response?.statusCode||n.response?.data.statusCode||0,d=n.response?.data?.message;throw{body:null,error:N({statusCode:l,code:"NetworkError",status:l,message:d||n.message,headers:u,body:n.response?.data||n,error:n.response?.data||n,...s?{originalRequest:i?k(o):o}:{uri:o.uri}})}}}function V(e){ye(e);let{host:t,credentialsMode:r,httpClient:o,timeout:i,enableRetry:s,retryConfig:a,getAbortController:n,includeOriginalRequest:u,includeRequestInErrorResponse:l=!0,includeResponseHeaders:d=!0,maskSensitiveHeaderData:c,httpClientOptions:M}=e;return C=>async p=>{let S=t.replace(/\/$/,"")+p.uri,h={...p.headers};Object.prototype.hasOwnProperty.call(h,"Content-Type")||Object.prototype.hasOwnProperty.call(h,"content-type")||(h["Content-Type"]="application/json"),h["Content-Type"]===null&&delete h["Content-Type"];let w=g.HEADERS_CONTENT_TYPES.indexOf(h["Content-Type"])>-1&&typeof p.body=="string"||Q(p.body)?p.body:JSON.stringify(p.body||void 0);w&&(typeof w=="string"||Q(w))&&(h["Content-Length"]=I(w));let f={enableRetry:s,retryConfig:a,request:p,method:p.method,headers:h,includeRequestInErrorResponse:l,maskSensitiveHeaderData:c,includeResponseHeaders:d,...M};r&&(f.credentialsMode=r),i&&(f.timeout=i,f.getAbortController=n),w&&(f.body=w);let q=await ot({url:S,clientOptions:f,httpClient:o}),x={...p,includeOriginalRequest:u,maskSensitiveHeaderData:c,response:q};return C(x)}}function G(e){return t=>async r=>{let o=await t(r),i=Object.assign({},o),{loggerFn:s=console.log}=e||{};return s&&typeof s=="function"&&s(o),i}}function Y({concurrency:e=20}){let t=0,r=[],o=()=>0>=e?Promise.resolve():new Promise(s=>{let a=()=>{t<e?(t++,s()):r.push(a)};a()}),i=()=>{if(t--,r.length>0){let s=r.shift();s&&s()}};return s=>a=>o().then(()=>{let n={...a,resolve(u){a.resolve(u),i()},reject(u){a.reject(u),i()}};return s(n).finally(()=>{i()})})}var ke={name:"@commercetools/ts-client",version:"3.2.2",engines:{node:">=18"},description:"commercetools Composable Commerce TypeScript SDK client.",keywords:["commercetools","composable commerce","sdk","typescript","client","middleware","http","oauth","auth"],homepage:"https://github.com/commercetools/commercetools-sdk-typescript",license:"MIT",directories:{lib:"lib",test:"test"},publishConfig:{access:"public"},repository:{type:"git",url:"git+https://github.com/commercetools/commercetools-sdk-typescript.git"},bugs:{url:"https://github.com/commercetools/commercetools-sdk-typescript/issues"},dependencies:{buffer:"^6.0.3"},files:["dist","CHANGELOG.md"],author:"Chukwuemeka Ajima <meeky.ae@gmail.com>",main:"dist/commercetools-ts-client.cjs.js",module:"dist/commercetools-ts-client.esm.js",browser:{"./dist/commercetools-ts-client.cjs.js":"./dist/commercetools-ts-client.browser.cjs.js","./dist/commercetools-ts-client.esm.js":"./dist/commercetools-ts-client.browser.esm.js"},devDependencies:{"common-tags":"1.8.2",dotenv:"16.4.7",jest:"29.7.0",nock:"14.0.1","organize-imports-cli":"0.10.0"},scripts:{organize_imports:"find src -type f -name '*.ts' | xargs organize-imports-cli",postbuild:"yarn organize_imports",post_process_generate:"yarn organize_imports",docs:"typedoc --out docs"}};function W(e){return t=>async r=>{let o=se({...e,name:`${e.name?e.name+"/":""}commercetools-sdk-javascript-v3/${ke.version}`}),i={...r,headers:{...r.headers,"User-Agent":o}};return t(i)}}function nt({middlewares:e}){return e.length===1?e[0]:e.slice().reduce((r,o)=>(...i)=>r(o.apply(null,i)))}var Pe;function de(e,t,r){if(ae("process",e,{allowedMethods:["GET"]}),typeof t!="function")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');let o={total:Number.POSITIVE_INFINITY,accumulate:!0,...r};return new Promise((i,s)=>{let a,n="";if(e&&e.uri){let[C,p]=e.uri.split("?");a=C,n=p}let l={limit:20,...{...me(n)}},d=o.total,c=!1,M=async(C,p=[])=>{let S=l.limit<d?l.limit:d,h=ne({...l,limit:S}),w={sort:"id asc",withTotal:!1,...C?{where:`id > "${C}"`}:{}},f=ne(w),q={...e,uri:`${a}?${f}&${h}`};try{let x=await P(Pe).execute(q),{results:X,count:F}=x?.body||{};if(!F&&c)return i(p||[]);let m=await Promise.resolve(t(x)),y;if(c=!0,o.accumulate&&(y=p.concat(m||[])),d-=F,F<l.limit||!d)return i(y||[]);let $=X[F-1],Z=$&&$.id;M(Z,y)}catch(x){s(x)}};M()})}function P(e){Pe=e,Me(e);let t=!1,r={async resolve(i){let{response:s,includeOriginalRequest:a,maskSensitiveHeaderData:n,...u}=i,{retryCount:l,...d}=s;return t=n,{body:null,error:null,reject:i.reject,resolve:i.resolve,...d,...a?{originalRequest:u}:{},...s?.retryCount?{retryCount:s.retryCount}:{}}}},o=nt(e)(r.resolve);return{process:de,execute(i){return ae("exec",i),new Promise(async(s,a)=>{try{let n=await o({reject:a,resolve:s,...i});if(n.error)return a(n.error);n.originalRequest&&t&&(n.originalRequest=k(n.originalRequest)),s(n)}catch(n){a(n)}})}}}var{createAuthMiddlewareForPasswordFlow:st,createAuthMiddlewareForAnonymousSessionFlow:at,createAuthMiddlewareForClientCredentialsFlow:lt,createAuthMiddlewareForRefreshTokenFlow:dt,createAuthMiddlewareForExistingTokenFlow:ut,createCorrelationIdMiddleware:ct,createHttpMiddleware:pt,createLoggerMiddleware:ht,createQueueMiddleware:wt,createUserAgentMiddleware:Se,createConcurrentModificationMiddleware:ft}=Ae,L=class{projectKey;authMiddleware;httpMiddleware;userAgentMiddleware;correlationIdMiddleware;loggerMiddleware;queueMiddleware;concurrentMiddleware;telemetryMiddleware;beforeMiddleware;afterMiddleware;middlewares=[];constructor(){this.userAgentMiddleware=Se({})}withProjectKey(t){return this.projectKey=t,this}defaultClient(t,r,o,i,s,a){return this.withClientCredentialsFlow({host:o,projectKey:i||this.projectKey,credentials:r,httpClient:a||fetch,scopes:s}).withHttpMiddleware({host:t,httpClient:a||fetch})}withAuthMiddleware(t){return this.authMiddleware=t,this}withMiddleware(t){return this.middlewares.push(t),this}withClientCredentialsFlow(t){return this.withAuthMiddleware(lt({host:t.host||g.CTP_AUTH_URL,projectKey:t.projectKey||this.projectKey,credentials:{clientId:t.credentials.clientId||null,clientSecret:t.credentials.clientSecret||null},oauthUri:t.oauthUri||null,scopes:t.scopes,httpClient:t.httpClient||fetch,...t}))}withPasswordFlow(t){return this.withAuthMiddleware(st({host:t.host||g.CTP_AUTH_URL,projectKey:t.projectKey||this.projectKey,credentials:{clientId:t.credentials.clientId||null,clientSecret:t.credentials.clientSecret||null,user:{username:t.credentials.user.username||null,password:t.credentials.user.password||null}},httpClient:t.httpClient||fetch,...t}))}withAnonymousSessionFlow(t){return this.withAuthMiddleware(at({host:t.host||g.CTP_AUTH_URL,projectKey:this.projectKey||t.projectKey,credentials:{clientId:t.credentials.clientId||null,clientSecret:t.credentials.clientSecret||null,anonymousId:t.credentials.anonymousId||null},httpClient:t.httpClient||fetch,...t}))}withRefreshTokenFlow(t){return this.withAuthMiddleware(dt({host:t.host||g.CTP_AUTH_URL,projectKey:this.projectKey||t.projectKey,credentials:{clientId:t.credentials.clientId||null,clientSecret:t.credentials.clientSecret||null},httpClient:t.httpClient||fetch,refreshToken:t.refreshToken||null,...t}))}withExistingTokenFlow(t,r){return this.withAuthMiddleware(ut(t,{force:r.force||!0,...r}))}withHttpMiddleware(t){return this.httpMiddleware=pt({host:t.host||g.CTP_API_URL,httpClient:t.httpClient||fetch,...t}),this}withUserAgentMiddleware(t){return this.userAgentMiddleware=Se(t),this}withQueueMiddleware(t){return this.queueMiddleware=wt({concurrency:t.concurrency||g.CONCURRENCT_REQUEST,...t}),this}withLoggerMiddleware(t){return this.loggerMiddleware=ht(t),this}withCorrelationIdMiddleware(t){return this.correlationIdMiddleware=ct({generate:t?.generate,...t}),this}withConcurrentModificationMiddleware(t){return this.concurrentMiddleware=ft(t?.concurrentModificationHandlerFn),this}withTelemetryMiddleware(t){let{createTelemetryMiddleware:r,...o}=t;return this.withUserAgentMiddleware({customAgent:o?.userAgent||"typescript-sdk-apm-middleware"}),this.telemetryMiddleware=r(o),this}withBeforeExecutionMiddleware(t){let{middleware:r,...o}=t||{};return this.beforeMiddleware=t.middleware(o),this}withAfterExecutionMiddleware(t){let{middleware:r,...o}=t||{};return this.afterMiddleware=t.middleware(o),this}build(){let t=this.middlewares.slice();return this.telemetryMiddleware&&t.push(this.telemetryMiddleware),this.correlationIdMiddleware&&t.push(this.correlationIdMiddleware),this.userAgentMiddleware&&t.push(this.userAgentMiddleware),this.authMiddleware&&t.push(this.authMiddleware),this.beforeMiddleware&&t.push(this.beforeMiddleware),this.queueMiddleware&&t.push(this.queueMiddleware),this.loggerMiddleware&&t.push(this.loggerMiddleware),this.concurrentMiddleware&&t.push(this.concurrentMiddleware),this.httpMiddleware&&t.push(this.httpMiddleware),this.afterMiddleware&&t.push(this.afterMiddleware),P({middlewares:t})}};return je(mt);})();
|
|
1
|
+
var window;(window||={})["@commercetools/ts-client"]=(()=>{var ce=Object.defineProperty;var Fe=Object.getOwnPropertyDescriptor;var Ie=Object.getOwnPropertyNames;var Ne=Object.prototype.hasOwnProperty;var pe=(e,r)=>{for(var t in r)ce(e,t,{get:r[t],enumerable:!0})},Ue=(e,r,t,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of Ie(r))!Ne.call(e,i)&&i!==t&&ce(e,i,{get:()=>r[i],enumerable:!(o=Fe(r,i))||o.enumerable});return e};var je=e=>Ue(ce({},"__esModule",{value:!0}),e);var yr={};pe(yr,{ClientBuilder:()=>L,Process:()=>ue,createAuthMiddlewareForAnonymousSessionFlow:()=>v,createAuthMiddlewareForClientCredentialsFlow:()=>H,createAuthMiddlewareForExistingTokenFlow:()=>_,createAuthMiddlewareForPasswordFlow:()=>B,createAuthMiddlewareForRefreshTokenFlow:()=>K,createClient:()=>P,createConcurrentModificationMiddleware:()=>z,createCorrelationIdMiddleware:()=>J,createErrorMiddleware:()=>V,createHttpMiddleware:()=>G,createLoggerMiddleware:()=>Y,createQueueMiddleware:()=>W,createUserAgentMiddleware:()=>X});var Ae={};pe(Ae,{createAuthMiddlewareForAnonymousSessionFlow:()=>v,createAuthMiddlewareForClientCredentialsFlow:()=>H,createAuthMiddlewareForExistingTokenFlow:()=>_,createAuthMiddlewareForPasswordFlow:()=>B,createAuthMiddlewareForRefreshTokenFlow:()=>K,createConcurrentModificationMiddleware:()=>z,createCorrelationIdMiddleware:()=>J,createErrorMiddleware:()=>V,createHttpMiddleware:()=>G,createLoggerMiddleware:()=>Y,createQueueMiddleware:()=>W,createUserAgentMiddleware:()=>X});function I(e){return e&&typeof e=="string"?new TextEncoder().encode(e).length.toString():e&&e instanceof Uint8Array?e.byteLength.toString():e&&typeof e=="object"?new TextEncoder().encode(JSON.stringify(e)).length.toString():"0"}var g={};pe(g,{CONCURRENCT_REQUEST:()=>He,CTP_API_URL:()=>_e,CTP_AUTH_URL:()=>Be,DEFAULT_HEADERS:()=>he,HEADERS_CONTENT_TYPES:()=>ve});var ve=["application/json","application/graphql"],He=20,_e="https://api.europe-west1.gcp.commercetools.com",Be="https://auth.europe-west1.gcp.commercetools.com",he=["content-type","access-control-allow-origin","access-control-allow-headers","access-control-allow-methods","access-control-expose-headers","access-control-max-ag","x-correlation-id","server-timing","date","server","transfer-encoding","access-control-max-age","content-encoding","x-envoy-upstream-service-time","via","alt-svc","connection"];function b(e,r,t={}){this.code=t.code??=this.constructor.name,this.statusCode=e,this.status=e,this.message=r,Object.assign(this,t),this.name=this.constructor.name,this.constructor.prototype.__proto__=Error.prototype,Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}function be(...e){b.call(this,0,...e)}function Te(...e){b.call(this,...e)}function Ke(...e){b.call(this,400,...e)}function Le(...e){b.call(this,401,...e)}function $e(...e){b.call(this,403,...e)}function De(...e){b.call(this,404,...e)}function Qe(...e){b.call(this,409,...e)}function ze(...e){b.call(this,500,...e)}function Je(...e){b.call(this,503,...e)}function we(e){switch(e){case 0:return be;case 400:return Ke;case 401:return Le;case 403:return $e;case 404:return De;case 409:return Qe;case 500:return ze;case 503:return Je;default:return}}function Ve({statusCode:e,message:r,...t}){let o=r||"Unexpected non-JSON error response";e===404&&(o=`URI not found: ${t.originalRequest?.uri||t.uri}`);let i=we(e);return i?new i(o,t):new Te(e,o,t)}var N=Ve;function Ge(e,r){return[503,...e].includes(r?.status||r?.statusCode)}async function Ye(e,r){async function t(){return await e({...r,headers:{...r.headers}})}return t().catch(o=>Promise.reject(o))}async function U(e){let{url:r,httpClient:t,...o}=e;return await Ye(async s=>{let{enableRetry:a,retryConfig:n,timeout:u,getAbortController:l}=o,{retryCodes:d=[],maxDelay:c=1/0,maxRetries:M=3,backoff:C=!0,retryDelay:p=200,retryOnAbort:S=!0}=n||{},h,w,f=0,q;fe(d);async function x(){return t(r,{...s,...o,headers:{...o.headers},...o.body?{data:o.body}:{},withCredentials:s.credentialsMode==="include"})}function Z(){let y=(l?l():null)||new AbortController;return o.abortController=y,o.signal=y.signal,y}async function F(){let y=async(re,qe)=>{let D={};if(u){let O=Z();q=setTimeout(()=>{O.abort(),O=Z()},u)}try{if(D=await x(),D.status>399&&Ge(re,D))return{_response:D,shouldRetry:!0}}catch(O){if((O.name.includes("AbortError")||O.name.includes("TimeoutError"))&&qe)return{_response:O,shouldRetry:!0};throw O}finally{clearTimeout(q)}return{_response:D,shouldRetry:!1}},{_response:$,shouldRetry:ee}=await y(d,S);for(;a&&ee&&f<M;){f++,await oe(te({retryCount:f,retryDelay:p,maxRetries:M,backoff:C,maxDelay:c}));let re=await y(d,S);$=re._response,ee=re.shouldRetry}return $}let m=await F();try{m.text&&typeof m.text=="function"?(h=await m.text()||JSON.stringify(m[Object.getOwnPropertySymbols(m)[1]]),w=JSON.parse(h)):w=m.data||m}catch(y){throw y}return{data:w,retryCount:f,statusCode:m.status||m.statusCode||w.statusCode,headers:m.headers}},{validateStatus:s=>!0})}function ie(){return("1000000-1000-4000-8000"+-1e11).replace(/[018]/g,e=>(parseInt(e)^Math.floor(Math.random()*256)&15>>parseInt(e)/4).toString(16))}function We(e){return he.reduce((r,t)=>{let o=e[t]?e[t]:typeof e.get=="function"?e.get(t):null;return o&&(r[t]=o),r},{})}function T(e){if(!e)return null;if(e.raw&&typeof e.raw=="function")return e.raw();if(!e.forEach)return We(e);let r={};return e.forEach((t,o)=>r[o]=t),r}function Q(e){return e!=null&&e.constructor!=null&&typeof e.constructor.isBuffer=="function"&&e.constructor.isBuffer(e)}function k(e){let r=JSON.parse(JSON.stringify(e));return r?.headers&&(r.headers.Authorization&&(r.headers.Authorization="Bearer ********"),r.headers.authorization&&(r.headers.authorization="Bearer ********")),r}function j(e,r){return{...r,headers:{...r.headers,Authorization:`Bearer ${e}`}}}var me=["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 te({retryCount:e,retryDelay:r,backoff:t,maxDelay:o}){return t&&e!==0?Math.min(Math.round((Math.random()+1)*r*2**e),o):r}Math.min(Math.round((Math.random()+1)*200*2**10),1/0);function oe(e){return new Promise(r=>{setTimeout(r,e)})}function R(e){if(!e?.credentials?.clientId||!e.projectKey||!e.host)throw new Error("Missing required options.");return{clientId:e.credentials.clientId,host:e.host,projectKey:e.projectKey}}function ne(e){return Date.now()+e*1e3-5*60*1e3}function A(e){let r=e;return{get:t=>r,set:(t,o)=>{r=t}}}function xe(e){return typeof e<"u"&&e!==null}function Xe(e){return xe(e)?typeof e=="string"?e:Object.fromEntries(Object.entries(e).filter(([r,t])=>![null,void 0,""].includes(t))):""}function Ze(e){let r={},t=new URLSearchParams(e);for(let o of t.keys())t.getAll(o).length>1?r[o]=t.getAll(o):r[o]=t.get(o);return r}function er(e){if(e=Xe(e),!e)return"";let r=new URLSearchParams(e);for(let[t,o]of Object.entries(e))Array.isArray(o)&&(r.delete(t),o.filter(xe).forEach(i=>r.append(t,i)));return r.toString()}function ye(e,r=Ze){return r(e)}function se(e,r=er){return r(e)}var rr=()=>typeof window<"u"&&window.document&&window.document.nodeType===9;function tr(){if(rr())return window.navigator.userAgent;let e=process?.version?.slice(1)||"unknown",r=`(${process?.platform||""}; ${process?.arch||""})`;return`node.js/${e} ${r.trim()}`}function ae(e){let r=null,t=null;if(!e)throw new Error("Missing required option `name`");let o=e.version?`${e.name}/${e.version}`:e.name;e.libraryName&&!e.libraryVersion?r=e.libraryName:e.libraryName&&e.libraryVersion&&(r=`${e.libraryName}/${e.libraryVersion}`),e.contactUrl&&!e.contactEmail?t=`(+${e.contactUrl})`:!e.contactUrl&&e.contactEmail?t=`(+${e.contactEmail})`:e.contactUrl&&e.contactEmail&&(t=`(+${e.contactUrl}; +${e.contactEmail})`);let i=tr(),s=e.customAgent||"";return[o,i,r,t,s].filter(Boolean).join(" ")}function Me(e){if(!e.host)throw new Error("Request `host` or `url` is missing or invalid, please pass in a valid host e.g `host: http://a-valid-host-url`");if(!e.httpClient&&typeof e.httpClient!="function")throw new Error("An `httpClient` is not available, please pass in a `fetch` or `axios` instance as an option or have them globally available.");if(e.httpClientOptions&&Object.prototype.toString.call(e.httpClientOptions)!=="[object Object]")throw new Error("`httpClientOptions` must be an object type")}function fe(e){if(!Array.isArray(e))throw new Error("`retryCodes` option must be an array of retry status (error) codes and/or messages.")}function ge(e){if(!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")}function le(e,r,t={allowedMethods:me}){if(!r)throw new Error(`The "${e}" function requires a "Request" object as an argument. See https://commercetools.github.io/nodejs/sdk/Glossary.html#clientrequest`);if(typeof r.uri!="string")throw new Error(`The "${e}" Request object requires a valid uri. See https://commercetools.github.io/nodejs/sdk/Glossary.html#clientrequest`);if(!t.allowedMethods.includes(r.method))throw new Error(`The "${e}" Request object requires a valid method. See https://commercetools.github.io/nodejs/sdk/Glossary.html#clientrequest`)}function Ce(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)");let{clientId:r,clientSecret:t}=e.credentials||{};if(!(r&&t))throw new Error("Missing required credentials (clientId, clientSecret)");let o=e.scopes?e.scopes.join(" "):void 0,i=btoa(`${r}:${t}`),s=e.oauthUri||"/oauth/token",a=e.host.replace(/\/$/,"")+s,n=`grant_type=client_credentials${o?`&scope=${o}`:""}`;return{url:a,body:n,basicAuth:i}}function Ee(e){if(!e)throw new Error("Missing required options");if(!e.projectKey)throw new Error("Missing required option (projectKey)");let r=e.projectKey;e.oauthUri=e.oauthUri||`/oauth/${r}/anonymous/token`;let t=Ce(e);return e.credentials.anonymousId&&(t.body+=`&anonymous_id=${e.credentials.anonymousId}`),{...t}}function de(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)");let{clientId:r,clientSecret:t}=e.credentials;if(!(r&&t))throw new Error("Missing required credentials (clientId, clientSecret)");let o=btoa(`${r}:${t}`),i=e.oauthUri||"/oauth/token",s=e.host.replace(/\/$/,"")+i,a=`grant_type=refresh_token&refresh_token=${encodeURIComponent(e.refreshToken)}`;return{basicAuth:o,url:s,body:a}}function Oe(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)");let{clientId:r,clientSecret:t,user:o}=e.credentials,i=e.projectKey;if(!(r&&t&&o))throw new Error("Missing required credentials (clientId, clientSecret, user)");let{username:s,password:a}=o;if(!(s&&a))throw new Error("Missing required user credentials (username, password)");let n=(e.scopes||[]).join(" "),u=n?`&scope=${n}`:"",l=btoa(`${r}:${t}`),d=e.oauthUri||`/oauth/${i}/customers/token`,c=e.host.replace(/\/$/,"")+d,M=`grant_type=password&username=${encodeURIComponent(s)}&password=${encodeURIComponent(a)}${u}`;return{basicAuth:l,url:c,body:M}}async function Re(e){let{httpClient:r,httpClientOptions:t,tokenCache:o,userOption:i,tokenCacheObject:s}=e,a=e.url,n=e.body,u=e.basicAuth;if(!r||typeof r!="function")throw new Error("an `httpClient` is not available, please pass in a `fetch` or `axios` instance as an option or have them globally available.");if(s&&s.refreshToken&&(!s.token||s.token&&Date.now()>s.expirationTime)){if(!i)throw new Error("Missing required options.");let d={...de({...i,refreshToken:s.refreshToken})};a=d.url,n=d.body,u=d.basicAuth}let l;try{if(l=await U({url:a,method:"POST",headers:{Authorization:`Basic ${u}`,"Content-Type":"application/x-www-form-urlencoded","Content-Length":I(n)},httpClient:r,httpClientOptions:t,body:n}),l.statusCode>=200&&l.statusCode<300){let{access_token:d,expires_in:c,refresh_token:M}=l?.data,C=ne(c);return o.set({token:d,expirationTime:C,refreshToken:M}),Promise.resolve(!0)}throw N({code:l.data.error,statusCode:l.data.statusCode,message:l.data.message,error:l.data.errors})}catch(d){throw d}}async function E(e,r=null,t,o,i,s,a,n){let u={request:e,tokenCache:i,httpClient:a.httpClient||fetch,httpClientOptions:a.httpClientOptions,...s(a),userOption:a,next:n},l=async d=>{let c=Object.assign({},d);return c.statusCode==401&&(r=Re(u),await r,r=null,t=i.get(o),c=await n(j(t.token,e))),c};return e.headers&&(e.headers.Authorization||e.headers.authorization)?l(await n(e)):(t=i.get(o),t&&t.token&&Date.now()<t.expirationTime?l(await n(j(t.token,e))):(r?await r:(r=Re(u),await r,r=null),t=i.get(o),n(j(t.token,e))))}function v(e){let r=e.tokenCache||A({token:"",expirationTime:-1}),t,o=null,i=R(e);return s=>async a=>E(a,o,t,i,r,Ee,e,s)}function H(e){let r=e.tokenCache||A({token:"",expirationTime:-1}),t,o=null,i=R(e);return s=>async a=>E(a,o,t,i,r,Ce,e,s)}function _(e,r){return t=>async o=>{if(typeof e!="string")throw new Error("authorization must be a string");let i=r?.force===void 0?!0:r.force;if(!e||o.headers&&(o.headers.Authorization||o.headers.authorization)&&i===!1)return t(o);let s={...o,headers:{...o.headers,Authorization:e}};return t(s)}}function B(e){let r=e.tokenCache||A({token:"",expirationTime:-1}),t,o=null,i=R(e);return s=>async a=>E(a,o,t,i,r,Oe,e,s)}function K(e){let r=e.tokenCache||A({token:"",tokenCacheKey:null}),t,o=null,i=R(e);return s=>async a=>E(a,o,t,i,r,de,e,s)}function z(e){return r=>async t=>{let o=await r(t);if(o.statusCode==409){let i=o.error.body?.errors?.[0]?.currentVersion;if(i)return e&&typeof e=="function"?t.body=await e(i,t,o):t.body=typeof t.body=="string"?{...JSON.parse(t.body),version:i}:{...t.body,version:i},r(t)}return o}}function J(e){return r=>t=>{let o={...t,headers:{...t.headers,"X-Correlation-ID":e.generate&&typeof e.generate=="function"?e.generate():ie()}};return r(o)}}function V(e={}){return r=>async t=>{let o=await r(t);if(o.error){let{error:i}=o;return e.handler&&typeof e.handler=="function"?e.handler({error:i,request:t,response:o,next:r}):{...o,statusCode:i.statusCode||0,headers:i.headers||T({}),body:i,error:i}}return o}}async function or({url:e,httpClient:r,clientOptions:t}){let{request:o,maskSensitiveHeaderData:i,includeRequestInErrorResponse:s,includeResponseHeaders:a}=t;try{let n=await U({url:e,...t,httpClient:r,method:t.method,...t.body?{body:t.body}:{}});if(a||(n.headers=null),n.statusCode>=200&&n.statusCode<300)return t.method=="HEAD"?{body:null,statusCode:n.statusCode,retryCount:n.retryCount,headers:T(n.headers)}:{body:n.data,statusCode:n.statusCode,retryCount:n.retryCount,headers:T(n.headers)};let u=N({code:n.data?.errors?.[0].code,message:n?.data?.message||n?.message,statusCode:n.statusCode||n?.data?.statusCode,method:t.method,headers:T(n.headers),body:n.data,error:n.data,retryCount:n.retryCount,...s?{originalRequest:i?k(o):o}:{uri:o.uri}});return{...u,error:u}}catch(n){let u=a?T(n.response?.headers):null,l=n.response?.status||n.response?.statusCode||n.response?.data.statusCode||0,d=n.response?.data?.message;throw{body:null,error:N({statusCode:l,code:"NetworkError",status:l,message:d||n.message,headers:u,body:n.response?.data||n,error:n.response?.data||n,...s?{originalRequest:i?k(o):o}:{uri:o.uri}})}}}function G(e){Me(e);let{host:r,credentialsMode:t,httpClient:o,timeout:i,enableRetry:s,retryConfig:a,getAbortController:n,includeOriginalRequest:u,includeRequestInErrorResponse:l=!0,includeResponseHeaders:d=!0,maskSensitiveHeaderData:c,httpClientOptions:M}=e;return C=>async p=>{let S=r.replace(/\/$/,"")+p.uri,h={...p.headers};Object.prototype.hasOwnProperty.call(h,"Content-Type")||Object.prototype.hasOwnProperty.call(h,"content-type")||(h["Content-Type"]="application/json"),h["Content-Type"]===null&&delete h["Content-Type"];let w=g.HEADERS_CONTENT_TYPES.indexOf(h["Content-Type"])>-1&&typeof p.body=="string"||Q(p.body)?p.body:JSON.stringify(p.body||void 0);w&&(typeof w=="string"||Q(w))&&(h["Content-Length"]=I(w));let f={enableRetry:s,retryConfig:a,request:p,method:p.method,headers:h,includeRequestInErrorResponse:l,maskSensitiveHeaderData:c,includeResponseHeaders:d,...M};t&&(f.credentialsMode=t),i&&(f.timeout=i,f.getAbortController=n),w&&(f.body=w);let q=await or({url:S,clientOptions:f,httpClient:o}),x={...p,includeOriginalRequest:u,maskSensitiveHeaderData:c,response:q};return C(x)}}function Y(e){return r=>async t=>{let o=await r(t),i=Object.assign({},o),{loggerFn:s=console.log}=e||{};return s&&typeof s=="function"&&s(o),i}}function W({concurrency:e=20}){let r=0,t=[],o=()=>0>=e?Promise.resolve():new Promise(s=>{let a=()=>{r<e?(r++,s()):t.push(a)};a()}),i=()=>{if(r--,t.length>0){let s=t.shift();s&&s()}};return s=>a=>o().then(()=>{let n={...a,resolve(u){a.resolve(u),i()},reject(u){a.reject(u),i()}};return s(n).finally(()=>{i()})})}var ke={name:"@commercetools/ts-client",version:"3.3.1",engines:{node:">=18"},description:"commercetools Composable Commerce TypeScript SDK client.",keywords:["commercetools","composable commerce","sdk","typescript","client","middleware","http","oauth","auth"],homepage:"https://github.com/commercetools/commercetools-sdk-typescript",license:"MIT",directories:{lib:"lib",test:"test"},publishConfig:{access:"public"},repository:{type:"git",url:"git+https://github.com/commercetools/commercetools-sdk-typescript.git"},bugs:{url:"https://github.com/commercetools/commercetools-sdk-typescript/issues"},dependencies:{buffer:"^6.0.3"},files:["dist","CHANGELOG.md"],author:"Chukwuemeka Ajima <meeky.ae@gmail.com>",main:"dist/commercetools-ts-client.cjs.js",module:"dist/commercetools-ts-client.esm.js",browser:{"./dist/commercetools-ts-client.cjs.js":"./dist/commercetools-ts-client.browser.cjs.js","./dist/commercetools-ts-client.esm.js":"./dist/commercetools-ts-client.browser.esm.js"},devDependencies:{"common-tags":"1.8.2",dotenv:"16.5.0",jest:"29.7.0",nock:"14.0.4","organize-imports-cli":"0.10.0"},scripts:{organize_imports:"find src -type f -name '*.ts' | xargs organize-imports-cli",postbuild:"yarn organize_imports",post_process_generate:"yarn organize_imports",docs:"typedoc --out docs"}};function X(e){return r=>async t=>{let o=ae({...e,name:`${e.name?e.name+"/":""}commercetools-sdk-javascript-v3/${ke.version}`}),i={...t,headers:{...t.headers,"User-Agent":o}};return r(i)}}function nr({middlewares:e}){return e.length===1?e[0]:e.slice().reduce((t,o)=>(...i)=>t(o.apply(null,i)))}var Pe;function ue(e,r,t){if(le("process",e,{allowedMethods:["GET"]}),typeof r!="function")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');let o={total:Number.POSITIVE_INFINITY,accumulate:!0,...t};return new Promise((i,s)=>{let a,n="";if(e&&e.uri){let[C,p]=e.uri.split("?");a=C,n=p}let l={limit:20,...{...ye(n)}},d=o.total,c=!1,M=async(C,p=[])=>{let S=l.limit<d?l.limit:d,h=se({...l,limit:S}),w={sort:"id asc",withTotal:!1,...C?{where:`id > "${C}"`}:{}},f=se(w),q={...e,uri:`${a}?${f}&${h}`};try{let x=await P(Pe).execute(q),{results:Z,count:F}=x?.body||{};if(!F&&c)return i(p||[]);let m=await Promise.resolve(r(x)),y;if(c=!0,o.accumulate&&(y=p.concat(m||[])),d-=F,F<l.limit||!d)return i(y||[]);let $=Z[F-1],ee=$&&$.id;M(ee,y)}catch(x){s(x)}};M()})}function P(e){Pe=e,ge(e);let r=!1,t={async resolve(i){let{response:s,includeOriginalRequest:a,maskSensitiveHeaderData:n,...u}=i,{retryCount:l,...d}=s;return r=n,{body:null,error:null,reject:i.reject,resolve:i.resolve,...d,...a?{originalRequest:u}:{},...s?.retryCount?{retryCount:s.retryCount}:{}}}},o=nr(e)(t.resolve);return{process:ue,execute(i){return le("exec",i),new Promise(async(s,a)=>{try{let n=await o({reject:a,resolve:s,...i});if(n.error)return a(n.error);n.originalRequest&&r&&(n.originalRequest=k(n.originalRequest)),s(n)}catch(n){a(n)}})}}}var{createAuthMiddlewareForPasswordFlow:sr,createAuthMiddlewareForAnonymousSessionFlow:ar,createAuthMiddlewareForClientCredentialsFlow:lr,createAuthMiddlewareForRefreshTokenFlow:dr,createAuthMiddlewareForExistingTokenFlow:ur,createCorrelationIdMiddleware:cr,createHttpMiddleware:pr,createLoggerMiddleware:hr,createQueueMiddleware:wr,createUserAgentMiddleware:Se,createConcurrentModificationMiddleware:fr,createErrorMiddleware:mr}=Ae,L=class{projectKey;authMiddleware;httpMiddleware;userAgentMiddleware;correlationIdMiddleware;loggerMiddleware;queueMiddleware;concurrentMiddleware;telemetryMiddleware;beforeMiddleware;afterMiddleware;errorMiddleware;middlewares=[];constructor(){this.userAgentMiddleware=Se({})}withProjectKey(r){return this.projectKey=r,this}defaultClient(r,t,o,i,s,a){return this.withClientCredentialsFlow({host:o,projectKey:i||this.projectKey,credentials:t,httpClient:a||fetch,scopes:s}).withHttpMiddleware({host:r,httpClient:a||fetch})}withAuthMiddleware(r){return this.authMiddleware=r,this}withMiddleware(r){return this.middlewares.push(r),this}withErrorMiddleware(r){return this.errorMiddleware=mr(r),this}withClientCredentialsFlow(r){return this.withAuthMiddleware(lr({host:r.host||g.CTP_AUTH_URL,projectKey:r.projectKey||this.projectKey,credentials:{clientId:r.credentials.clientId||null,clientSecret:r.credentials.clientSecret||null},oauthUri:r.oauthUri||null,scopes:r.scopes,httpClient:r.httpClient||fetch,...r}))}withPasswordFlow(r){return this.withAuthMiddleware(sr({host:r.host||g.CTP_AUTH_URL,projectKey:r.projectKey||this.projectKey,credentials:{clientId:r.credentials.clientId||null,clientSecret:r.credentials.clientSecret||null,user:{username:r.credentials.user.username||null,password:r.credentials.user.password||null}},httpClient:r.httpClient||fetch,...r}))}withAnonymousSessionFlow(r){return this.withAuthMiddleware(ar({host:r.host||g.CTP_AUTH_URL,projectKey:this.projectKey||r.projectKey,credentials:{clientId:r.credentials.clientId||null,clientSecret:r.credentials.clientSecret||null,anonymousId:r.credentials.anonymousId||null},httpClient:r.httpClient||fetch,...r}))}withRefreshTokenFlow(r){return this.withAuthMiddleware(dr({host:r.host||g.CTP_AUTH_URL,projectKey:this.projectKey||r.projectKey,credentials:{clientId:r.credentials.clientId||null,clientSecret:r.credentials.clientSecret||null},httpClient:r.httpClient||fetch,refreshToken:r.refreshToken||null,...r}))}withExistingTokenFlow(r,t){return this.withAuthMiddleware(ur(r,{force:t.force||!0,...t}))}withHttpMiddleware(r){return this.httpMiddleware=pr({host:r.host||g.CTP_API_URL,httpClient:r.httpClient||fetch,...r}),this}withUserAgentMiddleware(r){return this.userAgentMiddleware=Se(r),this}withQueueMiddleware(r){return this.queueMiddleware=wr({concurrency:r.concurrency||g.CONCURRENCT_REQUEST,...r}),this}withLoggerMiddleware(r){return this.loggerMiddleware=hr(r),this}withCorrelationIdMiddleware(r){return this.correlationIdMiddleware=cr({generate:r?.generate,...r}),this}withConcurrentModificationMiddleware(r){return this.concurrentMiddleware=fr(r?.concurrentModificationHandlerFn),this}withTelemetryMiddleware(r){let{createTelemetryMiddleware:t,...o}=r;return this.withUserAgentMiddleware({customAgent:o?.userAgent||"typescript-sdk-apm-middleware"}),this.telemetryMiddleware=t(o),this}withBeforeExecutionMiddleware(r){let{middleware:t,...o}=r||{};return this.beforeMiddleware=r.middleware(o),this}withAfterExecutionMiddleware(r){let{middleware:t,...o}=r||{};return this.afterMiddleware=r.middleware(o),this}build(){let r=this.middlewares.slice();return this.telemetryMiddleware&&r.push(this.telemetryMiddleware),this.correlationIdMiddleware&&r.push(this.correlationIdMiddleware),this.userAgentMiddleware&&r.push(this.userAgentMiddleware),this.errorMiddleware&&r.push(this.errorMiddleware),this.authMiddleware&&r.push(this.authMiddleware),this.beforeMiddleware&&r.push(this.beforeMiddleware),this.queueMiddleware&&r.push(this.queueMiddleware),this.loggerMiddleware&&r.push(this.loggerMiddleware),this.concurrentMiddleware&&r.push(this.concurrentMiddleware),this.httpMiddleware&&r.push(this.httpMiddleware),this.afterMiddleware&&r.push(this.afterMiddleware),P({middlewares:r})}};return je(yr);})();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AfterExecutionMiddlewareOptions, AuthMiddlewareOptions, BeforeExecutionMiddlewareOptions, Client, ConcurrentModificationMiddlewareOptions, CorrelationIdMiddlewareOptions, Credentials, ExistingTokenMiddlewareOptions, HttpMiddlewareOptions, HttpUserAgentOptions, LoggerMiddlewareOptions, Middleware, PasswordAuthMiddlewareOptions, QueueMiddlewareOptions, RefreshAuthMiddlewareOptions, TelemetryOptions } from "../types/types.js";
|
|
1
|
+
import { AfterExecutionMiddlewareOptions, AuthMiddlewareOptions, BeforeExecutionMiddlewareOptions, Client, ConcurrentModificationMiddlewareOptions, CorrelationIdMiddlewareOptions, Credentials, ErrorMiddlewareOptions, ExistingTokenMiddlewareOptions, HttpMiddlewareOptions, HttpUserAgentOptions, LoggerMiddlewareOptions, Middleware, PasswordAuthMiddlewareOptions, QueueMiddlewareOptions, RefreshAuthMiddlewareOptions, TelemetryOptions } from "../types/types.js";
|
|
2
2
|
export default class ClientBuilder {
|
|
3
3
|
private projectKey;
|
|
4
4
|
private authMiddleware;
|
|
@@ -11,12 +11,14 @@ export default class ClientBuilder {
|
|
|
11
11
|
private telemetryMiddleware;
|
|
12
12
|
private beforeMiddleware;
|
|
13
13
|
private afterMiddleware;
|
|
14
|
+
private errorMiddleware;
|
|
14
15
|
private middlewares;
|
|
15
16
|
constructor();
|
|
16
17
|
withProjectKey(key: string): ClientBuilder;
|
|
17
18
|
defaultClient(baseUri: string, credentials: Credentials, oauthUri?: string, projectKey?: string, scopes?: Array<string>, httpClient?: Function): ClientBuilder;
|
|
18
19
|
private withAuthMiddleware;
|
|
19
20
|
withMiddleware(middleware: Middleware): ClientBuilder;
|
|
21
|
+
withErrorMiddleware(options?: ErrorMiddlewareOptions): ClientBuilder;
|
|
20
22
|
withClientCredentialsFlow(options: AuthMiddlewareOptions): ClientBuilder;
|
|
21
23
|
withPasswordFlow(options: PasswordAuthMiddlewareOptions): ClientBuilder;
|
|
22
24
|
withAnonymousSessionFlow(options: AuthMiddlewareOptions): ClientBuilder;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builder.d.ts","sourceRoot":"../../../../src/client","sources":["builder.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,+BAA+B,EAC/B,qBAAqB,EACrB,gCAAgC,EAChC,MAAM,EACN,uCAAuC,EACvC,8BAA8B,EAC9B,WAAW,EACX,8BAA8B,EAC9B,qBAAqB,EACrB,oBAAoB,EACpB,uBAAuB,EACvB,UAAU,EAEV,6BAA6B,EAC7B,sBAAsB,EACtB,4BAA4B,EAC5B,gBAAgB,EACjB,0BAAsB;
|
|
1
|
+
{"version":3,"file":"builder.d.ts","sourceRoot":"../../../../src/client","sources":["builder.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,+BAA+B,EAC/B,qBAAqB,EACrB,gCAAgC,EAChC,MAAM,EACN,uCAAuC,EACvC,8BAA8B,EAC9B,WAAW,EACX,sBAAsB,EACtB,8BAA8B,EAC9B,qBAAqB,EACrB,oBAAoB,EACpB,uBAAuB,EACvB,UAAU,EAEV,6BAA6B,EAC7B,sBAAsB,EACtB,4BAA4B,EAC5B,gBAAgB,EACjB,0BAAsB;AAmBvB,MAAM,CAAC,OAAO,OAAO,aAAa;IAChC,OAAO,CAAC,UAAU,CAAoB;IAEtC,OAAO,CAAC,cAAc,CAAsB;IAC5C,OAAO,CAAC,cAAc,CAAsB;IAC5C,OAAO,CAAC,mBAAmB,CAAsB;IACjD,OAAO,CAAC,uBAAuB,CAAsB;IACrD,OAAO,CAAC,gBAAgB,CAAsB;IAC9C,OAAO,CAAC,eAAe,CAAsB;IAC7C,OAAO,CAAC,oBAAoB,CAAsB;IAClD,OAAO,CAAC,mBAAmB,CAAsB;IACjD,OAAO,CAAC,gBAAgB,CAAsB;IAC9C,OAAO,CAAC,eAAe,CAAsB;IAC7C,OAAO,CAAC,eAAe,CAAsB;IAE7C,OAAO,CAAC,WAAW,CAAwB;;IAMpC,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa;IAK1C,aAAa,CAClB,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,WAAW,EACxB,QAAQ,CAAC,EAAE,MAAM,EACjB,UAAU,CAAC,EAAE,MAAM,EACnB,MAAM,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,EACtB,UAAU,CAAC,EAAE,QAAQ,GACpB,aAAa;IAahB,OAAO,CAAC,kBAAkB;IAKnB,cAAc,CAAC,UAAU,EAAE,UAAU,GAAG,aAAa;IAKrD,mBAAmB,CAAC,OAAO,CAAC,EAAE,sBAAsB,GAAG,aAAa;IAKpE,yBAAyB,CAC9B,OAAO,EAAE,qBAAqB,GAC7B,aAAa;IAiBT,gBAAgB,CACrB,OAAO,EAAE,6BAA6B,GACrC,aAAa;IAmBT,wBAAwB,CAC7B,OAAO,EAAE,qBAAqB,GAC7B,aAAa;IAgBT,oBAAoB,CACzB,OAAO,EAAE,4BAA4B,GACpC,aAAa;IAgBT,qBAAqB,CAC1B,aAAa,EAAE,MAAM,EACrB,OAAO,CAAC,EAAE,8BAA8B,GACvC,aAAa;IAST,kBAAkB,CAAC,OAAO,EAAE,qBAAqB,GAAG,aAAa;IAUjE,uBAAuB,CAC5B,OAAO,CAAC,EAAE,oBAAoB,GAC7B,aAAa;IAMT,mBAAmB,CAAC,OAAO,CAAC,EAAE,sBAAsB,GAAG,aAAa;IASpE,oBAAoB,CAAC,OAAO,CAAC,EAAE,uBAAuB;IAMtD,2BAA2B,CAChC,OAAO,CAAC,EAAE,8BAA8B,GACvC,aAAa;IAST,oCAAoC,CACzC,OAAO,CAAC,EAAE,uCAAuC,GAChD,aAAa;IAQT,uBAAuB,CAAC,CAAC,SAAS,gBAAgB,EACvD,OAAO,EAAE,CAAC,GACT,aAAa;IAUT,6BAA6B,CAClC,OAAO,EAAE,gCAAgC;IAOpC,4BAA4B,CACjC,OAAO,EAAE,+BAA+B;IAO1C,KAAK,IAAI,MAAM;CAkBhB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Client, ClientOptions, ClientRequest, ProcessFn, ProcessOptions } from "../types/types.js";
|
|
2
|
-
export declare function process(request: ClientRequest, fn: ProcessFn
|
|
2
|
+
export declare function process<T extends object = any>(request: ClientRequest, fn: ProcessFn<T>, processOpt?: ProcessOptions): Promise<Array<T>>;
|
|
3
3
|
export default function createClient(middlewares: ClientOptions): Client;
|
|
4
4
|
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"../../../../src/client","sources":["client.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,MAAM,EACN,aAAa,EACb,aAAa,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"../../../../src/client","sources":["client.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,MAAM,EACN,aAAa,EACb,aAAa,EAOb,SAAS,EACT,cAAc,EACf,0BAAsB;AAmBvB,wBAAgB,OAAO,CAAC,CAAC,SAAS,MAAM,GAAG,GAAG,EAC5C,OAAO,EAAE,aAAa,EACtB,EAAE,EAAE,SAAS,CAAC,CAAC,CAAC,EAChB,UAAU,CAAC,EAAE,cAAc,GAC1B,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CA0FnB;AAED,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,WAAW,EAAE,aAAa,GAAG,MAAM,CAoDvE"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { ClientBuilder, createClient, Process } from "./client/index.js";
|
|
2
|
-
export { createAuthMiddlewareForAnonymousSessionFlow, createAuthMiddlewareForClientCredentialsFlow, createAuthMiddlewareForExistingTokenFlow, createAuthMiddlewareForPasswordFlow, createAuthMiddlewareForRefreshTokenFlow, createConcurrentModificationMiddleware, createCorrelationIdMiddleware, createHttpMiddleware, createLoggerMiddleware, createQueueMiddleware, createUserAgentMiddleware } from "./middleware/index.js";
|
|
2
|
+
export { createAuthMiddlewareForAnonymousSessionFlow, createAuthMiddlewareForClientCredentialsFlow, createAuthMiddlewareForExistingTokenFlow, createAuthMiddlewareForPasswordFlow, createAuthMiddlewareForRefreshTokenFlow, createConcurrentModificationMiddleware, createCorrelationIdMiddleware, createErrorMiddleware, createHttpMiddleware, createLoggerMiddleware, createQueueMiddleware, createUserAgentMiddleware } from "./middleware/index.js";
|
|
3
3
|
export * from "./types/types.js";
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"../../../src","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,OAAO,EAAE,0BAAgB;AAC/D,OAAO,EACH,2CAA2C,EAC3C,4CAA4C,EAC5C,wCAAwC,EACxC,mCAAmC,EACnC,uCAAuC,EACvC,sCAAsC,EACtC,6BAA6B,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"../../../src","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,OAAO,EAAE,0BAAgB;AAC/D,OAAO,EACH,2CAA2C,EAC3C,4CAA4C,EAC5C,wCAAwC,EACxC,mCAAmC,EACnC,uCAAuC,EACvC,sCAAsC,EACtC,6BAA6B,EAAE,qBAAqB,EAAE,oBAAoB,EAC1E,sBAAsB,EACtB,qBAAqB,EACrB,yBAAyB,EAC5B,8BAAoB;AACrB,iCAA+B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-error-middleware.d.ts","sourceRoot":"../../../../src/middleware","sources":["create-error-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,
|
|
1
|
+
{"version":3,"file":"create-error-middleware.d.ts","sourceRoot":"../../../../src/middleware","sources":["create-error-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,UAAU,EAIX,0BAAsB;AAGvB,MAAM,CAAC,OAAO,UAAU,qBAAqB,CAC3C,OAAO,GAAE,sBAA2B,GACnC,UAAU,CAsBZ"}
|
|
@@ -24,7 +24,11 @@ export type HttpErrorType = {
|
|
|
24
24
|
method: MethodType
|
|
25
25
|
statusCode: number
|
|
26
26
|
originalRequest?: ClientRequest
|
|
27
|
+
/**
|
|
28
|
+
* @deprecated use `error` instead
|
|
29
|
+
*/
|
|
27
30
|
body?: JsonObject
|
|
31
|
+
error?: JsonObject
|
|
28
32
|
retryCount?: number
|
|
29
33
|
headers?: Record<string, any>
|
|
30
34
|
[key: string]: any
|
|
@@ -80,7 +84,7 @@ export type ClientResponse<T = any> = {
|
|
|
80
84
|
retryCount?: number
|
|
81
85
|
}
|
|
82
86
|
|
|
83
|
-
export type ClientResult = ClientResponse
|
|
87
|
+
export type ClientResult<T extends object = any> = ClientResponse<T>
|
|
84
88
|
export type ClientOptions = { middlewares: Array<Middleware> }
|
|
85
89
|
|
|
86
90
|
export type Credentials = {
|
|
@@ -319,19 +323,35 @@ type TResponse = {
|
|
|
319
323
|
|
|
320
324
|
export type Client = {
|
|
321
325
|
execute(request: ClientRequest): Promise<ClientResult>
|
|
322
|
-
process
|
|
326
|
+
process<T extends object = any>(
|
|
323
327
|
request: ClientRequest,
|
|
324
|
-
fn: ProcessFn
|
|
328
|
+
fn: ProcessFn<T>,
|
|
325
329
|
processOpt?: ProcessOptions
|
|
326
|
-
)
|
|
330
|
+
): Promise<Array<T> | Array<void>>
|
|
327
331
|
}
|
|
328
332
|
|
|
329
|
-
export type ProcessFn = (result: ClientResult) => Promise<
|
|
330
|
-
export type ProcessOptions = {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
+
export type ProcessFn<T extends object> = (result: ClientResult<T>) => Promise<ClientResult<T>>
|
|
334
|
+
export type ProcessOptions = {
|
|
335
|
+
limit?: number;
|
|
336
|
+
sort?: string;
|
|
337
|
+
accumulate?: boolean;
|
|
338
|
+
total?: number;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
export type ErrorHandlerOptions = {
|
|
342
|
+
error: HttpErrorType
|
|
343
|
+
request: MiddlewareRequest
|
|
344
|
+
response: MiddlewareResponse
|
|
345
|
+
next: Next
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
export type ErrorMiddlewareOptions = {
|
|
349
|
+
handler?: (args: ErrorHandlerOptions) => Promise<MiddlewareResponse>
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
export type SuccessResult<T extends Record<string | number, Record<string, any>>> = {
|
|
333
353
|
body: {
|
|
334
|
-
results:
|
|
354
|
+
results: Array<T>;
|
|
335
355
|
count: number;
|
|
336
356
|
};
|
|
337
357
|
statusCode: number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools/ts-client",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.1",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=18"
|
|
6
6
|
},
|
|
@@ -45,9 +45,9 @@
|
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"common-tags": "1.8.2",
|
|
48
|
-
"dotenv": "16.
|
|
48
|
+
"dotenv": "16.5.0",
|
|
49
49
|
"jest": "29.7.0",
|
|
50
|
-
"nock": "14.0.
|
|
50
|
+
"nock": "14.0.4",
|
|
51
51
|
"organize-imports-cli": "0.10.0"
|
|
52
52
|
},
|
|
53
53
|
"scripts": {
|