@commercetools/ts-client 2.0.5 → 2.1.0-alpha.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/dist/commercetools-ts-client.browser.cjs.js +193 -114
- package/dist/commercetools-ts-client.browser.esm.js +193 -114
- package/dist/commercetools-ts-client.cjs.dev.js +193 -114
- package/dist/commercetools-ts-client.cjs.prod.js +193 -114
- package/dist/commercetools-ts-client.esm.js +193 -114
- package/dist/commercetools-ts-client.umd.js +1 -1
- package/dist/declarations/src/middleware/auth-middleware/anonymous-session-flow.d.ts.map +1 -1
- package/dist/declarations/src/middleware/auth-middleware/client-credentials-flow.d.ts.map +1 -1
- package/dist/declarations/src/middleware/auth-middleware/password-flow.d.ts.map +1 -1
- package/dist/declarations/src/middleware/auth-middleware/refresh-token-flow.d.ts.map +1 -1
- package/dist/declarations/src/middleware/create-concurrent-modification-middleware.d.ts.map +1 -1
- package/dist/declarations/src/middleware/create-http-middleware.d.ts.map +1 -1
- package/dist/declarations/src/types/types.d.ts +3 -2
- package/package.json +2 -3
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var fetch$1 = require('node-fetch');
|
|
6
|
-
var asyncMutex = require('async-mutex');
|
|
7
6
|
var uuid = require('uuid');
|
|
8
7
|
var _ = require('buffer/');
|
|
9
8
|
var AbortController = require('abort-controller');
|
|
@@ -193,7 +192,7 @@ async function executor(request) {
|
|
|
193
192
|
let _response = {};
|
|
194
193
|
try {
|
|
195
194
|
_response = await execute();
|
|
196
|
-
if (_response.status >
|
|
195
|
+
if (_response.status > 399 && hasResponseRetryCode(retryCodes, _response)) return {
|
|
197
196
|
_response,
|
|
198
197
|
shouldRetry: true
|
|
199
198
|
};
|
|
@@ -456,6 +455,18 @@ function createUserAgent(options) {
|
|
|
456
455
|
return [baseInfo, systemInfo, libraryInfo, contactInfo, customAgent].filter(Boolean).join(' ');
|
|
457
456
|
}
|
|
458
457
|
|
|
458
|
+
function responseCache() {
|
|
459
|
+
let val;
|
|
460
|
+
return {
|
|
461
|
+
set(response) {
|
|
462
|
+
val = response;
|
|
463
|
+
},
|
|
464
|
+
get() {
|
|
465
|
+
return val;
|
|
466
|
+
}
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
|
|
459
470
|
/**
|
|
460
471
|
* validate some essential http options
|
|
461
472
|
* @param options
|
|
@@ -623,6 +634,7 @@ async function executeRequest$1(options) {
|
|
|
623
634
|
tokenCache,
|
|
624
635
|
tokenCacheKey,
|
|
625
636
|
userOption,
|
|
637
|
+
tokenCacheObject,
|
|
626
638
|
next
|
|
627
639
|
} = options;
|
|
628
640
|
let url = options.url;
|
|
@@ -630,20 +642,26 @@ async function executeRequest$1(options) {
|
|
|
630
642
|
let basicAuth = options.basicAuth;
|
|
631
643
|
|
|
632
644
|
// get the pending object from option
|
|
633
|
-
let pendingTasks = options.pendingTasks
|
|
645
|
+
// let pendingTasks: Array<Task> = options.pendingTasks
|
|
646
|
+
|
|
634
647
|
if (!httpClient || typeof 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.');
|
|
635
648
|
|
|
636
649
|
/**
|
|
637
650
|
* If there is a token in the tokenCache, and it's not
|
|
638
651
|
* expired, append the token in the `Authorization` header.
|
|
639
652
|
*/
|
|
640
|
-
const tokenCacheObject = tokenCache.get(tokenCacheKey)
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
653
|
+
// const tokenCacheObject = tokenCache.get(tokenCacheKey)
|
|
654
|
+
|
|
655
|
+
// if (
|
|
656
|
+
// tokenCacheObject && tokenCacheObject.token
|
|
657
|
+
// && Date.now() < tokenCacheObject.expirationTime
|
|
658
|
+
// ) {
|
|
659
|
+
// return next(
|
|
660
|
+
// mergeAuthHeader(
|
|
661
|
+
// tokenCacheObject.token, request
|
|
662
|
+
// )
|
|
663
|
+
// );
|
|
664
|
+
// }
|
|
647
665
|
|
|
648
666
|
/**
|
|
649
667
|
* Keep pending tasks until a token is fetched
|
|
@@ -651,10 +669,7 @@ async function executeRequest$1(options) {
|
|
|
651
669
|
* unexpected behaviour in a context in which the next function uses global vars
|
|
652
670
|
* or Promises to capture the token to hand it to other libraries, e.g. Apollo
|
|
653
671
|
*/
|
|
654
|
-
pendingTasks.push({
|
|
655
|
-
request,
|
|
656
|
-
next
|
|
657
|
-
});
|
|
672
|
+
// pendingTasks.push({ request, next })
|
|
658
673
|
|
|
659
674
|
/**
|
|
660
675
|
* use refreshToken flow if there is refresh-token
|
|
@@ -712,30 +727,35 @@ async function executeRequest$1(options) {
|
|
|
712
727
|
* Freeze and copy pending queue, reset
|
|
713
728
|
* original one for accepting new pending tasks
|
|
714
729
|
*/
|
|
715
|
-
const requestQueue = pendingTasks.slice()
|
|
730
|
+
// const requestQueue = pendingTasks.slice()
|
|
716
731
|
|
|
717
|
-
// reset pendingTask queue
|
|
718
|
-
pendingTasks = []
|
|
719
|
-
if (requestQueue.length === 1) {
|
|
720
|
-
return mergeAuthHeader(token, requestQueue.pop().request);
|
|
721
|
-
}
|
|
732
|
+
// // reset pendingTask queue
|
|
733
|
+
// pendingTasks = []
|
|
722
734
|
|
|
723
|
-
//
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
const requestWithAuth = mergeAuthHeader(token, task.request);
|
|
735
|
+
// if (requestQueue.length === 1) {
|
|
736
|
+
// return mergeAuthHeader(token, requestQueue.pop().request)
|
|
737
|
+
// }
|
|
727
738
|
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
739
|
+
// // execute all pending tasks if any
|
|
740
|
+
// for (let i = 0; i < pendingTasks.length; i++) {
|
|
741
|
+
// const task: Task = pendingTasks[i];
|
|
742
|
+
// const requestWithAuth = mergeAuthHeader(token, task.request)
|
|
743
|
+
|
|
744
|
+
// // execute task
|
|
745
|
+
// // task.next(requestWithAuth)
|
|
746
|
+
|
|
747
|
+
// pendingTasks[i].request = requestWithAuth;
|
|
748
|
+
// }
|
|
749
|
+
|
|
750
|
+
// return pendingTasks;
|
|
751
|
+
return Promise.resolve(true);
|
|
732
752
|
}
|
|
733
753
|
const error = new Error(response.data.message ? response.data.message : JSON.stringify(response.data));
|
|
734
754
|
/**
|
|
735
755
|
* reject the error immediately
|
|
736
756
|
* and free up the middleware chain
|
|
737
757
|
*/
|
|
738
|
-
request.reject({
|
|
758
|
+
return request.reject({
|
|
739
759
|
...request,
|
|
740
760
|
headers: {
|
|
741
761
|
...request.headers
|
|
@@ -749,7 +769,7 @@ async function executeRequest$1(options) {
|
|
|
749
769
|
}
|
|
750
770
|
});
|
|
751
771
|
} catch (error) {
|
|
752
|
-
|
|
772
|
+
request.reject({
|
|
753
773
|
...request,
|
|
754
774
|
headers: {
|
|
755
775
|
...request.headers
|
|
@@ -763,17 +783,19 @@ async function executeRequest$1(options) {
|
|
|
763
783
|
body: response
|
|
764
784
|
}
|
|
765
785
|
}
|
|
766
|
-
};
|
|
786
|
+
});
|
|
767
787
|
}
|
|
768
788
|
}
|
|
769
789
|
|
|
770
790
|
function createAuthMiddlewareForAnonymousSessionFlow$1(options) {
|
|
771
|
-
const pendingTasks = []
|
|
772
|
-
const requestState = new
|
|
791
|
+
// const pendingTasks: Array<Task> = []
|
|
792
|
+
// const requestState = new Mutex()
|
|
773
793
|
const tokenCache = options.tokenCache || store({
|
|
774
794
|
token: '',
|
|
775
795
|
expirationTime: -1
|
|
776
796
|
});
|
|
797
|
+
let tokenCacheObject;
|
|
798
|
+
let tokenFetchPromise = null;
|
|
777
799
|
const tokenCacheKey = buildTokenCacheKey(options);
|
|
778
800
|
return next => {
|
|
779
801
|
return async request => {
|
|
@@ -782,13 +804,17 @@ function createAuthMiddlewareForAnonymousSessionFlow$1(options) {
|
|
|
782
804
|
// move on
|
|
783
805
|
return next(request);
|
|
784
806
|
}
|
|
807
|
+
tokenCacheObject = tokenCache.get(tokenCacheKey);
|
|
808
|
+
if (tokenCacheObject && tokenCacheObject.token && Date.now() < tokenCacheObject.expirationTime) {
|
|
809
|
+
return next(mergeAuthHeader(tokenCacheObject.token, request));
|
|
810
|
+
}
|
|
785
811
|
|
|
786
812
|
// prepare request options
|
|
787
813
|
const requestOptions = {
|
|
814
|
+
// requestState,
|
|
815
|
+
// pendingTasks,
|
|
788
816
|
request,
|
|
789
|
-
requestState,
|
|
790
817
|
tokenCache,
|
|
791
|
-
pendingTasks,
|
|
792
818
|
tokenCacheKey,
|
|
793
819
|
httpClient: options.httpClient || fetch__default["default"],
|
|
794
820
|
...buildRequestForAnonymousSessionFlow(options),
|
|
@@ -796,28 +822,34 @@ function createAuthMiddlewareForAnonymousSessionFlow$1(options) {
|
|
|
796
822
|
next
|
|
797
823
|
};
|
|
798
824
|
|
|
799
|
-
//
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
825
|
+
// If a token is already being fetched, wait for it to finish
|
|
826
|
+
if (tokenFetchPromise) {
|
|
827
|
+
await tokenFetchPromise;
|
|
828
|
+
} else {
|
|
829
|
+
// Otherwise, fetch the token and let others wait for this process to complete
|
|
830
|
+
tokenFetchPromise = executeRequest$1(requestOptions);
|
|
831
|
+
await tokenFetchPromise;
|
|
832
|
+
tokenFetchPromise = null;
|
|
806
833
|
}
|
|
807
|
-
|
|
808
|
-
|
|
834
|
+
|
|
835
|
+
// Now the token is present in the tokenCache
|
|
836
|
+
tokenCacheObject = tokenCache.get(tokenCacheKey);
|
|
837
|
+
if (tokenCacheObject && tokenCacheObject.token && Date.now() < tokenCacheObject.expirationTime) {
|
|
838
|
+
return next(mergeAuthHeader(tokenCacheObject.token, request));
|
|
809
839
|
}
|
|
810
840
|
};
|
|
811
841
|
};
|
|
812
842
|
}
|
|
813
843
|
|
|
814
844
|
function createAuthMiddlewareForClientCredentialsFlow$1(options) {
|
|
815
|
-
const requestState = new
|
|
816
|
-
const pendingTasks = []
|
|
845
|
+
// const requestState = new Mutex()
|
|
846
|
+
// const pendingTasks: Array<Task> = []
|
|
817
847
|
const tokenCache = options.tokenCache || store({
|
|
818
848
|
token: '',
|
|
819
849
|
expirationTime: -1
|
|
820
850
|
});
|
|
851
|
+
let tokenCacheObject;
|
|
852
|
+
let tokenFetchPromise = null;
|
|
821
853
|
const tokenCacheKey = buildTokenCacheKey(options);
|
|
822
854
|
return next => {
|
|
823
855
|
return async request => {
|
|
@@ -826,30 +858,38 @@ function createAuthMiddlewareForClientCredentialsFlow$1(options) {
|
|
|
826
858
|
// move on
|
|
827
859
|
return next(request);
|
|
828
860
|
}
|
|
861
|
+
tokenCacheObject = tokenCache.get(tokenCacheKey);
|
|
862
|
+
if (tokenCacheObject && tokenCacheObject.token && Date.now() < tokenCacheObject.expirationTime) {
|
|
863
|
+
return next(mergeAuthHeader(tokenCacheObject.token, request));
|
|
864
|
+
}
|
|
829
865
|
|
|
830
866
|
// prepare request options
|
|
831
867
|
const requestOptions = {
|
|
868
|
+
// requestState,
|
|
869
|
+
// pendingTasks,
|
|
832
870
|
request,
|
|
833
|
-
requestState,
|
|
834
871
|
tokenCache,
|
|
835
|
-
pendingTasks,
|
|
836
872
|
tokenCacheKey,
|
|
873
|
+
tokenCacheObject,
|
|
837
874
|
httpClient: options.httpClient || fetch__default["default"],
|
|
838
875
|
...buildRequestForClientCredentialsFlow(options),
|
|
839
876
|
next
|
|
840
877
|
};
|
|
841
878
|
|
|
842
|
-
//
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
879
|
+
// If a token is already being fetched, wait for it to finish
|
|
880
|
+
if (tokenFetchPromise) {
|
|
881
|
+
await tokenFetchPromise;
|
|
882
|
+
} else {
|
|
883
|
+
// Otherwise, fetch the token and let others wait for this process to complete
|
|
884
|
+
tokenFetchPromise = executeRequest$1(requestOptions);
|
|
885
|
+
await tokenFetchPromise;
|
|
886
|
+
tokenFetchPromise = null;
|
|
849
887
|
}
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
888
|
+
|
|
889
|
+
// Now the token is present in the tokenCache
|
|
890
|
+
tokenCacheObject = tokenCache.get(tokenCacheKey);
|
|
891
|
+
if (tokenCacheObject && tokenCacheObject.token && Date.now() < tokenCacheObject.expirationTime) {
|
|
892
|
+
return next(mergeAuthHeader(tokenCacheObject.token, request));
|
|
853
893
|
}
|
|
854
894
|
};
|
|
855
895
|
};
|
|
@@ -886,8 +926,8 @@ function createAuthMiddlewareForPasswordFlow$1(options) {
|
|
|
886
926
|
token: '',
|
|
887
927
|
expirationTime: -1
|
|
888
928
|
});
|
|
889
|
-
|
|
890
|
-
|
|
929
|
+
let tokenCacheObject;
|
|
930
|
+
let tokenFetchPromise = null;
|
|
891
931
|
const tokenCacheKey = buildTokenCacheKey(options);
|
|
892
932
|
return next => {
|
|
893
933
|
return async request => {
|
|
@@ -895,10 +935,10 @@ function createAuthMiddlewareForPasswordFlow$1(options) {
|
|
|
895
935
|
return next(request);
|
|
896
936
|
}
|
|
897
937
|
const requestOptions = {
|
|
938
|
+
// requestState,
|
|
939
|
+
// pendingTasks,
|
|
898
940
|
request,
|
|
899
|
-
requestState,
|
|
900
941
|
tokenCache,
|
|
901
|
-
pendingTasks,
|
|
902
942
|
tokenCacheKey,
|
|
903
943
|
httpClient: options.httpClient || fetch__default["default"],
|
|
904
944
|
...buildRequestForPasswordFlow(options),
|
|
@@ -906,16 +946,20 @@ function createAuthMiddlewareForPasswordFlow$1(options) {
|
|
|
906
946
|
next
|
|
907
947
|
};
|
|
908
948
|
|
|
909
|
-
//
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
949
|
+
// If a token is already being fetched, wait for it to finish
|
|
950
|
+
if (tokenFetchPromise) {
|
|
951
|
+
await tokenFetchPromise;
|
|
952
|
+
} else {
|
|
953
|
+
// Otherwise, fetch the token and let others wait for this process to complete
|
|
954
|
+
tokenFetchPromise = executeRequest$1(requestOptions);
|
|
955
|
+
await tokenFetchPromise;
|
|
956
|
+
tokenFetchPromise = null;
|
|
916
957
|
}
|
|
917
|
-
|
|
918
|
-
|
|
958
|
+
|
|
959
|
+
// Now the token is present in the tokenCache
|
|
960
|
+
tokenCacheObject = tokenCache.get(tokenCacheKey);
|
|
961
|
+
if (tokenCacheObject && tokenCacheObject.token && Date.now() < tokenCacheObject.expirationTime) {
|
|
962
|
+
return next(mergeAuthHeader(tokenCacheObject.token, request));
|
|
919
963
|
}
|
|
920
964
|
};
|
|
921
965
|
};
|
|
@@ -926,8 +970,13 @@ function createAuthMiddlewareForRefreshTokenFlow$1(options) {
|
|
|
926
970
|
token: '',
|
|
927
971
|
tokenCacheKey: null
|
|
928
972
|
});
|
|
929
|
-
|
|
930
|
-
const
|
|
973
|
+
|
|
974
|
+
// const pendingTasks: Array<Task> = []
|
|
975
|
+
// const requestState = new Mutex()
|
|
976
|
+
|
|
977
|
+
let tokenCacheObject;
|
|
978
|
+
let tokenFetchPromise = null;
|
|
979
|
+
const tokenCacheKey = buildTokenCacheKey(options);
|
|
931
980
|
return next => {
|
|
932
981
|
return async request => {
|
|
933
982
|
if (request.headers && (request.headers.Authorization || request.headers.authorization)) {
|
|
@@ -936,25 +985,29 @@ function createAuthMiddlewareForRefreshTokenFlow$1(options) {
|
|
|
936
985
|
|
|
937
986
|
// prepare request options
|
|
938
987
|
const requestOptions = {
|
|
988
|
+
// pendingTasks,
|
|
989
|
+
// requestState,
|
|
939
990
|
request,
|
|
940
|
-
requestState,
|
|
941
991
|
tokenCache,
|
|
942
|
-
pendingTasks,
|
|
943
992
|
httpClient: options.httpClient || fetch,
|
|
944
993
|
...buildRequestForRefreshTokenFlow(options),
|
|
945
994
|
next
|
|
946
995
|
};
|
|
947
996
|
|
|
948
|
-
//
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
997
|
+
// If a token is already being fetched, wait for it to finish
|
|
998
|
+
if (tokenFetchPromise) {
|
|
999
|
+
await tokenFetchPromise;
|
|
1000
|
+
} else {
|
|
1001
|
+
// Otherwise, fetch the token and let others wait for this process to complete
|
|
1002
|
+
tokenFetchPromise = executeRequest$1(requestOptions);
|
|
1003
|
+
await tokenFetchPromise;
|
|
1004
|
+
tokenFetchPromise = null;
|
|
955
1005
|
}
|
|
956
|
-
|
|
957
|
-
|
|
1006
|
+
|
|
1007
|
+
// Now the token is present in the tokenCache
|
|
1008
|
+
tokenCacheObject = tokenCache.get(tokenCacheKey);
|
|
1009
|
+
if (tokenCacheObject && tokenCacheObject.token && Date.now() < tokenCacheObject.expirationTime) {
|
|
1010
|
+
return next(mergeAuthHeader(tokenCacheObject.token, request));
|
|
958
1011
|
}
|
|
959
1012
|
};
|
|
960
1013
|
};
|
|
@@ -963,6 +1016,7 @@ function createAuthMiddlewareForRefreshTokenFlow$1(options) {
|
|
|
963
1016
|
function createConcurrentModificationMiddleware$1(modifierFunction) {
|
|
964
1017
|
return next => {
|
|
965
1018
|
return async request => {
|
|
1019
|
+
request['concurrent'] = true;
|
|
966
1020
|
const response = await next(request);
|
|
967
1021
|
if (response.statusCode == 409) {
|
|
968
1022
|
/**
|
|
@@ -970,7 +1024,7 @@ function createConcurrentModificationMiddleware$1(modifierFunction) {
|
|
|
970
1024
|
* from the error body and update
|
|
971
1025
|
* request with the currentVersion
|
|
972
1026
|
*/
|
|
973
|
-
const version = response.error
|
|
1027
|
+
const version = response.error?.body?.errors?.[0]?.currentVersion;
|
|
974
1028
|
|
|
975
1029
|
// update the resource version here
|
|
976
1030
|
if (version) {
|
|
@@ -985,10 +1039,18 @@ function createConcurrentModificationMiddleware$1(modifierFunction) {
|
|
|
985
1039
|
version
|
|
986
1040
|
};
|
|
987
1041
|
}
|
|
988
|
-
return next(
|
|
1042
|
+
return next({
|
|
1043
|
+
...request,
|
|
1044
|
+
response
|
|
1045
|
+
});
|
|
989
1046
|
}
|
|
990
1047
|
}
|
|
991
|
-
|
|
1048
|
+
request.continue = true;
|
|
1049
|
+
delete request['concurrent'];
|
|
1050
|
+
return next({
|
|
1051
|
+
...request,
|
|
1052
|
+
response
|
|
1053
|
+
});
|
|
992
1054
|
};
|
|
993
1055
|
};
|
|
994
1056
|
}
|
|
@@ -1027,12 +1089,20 @@ function createErrorMiddleware(options) {
|
|
|
1027
1089
|
};
|
|
1028
1090
|
}
|
|
1029
1091
|
|
|
1092
|
+
let result;
|
|
1093
|
+
const cache = responseCache();
|
|
1030
1094
|
async function executeRequest({
|
|
1031
1095
|
url,
|
|
1032
1096
|
httpClient,
|
|
1033
1097
|
clientOptions
|
|
1034
1098
|
}) {
|
|
1035
1099
|
let timer;
|
|
1100
|
+
|
|
1101
|
+
// don't make further api calls
|
|
1102
|
+
if (clientOptions.request['continue']) {
|
|
1103
|
+
delete clientOptions.request['continue'];
|
|
1104
|
+
return cache.get();
|
|
1105
|
+
}
|
|
1036
1106
|
const {
|
|
1037
1107
|
timeout,
|
|
1038
1108
|
request,
|
|
@@ -1059,19 +1129,22 @@ async function executeRequest({
|
|
|
1059
1129
|
}
|
|
1060
1130
|
if (response.statusCode >= 200 && response.statusCode < 300) {
|
|
1061
1131
|
if (clientOptions.method == 'HEAD') {
|
|
1062
|
-
|
|
1132
|
+
const _result = {
|
|
1063
1133
|
body: null,
|
|
1064
1134
|
statusCode: response.statusCode,
|
|
1065
1135
|
retryCount: response.retryCount,
|
|
1066
1136
|
headers: getHeaders(response.headers)
|
|
1067
1137
|
};
|
|
1138
|
+
cache.set(_result);
|
|
1139
|
+
return _result;
|
|
1068
1140
|
}
|
|
1069
|
-
|
|
1141
|
+
result = {
|
|
1070
1142
|
body: response.data,
|
|
1071
1143
|
statusCode: response.statusCode,
|
|
1072
1144
|
retryCount: response.retryCount,
|
|
1073
1145
|
headers: getHeaders(response.headers)
|
|
1074
1146
|
};
|
|
1147
|
+
return result;
|
|
1075
1148
|
}
|
|
1076
1149
|
const error = createError({
|
|
1077
1150
|
message: response?.data?.message || response?.message,
|
|
@@ -1091,17 +1164,18 @@ async function executeRequest({
|
|
|
1091
1164
|
* handle non-ok (error) response
|
|
1092
1165
|
* build error body
|
|
1093
1166
|
*/
|
|
1094
|
-
|
|
1167
|
+
result = {
|
|
1095
1168
|
body: response.data,
|
|
1096
1169
|
code: response.statusCode,
|
|
1097
1170
|
statusCode: response.statusCode,
|
|
1098
1171
|
headers: getHeaders(response.headers),
|
|
1099
1172
|
error
|
|
1100
1173
|
};
|
|
1174
|
+
return result;
|
|
1101
1175
|
} catch (e) {
|
|
1102
1176
|
// We know that this is a network error
|
|
1103
1177
|
const headers = includeResponseHeaders ? getHeaders(e.response?.headers) : null;
|
|
1104
|
-
const statusCode = e.response?.status || e.response?.
|
|
1178
|
+
const statusCode = e.response?.status || e.response?.data || 0;
|
|
1105
1179
|
const message = e.response?.data?.message;
|
|
1106
1180
|
const error = createError({
|
|
1107
1181
|
statusCode,
|
|
@@ -1117,11 +1191,16 @@ async function executeRequest({
|
|
|
1117
1191
|
uri: request.uri
|
|
1118
1192
|
})
|
|
1119
1193
|
});
|
|
1120
|
-
|
|
1194
|
+
result = {
|
|
1121
1195
|
body: error,
|
|
1122
1196
|
error
|
|
1123
1197
|
};
|
|
1198
|
+
return result;
|
|
1124
1199
|
} finally {
|
|
1200
|
+
/**
|
|
1201
|
+
* finally cache the response
|
|
1202
|
+
*/
|
|
1203
|
+
cache.set(result);
|
|
1125
1204
|
clearTimeout(timer);
|
|
1126
1205
|
}
|
|
1127
1206
|
}
|
|
@@ -1197,6 +1276,9 @@ function createHttpMiddleware$1(options) {
|
|
|
1197
1276
|
clientOptions,
|
|
1198
1277
|
httpClient
|
|
1199
1278
|
});
|
|
1279
|
+
if (request['concurrent']) {
|
|
1280
|
+
return response;
|
|
1281
|
+
}
|
|
1200
1282
|
const responseWithRequest = {
|
|
1201
1283
|
...request,
|
|
1202
1284
|
includeOriginalRequest,
|
|
@@ -1270,7 +1352,7 @@ function createQueueMiddleware$1({
|
|
|
1270
1352
|
|
|
1271
1353
|
var packageJson = {
|
|
1272
1354
|
name: "@commercetools/ts-client",
|
|
1273
|
-
version: "2.0.
|
|
1355
|
+
version: "2.1.0-alpha.0",
|
|
1274
1356
|
engines: {
|
|
1275
1357
|
node: ">=14"
|
|
1276
1358
|
},
|
|
@@ -1304,14 +1386,16 @@ var packageJson = {
|
|
|
1304
1386
|
},
|
|
1305
1387
|
dependencies: {
|
|
1306
1388
|
"abort-controller": "3.0.0",
|
|
1307
|
-
"async-mutex": "^0.5.0",
|
|
1308
1389
|
buffer: "^6.0.3",
|
|
1309
1390
|
"node-fetch": "^2.6.1",
|
|
1310
1391
|
uuid: "10.0.0"
|
|
1311
1392
|
},
|
|
1312
1393
|
files: [
|
|
1313
1394
|
"dist",
|
|
1314
|
-
"CHANGELOG.md"
|
|
1395
|
+
"CHANGELOG.md",
|
|
1396
|
+
"LICENSE",
|
|
1397
|
+
"README.md",
|
|
1398
|
+
"package.json"
|
|
1315
1399
|
],
|
|
1316
1400
|
author: "Chukwuemeka Ajima <meeky.ae@gmail.com>",
|
|
1317
1401
|
main: "dist/commercetools-ts-client.cjs.js",
|
|
@@ -1466,7 +1550,6 @@ function process$1(request, fn, processOpt) {
|
|
|
1466
1550
|
function createClient(middlewares) {
|
|
1467
1551
|
_options = middlewares;
|
|
1468
1552
|
validateClient(middlewares);
|
|
1469
|
-
let _maskSensitiveHeaderData = false;
|
|
1470
1553
|
const resolver = {
|
|
1471
1554
|
async resolve(rs) {
|
|
1472
1555
|
const {
|
|
@@ -1479,20 +1562,25 @@ function createClient(middlewares) {
|
|
|
1479
1562
|
retryCount,
|
|
1480
1563
|
...rest
|
|
1481
1564
|
} = response;
|
|
1482
|
-
_maskSensitiveHeaderData = maskSensitiveHeaderData
|
|
1565
|
+
// _maskSensitiveHeaderData = maskSensitiveHeaderData
|
|
1566
|
+
|
|
1483
1567
|
const res = {
|
|
1484
1568
|
body: null,
|
|
1485
1569
|
error: null,
|
|
1486
1570
|
reject: rs.reject,
|
|
1487
1571
|
resolve: rs.resolve,
|
|
1488
1572
|
...rest,
|
|
1489
|
-
...(includeOriginalRequest ? {
|
|
1490
|
-
originalRequest: request
|
|
1491
|
-
} : {}),
|
|
1492
1573
|
...(response?.retryCount ? {
|
|
1493
1574
|
retryCount: response.retryCount
|
|
1575
|
+
} : {}),
|
|
1576
|
+
...(includeOriginalRequest ? {
|
|
1577
|
+
originalRequest: maskSensitiveHeaderData ? maskAuthData(request) : request
|
|
1494
1578
|
} : {})
|
|
1495
1579
|
};
|
|
1580
|
+
if (res.error) {
|
|
1581
|
+
rs.reject(res.error);
|
|
1582
|
+
}
|
|
1583
|
+
rs.resolve(res);
|
|
1496
1584
|
return res;
|
|
1497
1585
|
}
|
|
1498
1586
|
};
|
|
@@ -1502,20 +1590,11 @@ function createClient(middlewares) {
|
|
|
1502
1590
|
execute(request) {
|
|
1503
1591
|
validate('exec', request);
|
|
1504
1592
|
return new Promise(async (resolve, reject) => {
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
});
|
|
1511
|
-
if (response.error) return reject(response.error);
|
|
1512
|
-
if (response.originalRequest && _maskSensitiveHeaderData) {
|
|
1513
|
-
response.originalRequest = maskAuthData(response.originalRequest);
|
|
1514
|
-
}
|
|
1515
|
-
resolve(response);
|
|
1516
|
-
} catch (err) {
|
|
1517
|
-
reject(err);
|
|
1518
|
-
}
|
|
1593
|
+
return dispatch({
|
|
1594
|
+
reject,
|
|
1595
|
+
resolve,
|
|
1596
|
+
...request
|
|
1597
|
+
});
|
|
1519
1598
|
});
|
|
1520
1599
|
}
|
|
1521
1600
|
};
|