@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
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import fetch$1 from 'node-fetch';
|
|
2
|
-
import { Mutex } from 'async-mutex';
|
|
3
2
|
import { v4 } from 'uuid';
|
|
4
3
|
import { Buffer } from 'buffer/';
|
|
5
4
|
import AbortController from 'abort-controller';
|
|
@@ -184,7 +183,7 @@ async function executor(request) {
|
|
|
184
183
|
let _response = {};
|
|
185
184
|
try {
|
|
186
185
|
_response = await execute();
|
|
187
|
-
if (_response.status >
|
|
186
|
+
if (_response.status > 399 && hasResponseRetryCode(retryCodes, _response)) return {
|
|
188
187
|
_response,
|
|
189
188
|
shouldRetry: true
|
|
190
189
|
};
|
|
@@ -447,6 +446,18 @@ function createUserAgent(options) {
|
|
|
447
446
|
return [baseInfo, systemInfo, libraryInfo, contactInfo, customAgent].filter(Boolean).join(' ');
|
|
448
447
|
}
|
|
449
448
|
|
|
449
|
+
function responseCache() {
|
|
450
|
+
let val;
|
|
451
|
+
return {
|
|
452
|
+
set(response) {
|
|
453
|
+
val = response;
|
|
454
|
+
},
|
|
455
|
+
get() {
|
|
456
|
+
return val;
|
|
457
|
+
}
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
|
|
450
461
|
/**
|
|
451
462
|
* validate some essential http options
|
|
452
463
|
* @param options
|
|
@@ -614,6 +625,7 @@ async function executeRequest$1(options) {
|
|
|
614
625
|
tokenCache,
|
|
615
626
|
tokenCacheKey,
|
|
616
627
|
userOption,
|
|
628
|
+
tokenCacheObject,
|
|
617
629
|
next
|
|
618
630
|
} = options;
|
|
619
631
|
let url = options.url;
|
|
@@ -621,20 +633,26 @@ async function executeRequest$1(options) {
|
|
|
621
633
|
let basicAuth = options.basicAuth;
|
|
622
634
|
|
|
623
635
|
// get the pending object from option
|
|
624
|
-
let pendingTasks = options.pendingTasks
|
|
636
|
+
// let pendingTasks: Array<Task> = options.pendingTasks
|
|
637
|
+
|
|
625
638
|
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.');
|
|
626
639
|
|
|
627
640
|
/**
|
|
628
641
|
* If there is a token in the tokenCache, and it's not
|
|
629
642
|
* expired, append the token in the `Authorization` header.
|
|
630
643
|
*/
|
|
631
|
-
const tokenCacheObject = tokenCache.get(tokenCacheKey)
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
644
|
+
// const tokenCacheObject = tokenCache.get(tokenCacheKey)
|
|
645
|
+
|
|
646
|
+
// if (
|
|
647
|
+
// tokenCacheObject && tokenCacheObject.token
|
|
648
|
+
// && Date.now() < tokenCacheObject.expirationTime
|
|
649
|
+
// ) {
|
|
650
|
+
// return next(
|
|
651
|
+
// mergeAuthHeader(
|
|
652
|
+
// tokenCacheObject.token, request
|
|
653
|
+
// )
|
|
654
|
+
// );
|
|
655
|
+
// }
|
|
638
656
|
|
|
639
657
|
/**
|
|
640
658
|
* Keep pending tasks until a token is fetched
|
|
@@ -642,10 +660,7 @@ async function executeRequest$1(options) {
|
|
|
642
660
|
* unexpected behaviour in a context in which the next function uses global vars
|
|
643
661
|
* or Promises to capture the token to hand it to other libraries, e.g. Apollo
|
|
644
662
|
*/
|
|
645
|
-
pendingTasks.push({
|
|
646
|
-
request,
|
|
647
|
-
next
|
|
648
|
-
});
|
|
663
|
+
// pendingTasks.push({ request, next })
|
|
649
664
|
|
|
650
665
|
/**
|
|
651
666
|
* use refreshToken flow if there is refresh-token
|
|
@@ -703,30 +718,35 @@ async function executeRequest$1(options) {
|
|
|
703
718
|
* Freeze and copy pending queue, reset
|
|
704
719
|
* original one for accepting new pending tasks
|
|
705
720
|
*/
|
|
706
|
-
const requestQueue = pendingTasks.slice()
|
|
721
|
+
// const requestQueue = pendingTasks.slice()
|
|
707
722
|
|
|
708
|
-
// reset pendingTask queue
|
|
709
|
-
pendingTasks = []
|
|
710
|
-
if (requestQueue.length === 1) {
|
|
711
|
-
return mergeAuthHeader(token, requestQueue.pop().request);
|
|
712
|
-
}
|
|
723
|
+
// // reset pendingTask queue
|
|
724
|
+
// pendingTasks = []
|
|
713
725
|
|
|
714
|
-
//
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
const requestWithAuth = mergeAuthHeader(token, task.request);
|
|
726
|
+
// if (requestQueue.length === 1) {
|
|
727
|
+
// return mergeAuthHeader(token, requestQueue.pop().request)
|
|
728
|
+
// }
|
|
718
729
|
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
730
|
+
// // execute all pending tasks if any
|
|
731
|
+
// for (let i = 0; i < pendingTasks.length; i++) {
|
|
732
|
+
// const task: Task = pendingTasks[i];
|
|
733
|
+
// const requestWithAuth = mergeAuthHeader(token, task.request)
|
|
734
|
+
|
|
735
|
+
// // execute task
|
|
736
|
+
// // task.next(requestWithAuth)
|
|
737
|
+
|
|
738
|
+
// pendingTasks[i].request = requestWithAuth;
|
|
739
|
+
// }
|
|
740
|
+
|
|
741
|
+
// return pendingTasks;
|
|
742
|
+
return Promise.resolve(true);
|
|
723
743
|
}
|
|
724
744
|
const error = new Error(response.data.message ? response.data.message : JSON.stringify(response.data));
|
|
725
745
|
/**
|
|
726
746
|
* reject the error immediately
|
|
727
747
|
* and free up the middleware chain
|
|
728
748
|
*/
|
|
729
|
-
request.reject({
|
|
749
|
+
return request.reject({
|
|
730
750
|
...request,
|
|
731
751
|
headers: {
|
|
732
752
|
...request.headers
|
|
@@ -740,7 +760,7 @@ async function executeRequest$1(options) {
|
|
|
740
760
|
}
|
|
741
761
|
});
|
|
742
762
|
} catch (error) {
|
|
743
|
-
|
|
763
|
+
request.reject({
|
|
744
764
|
...request,
|
|
745
765
|
headers: {
|
|
746
766
|
...request.headers
|
|
@@ -754,17 +774,19 @@ async function executeRequest$1(options) {
|
|
|
754
774
|
body: response
|
|
755
775
|
}
|
|
756
776
|
}
|
|
757
|
-
};
|
|
777
|
+
});
|
|
758
778
|
}
|
|
759
779
|
}
|
|
760
780
|
|
|
761
781
|
function createAuthMiddlewareForAnonymousSessionFlow$1(options) {
|
|
762
|
-
const pendingTasks = []
|
|
763
|
-
const requestState = new Mutex()
|
|
782
|
+
// const pendingTasks: Array<Task> = []
|
|
783
|
+
// const requestState = new Mutex()
|
|
764
784
|
const tokenCache = options.tokenCache || store({
|
|
765
785
|
token: '',
|
|
766
786
|
expirationTime: -1
|
|
767
787
|
});
|
|
788
|
+
let tokenCacheObject;
|
|
789
|
+
let tokenFetchPromise = null;
|
|
768
790
|
const tokenCacheKey = buildTokenCacheKey(options);
|
|
769
791
|
return next => {
|
|
770
792
|
return async request => {
|
|
@@ -773,13 +795,17 @@ function createAuthMiddlewareForAnonymousSessionFlow$1(options) {
|
|
|
773
795
|
// move on
|
|
774
796
|
return next(request);
|
|
775
797
|
}
|
|
798
|
+
tokenCacheObject = tokenCache.get(tokenCacheKey);
|
|
799
|
+
if (tokenCacheObject && tokenCacheObject.token && Date.now() < tokenCacheObject.expirationTime) {
|
|
800
|
+
return next(mergeAuthHeader(tokenCacheObject.token, request));
|
|
801
|
+
}
|
|
776
802
|
|
|
777
803
|
// prepare request options
|
|
778
804
|
const requestOptions = {
|
|
805
|
+
// requestState,
|
|
806
|
+
// pendingTasks,
|
|
779
807
|
request,
|
|
780
|
-
requestState,
|
|
781
808
|
tokenCache,
|
|
782
|
-
pendingTasks,
|
|
783
809
|
tokenCacheKey,
|
|
784
810
|
httpClient: options.httpClient || fetch$1,
|
|
785
811
|
...buildRequestForAnonymousSessionFlow(options),
|
|
@@ -787,28 +813,34 @@ function createAuthMiddlewareForAnonymousSessionFlow$1(options) {
|
|
|
787
813
|
next
|
|
788
814
|
};
|
|
789
815
|
|
|
790
|
-
//
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
816
|
+
// If a token is already being fetched, wait for it to finish
|
|
817
|
+
if (tokenFetchPromise) {
|
|
818
|
+
await tokenFetchPromise;
|
|
819
|
+
} else {
|
|
820
|
+
// Otherwise, fetch the token and let others wait for this process to complete
|
|
821
|
+
tokenFetchPromise = executeRequest$1(requestOptions);
|
|
822
|
+
await tokenFetchPromise;
|
|
823
|
+
tokenFetchPromise = null;
|
|
797
824
|
}
|
|
798
|
-
|
|
799
|
-
|
|
825
|
+
|
|
826
|
+
// Now the token is present in the tokenCache
|
|
827
|
+
tokenCacheObject = tokenCache.get(tokenCacheKey);
|
|
828
|
+
if (tokenCacheObject && tokenCacheObject.token && Date.now() < tokenCacheObject.expirationTime) {
|
|
829
|
+
return next(mergeAuthHeader(tokenCacheObject.token, request));
|
|
800
830
|
}
|
|
801
831
|
};
|
|
802
832
|
};
|
|
803
833
|
}
|
|
804
834
|
|
|
805
835
|
function createAuthMiddlewareForClientCredentialsFlow$1(options) {
|
|
806
|
-
const requestState = new Mutex()
|
|
807
|
-
const pendingTasks = []
|
|
836
|
+
// const requestState = new Mutex()
|
|
837
|
+
// const pendingTasks: Array<Task> = []
|
|
808
838
|
const tokenCache = options.tokenCache || store({
|
|
809
839
|
token: '',
|
|
810
840
|
expirationTime: -1
|
|
811
841
|
});
|
|
842
|
+
let tokenCacheObject;
|
|
843
|
+
let tokenFetchPromise = null;
|
|
812
844
|
const tokenCacheKey = buildTokenCacheKey(options);
|
|
813
845
|
return next => {
|
|
814
846
|
return async request => {
|
|
@@ -817,30 +849,38 @@ function createAuthMiddlewareForClientCredentialsFlow$1(options) {
|
|
|
817
849
|
// move on
|
|
818
850
|
return next(request);
|
|
819
851
|
}
|
|
852
|
+
tokenCacheObject = tokenCache.get(tokenCacheKey);
|
|
853
|
+
if (tokenCacheObject && tokenCacheObject.token && Date.now() < tokenCacheObject.expirationTime) {
|
|
854
|
+
return next(mergeAuthHeader(tokenCacheObject.token, request));
|
|
855
|
+
}
|
|
820
856
|
|
|
821
857
|
// prepare request options
|
|
822
858
|
const requestOptions = {
|
|
859
|
+
// requestState,
|
|
860
|
+
// pendingTasks,
|
|
823
861
|
request,
|
|
824
|
-
requestState,
|
|
825
862
|
tokenCache,
|
|
826
|
-
pendingTasks,
|
|
827
863
|
tokenCacheKey,
|
|
864
|
+
tokenCacheObject,
|
|
828
865
|
httpClient: options.httpClient || fetch$1,
|
|
829
866
|
...buildRequestForClientCredentialsFlow(options),
|
|
830
867
|
next
|
|
831
868
|
};
|
|
832
869
|
|
|
833
|
-
//
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
870
|
+
// If a token is already being fetched, wait for it to finish
|
|
871
|
+
if (tokenFetchPromise) {
|
|
872
|
+
await tokenFetchPromise;
|
|
873
|
+
} else {
|
|
874
|
+
// Otherwise, fetch the token and let others wait for this process to complete
|
|
875
|
+
tokenFetchPromise = executeRequest$1(requestOptions);
|
|
876
|
+
await tokenFetchPromise;
|
|
877
|
+
tokenFetchPromise = null;
|
|
840
878
|
}
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
879
|
+
|
|
880
|
+
// Now the token is present in the tokenCache
|
|
881
|
+
tokenCacheObject = tokenCache.get(tokenCacheKey);
|
|
882
|
+
if (tokenCacheObject && tokenCacheObject.token && Date.now() < tokenCacheObject.expirationTime) {
|
|
883
|
+
return next(mergeAuthHeader(tokenCacheObject.token, request));
|
|
844
884
|
}
|
|
845
885
|
};
|
|
846
886
|
};
|
|
@@ -877,8 +917,8 @@ function createAuthMiddlewareForPasswordFlow$1(options) {
|
|
|
877
917
|
token: '',
|
|
878
918
|
expirationTime: -1
|
|
879
919
|
});
|
|
880
|
-
|
|
881
|
-
|
|
920
|
+
let tokenCacheObject;
|
|
921
|
+
let tokenFetchPromise = null;
|
|
882
922
|
const tokenCacheKey = buildTokenCacheKey(options);
|
|
883
923
|
return next => {
|
|
884
924
|
return async request => {
|
|
@@ -886,10 +926,10 @@ function createAuthMiddlewareForPasswordFlow$1(options) {
|
|
|
886
926
|
return next(request);
|
|
887
927
|
}
|
|
888
928
|
const requestOptions = {
|
|
929
|
+
// requestState,
|
|
930
|
+
// pendingTasks,
|
|
889
931
|
request,
|
|
890
|
-
requestState,
|
|
891
932
|
tokenCache,
|
|
892
|
-
pendingTasks,
|
|
893
933
|
tokenCacheKey,
|
|
894
934
|
httpClient: options.httpClient || fetch$1,
|
|
895
935
|
...buildRequestForPasswordFlow(options),
|
|
@@ -897,16 +937,20 @@ function createAuthMiddlewareForPasswordFlow$1(options) {
|
|
|
897
937
|
next
|
|
898
938
|
};
|
|
899
939
|
|
|
900
|
-
//
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
940
|
+
// If a token is already being fetched, wait for it to finish
|
|
941
|
+
if (tokenFetchPromise) {
|
|
942
|
+
await tokenFetchPromise;
|
|
943
|
+
} else {
|
|
944
|
+
// Otherwise, fetch the token and let others wait for this process to complete
|
|
945
|
+
tokenFetchPromise = executeRequest$1(requestOptions);
|
|
946
|
+
await tokenFetchPromise;
|
|
947
|
+
tokenFetchPromise = null;
|
|
907
948
|
}
|
|
908
|
-
|
|
909
|
-
|
|
949
|
+
|
|
950
|
+
// Now the token is present in the tokenCache
|
|
951
|
+
tokenCacheObject = tokenCache.get(tokenCacheKey);
|
|
952
|
+
if (tokenCacheObject && tokenCacheObject.token && Date.now() < tokenCacheObject.expirationTime) {
|
|
953
|
+
return next(mergeAuthHeader(tokenCacheObject.token, request));
|
|
910
954
|
}
|
|
911
955
|
};
|
|
912
956
|
};
|
|
@@ -917,8 +961,13 @@ function createAuthMiddlewareForRefreshTokenFlow$1(options) {
|
|
|
917
961
|
token: '',
|
|
918
962
|
tokenCacheKey: null
|
|
919
963
|
});
|
|
920
|
-
|
|
921
|
-
const
|
|
964
|
+
|
|
965
|
+
// const pendingTasks: Array<Task> = []
|
|
966
|
+
// const requestState = new Mutex()
|
|
967
|
+
|
|
968
|
+
let tokenCacheObject;
|
|
969
|
+
let tokenFetchPromise = null;
|
|
970
|
+
const tokenCacheKey = buildTokenCacheKey(options);
|
|
922
971
|
return next => {
|
|
923
972
|
return async request => {
|
|
924
973
|
if (request.headers && (request.headers.Authorization || request.headers.authorization)) {
|
|
@@ -927,25 +976,29 @@ function createAuthMiddlewareForRefreshTokenFlow$1(options) {
|
|
|
927
976
|
|
|
928
977
|
// prepare request options
|
|
929
978
|
const requestOptions = {
|
|
979
|
+
// pendingTasks,
|
|
980
|
+
// requestState,
|
|
930
981
|
request,
|
|
931
|
-
requestState,
|
|
932
982
|
tokenCache,
|
|
933
|
-
pendingTasks,
|
|
934
983
|
httpClient: options.httpClient || fetch,
|
|
935
984
|
...buildRequestForRefreshTokenFlow(options),
|
|
936
985
|
next
|
|
937
986
|
};
|
|
938
987
|
|
|
939
|
-
//
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
988
|
+
// If a token is already being fetched, wait for it to finish
|
|
989
|
+
if (tokenFetchPromise) {
|
|
990
|
+
await tokenFetchPromise;
|
|
991
|
+
} else {
|
|
992
|
+
// Otherwise, fetch the token and let others wait for this process to complete
|
|
993
|
+
tokenFetchPromise = executeRequest$1(requestOptions);
|
|
994
|
+
await tokenFetchPromise;
|
|
995
|
+
tokenFetchPromise = null;
|
|
946
996
|
}
|
|
947
|
-
|
|
948
|
-
|
|
997
|
+
|
|
998
|
+
// Now the token is present in the tokenCache
|
|
999
|
+
tokenCacheObject = tokenCache.get(tokenCacheKey);
|
|
1000
|
+
if (tokenCacheObject && tokenCacheObject.token && Date.now() < tokenCacheObject.expirationTime) {
|
|
1001
|
+
return next(mergeAuthHeader(tokenCacheObject.token, request));
|
|
949
1002
|
}
|
|
950
1003
|
};
|
|
951
1004
|
};
|
|
@@ -954,6 +1007,7 @@ function createAuthMiddlewareForRefreshTokenFlow$1(options) {
|
|
|
954
1007
|
function createConcurrentModificationMiddleware$1(modifierFunction) {
|
|
955
1008
|
return next => {
|
|
956
1009
|
return async request => {
|
|
1010
|
+
request['concurrent'] = true;
|
|
957
1011
|
const response = await next(request);
|
|
958
1012
|
if (response.statusCode == 409) {
|
|
959
1013
|
/**
|
|
@@ -961,7 +1015,7 @@ function createConcurrentModificationMiddleware$1(modifierFunction) {
|
|
|
961
1015
|
* from the error body and update
|
|
962
1016
|
* request with the currentVersion
|
|
963
1017
|
*/
|
|
964
|
-
const version = response.error
|
|
1018
|
+
const version = response.error?.body?.errors?.[0]?.currentVersion;
|
|
965
1019
|
|
|
966
1020
|
// update the resource version here
|
|
967
1021
|
if (version) {
|
|
@@ -976,10 +1030,18 @@ function createConcurrentModificationMiddleware$1(modifierFunction) {
|
|
|
976
1030
|
version
|
|
977
1031
|
};
|
|
978
1032
|
}
|
|
979
|
-
return next(
|
|
1033
|
+
return next({
|
|
1034
|
+
...request,
|
|
1035
|
+
response
|
|
1036
|
+
});
|
|
980
1037
|
}
|
|
981
1038
|
}
|
|
982
|
-
|
|
1039
|
+
request.continue = true;
|
|
1040
|
+
delete request['concurrent'];
|
|
1041
|
+
return next({
|
|
1042
|
+
...request,
|
|
1043
|
+
response
|
|
1044
|
+
});
|
|
983
1045
|
};
|
|
984
1046
|
};
|
|
985
1047
|
}
|
|
@@ -1018,12 +1080,20 @@ function createErrorMiddleware(options) {
|
|
|
1018
1080
|
};
|
|
1019
1081
|
}
|
|
1020
1082
|
|
|
1083
|
+
let result;
|
|
1084
|
+
const cache = responseCache();
|
|
1021
1085
|
async function executeRequest({
|
|
1022
1086
|
url,
|
|
1023
1087
|
httpClient,
|
|
1024
1088
|
clientOptions
|
|
1025
1089
|
}) {
|
|
1026
1090
|
let timer;
|
|
1091
|
+
|
|
1092
|
+
// don't make further api calls
|
|
1093
|
+
if (clientOptions.request['continue']) {
|
|
1094
|
+
delete clientOptions.request['continue'];
|
|
1095
|
+
return cache.get();
|
|
1096
|
+
}
|
|
1027
1097
|
const {
|
|
1028
1098
|
timeout,
|
|
1029
1099
|
request,
|
|
@@ -1050,19 +1120,22 @@ async function executeRequest({
|
|
|
1050
1120
|
}
|
|
1051
1121
|
if (response.statusCode >= 200 && response.statusCode < 300) {
|
|
1052
1122
|
if (clientOptions.method == 'HEAD') {
|
|
1053
|
-
|
|
1123
|
+
const _result = {
|
|
1054
1124
|
body: null,
|
|
1055
1125
|
statusCode: response.statusCode,
|
|
1056
1126
|
retryCount: response.retryCount,
|
|
1057
1127
|
headers: getHeaders(response.headers)
|
|
1058
1128
|
};
|
|
1129
|
+
cache.set(_result);
|
|
1130
|
+
return _result;
|
|
1059
1131
|
}
|
|
1060
|
-
|
|
1132
|
+
result = {
|
|
1061
1133
|
body: response.data,
|
|
1062
1134
|
statusCode: response.statusCode,
|
|
1063
1135
|
retryCount: response.retryCount,
|
|
1064
1136
|
headers: getHeaders(response.headers)
|
|
1065
1137
|
};
|
|
1138
|
+
return result;
|
|
1066
1139
|
}
|
|
1067
1140
|
const error = createError({
|
|
1068
1141
|
message: response?.data?.message || response?.message,
|
|
@@ -1082,17 +1155,18 @@ async function executeRequest({
|
|
|
1082
1155
|
* handle non-ok (error) response
|
|
1083
1156
|
* build error body
|
|
1084
1157
|
*/
|
|
1085
|
-
|
|
1158
|
+
result = {
|
|
1086
1159
|
body: response.data,
|
|
1087
1160
|
code: response.statusCode,
|
|
1088
1161
|
statusCode: response.statusCode,
|
|
1089
1162
|
headers: getHeaders(response.headers),
|
|
1090
1163
|
error
|
|
1091
1164
|
};
|
|
1165
|
+
return result;
|
|
1092
1166
|
} catch (e) {
|
|
1093
1167
|
// We know that this is a network error
|
|
1094
1168
|
const headers = includeResponseHeaders ? getHeaders(e.response?.headers) : null;
|
|
1095
|
-
const statusCode = e.response?.status || e.response?.
|
|
1169
|
+
const statusCode = e.response?.status || e.response?.data || 0;
|
|
1096
1170
|
const message = e.response?.data?.message;
|
|
1097
1171
|
const error = createError({
|
|
1098
1172
|
statusCode,
|
|
@@ -1108,11 +1182,16 @@ async function executeRequest({
|
|
|
1108
1182
|
uri: request.uri
|
|
1109
1183
|
})
|
|
1110
1184
|
});
|
|
1111
|
-
|
|
1185
|
+
result = {
|
|
1112
1186
|
body: error,
|
|
1113
1187
|
error
|
|
1114
1188
|
};
|
|
1189
|
+
return result;
|
|
1115
1190
|
} finally {
|
|
1191
|
+
/**
|
|
1192
|
+
* finally cache the response
|
|
1193
|
+
*/
|
|
1194
|
+
cache.set(result);
|
|
1116
1195
|
clearTimeout(timer);
|
|
1117
1196
|
}
|
|
1118
1197
|
}
|
|
@@ -1188,6 +1267,9 @@ function createHttpMiddleware$1(options) {
|
|
|
1188
1267
|
clientOptions,
|
|
1189
1268
|
httpClient
|
|
1190
1269
|
});
|
|
1270
|
+
if (request['concurrent']) {
|
|
1271
|
+
return response;
|
|
1272
|
+
}
|
|
1191
1273
|
const responseWithRequest = {
|
|
1192
1274
|
...request,
|
|
1193
1275
|
includeOriginalRequest,
|
|
@@ -1261,7 +1343,7 @@ function createQueueMiddleware$1({
|
|
|
1261
1343
|
|
|
1262
1344
|
var packageJson = {
|
|
1263
1345
|
name: "@commercetools/ts-client",
|
|
1264
|
-
version: "2.0.
|
|
1346
|
+
version: "2.1.0-alpha.0",
|
|
1265
1347
|
engines: {
|
|
1266
1348
|
node: ">=14"
|
|
1267
1349
|
},
|
|
@@ -1295,14 +1377,16 @@ var packageJson = {
|
|
|
1295
1377
|
},
|
|
1296
1378
|
dependencies: {
|
|
1297
1379
|
"abort-controller": "3.0.0",
|
|
1298
|
-
"async-mutex": "^0.5.0",
|
|
1299
1380
|
buffer: "^6.0.3",
|
|
1300
1381
|
"node-fetch": "^2.6.1",
|
|
1301
1382
|
uuid: "10.0.0"
|
|
1302
1383
|
},
|
|
1303
1384
|
files: [
|
|
1304
1385
|
"dist",
|
|
1305
|
-
"CHANGELOG.md"
|
|
1386
|
+
"CHANGELOG.md",
|
|
1387
|
+
"LICENSE",
|
|
1388
|
+
"README.md",
|
|
1389
|
+
"package.json"
|
|
1306
1390
|
],
|
|
1307
1391
|
author: "Chukwuemeka Ajima <meeky.ae@gmail.com>",
|
|
1308
1392
|
main: "dist/commercetools-ts-client.cjs.js",
|
|
@@ -1457,7 +1541,6 @@ function process$1(request, fn, processOpt) {
|
|
|
1457
1541
|
function createClient(middlewares) {
|
|
1458
1542
|
_options = middlewares;
|
|
1459
1543
|
validateClient(middlewares);
|
|
1460
|
-
let _maskSensitiveHeaderData = false;
|
|
1461
1544
|
const resolver = {
|
|
1462
1545
|
async resolve(rs) {
|
|
1463
1546
|
const {
|
|
@@ -1470,20 +1553,25 @@ function createClient(middlewares) {
|
|
|
1470
1553
|
retryCount,
|
|
1471
1554
|
...rest
|
|
1472
1555
|
} = response;
|
|
1473
|
-
_maskSensitiveHeaderData = maskSensitiveHeaderData
|
|
1556
|
+
// _maskSensitiveHeaderData = maskSensitiveHeaderData
|
|
1557
|
+
|
|
1474
1558
|
const res = {
|
|
1475
1559
|
body: null,
|
|
1476
1560
|
error: null,
|
|
1477
1561
|
reject: rs.reject,
|
|
1478
1562
|
resolve: rs.resolve,
|
|
1479
1563
|
...rest,
|
|
1480
|
-
...(includeOriginalRequest ? {
|
|
1481
|
-
originalRequest: request
|
|
1482
|
-
} : {}),
|
|
1483
1564
|
...(response?.retryCount ? {
|
|
1484
1565
|
retryCount: response.retryCount
|
|
1566
|
+
} : {}),
|
|
1567
|
+
...(includeOriginalRequest ? {
|
|
1568
|
+
originalRequest: maskSensitiveHeaderData ? maskAuthData(request) : request
|
|
1485
1569
|
} : {})
|
|
1486
1570
|
};
|
|
1571
|
+
if (res.error) {
|
|
1572
|
+
rs.reject(res.error);
|
|
1573
|
+
}
|
|
1574
|
+
rs.resolve(res);
|
|
1487
1575
|
return res;
|
|
1488
1576
|
}
|
|
1489
1577
|
};
|
|
@@ -1493,20 +1581,11 @@ function createClient(middlewares) {
|
|
|
1493
1581
|
execute(request) {
|
|
1494
1582
|
validate('exec', request);
|
|
1495
1583
|
return new Promise(async (resolve, reject) => {
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
});
|
|
1502
|
-
if (response.error) return reject(response.error);
|
|
1503
|
-
if (response.originalRequest && _maskSensitiveHeaderData) {
|
|
1504
|
-
response.originalRequest = maskAuthData(response.originalRequest);
|
|
1505
|
-
}
|
|
1506
|
-
resolve(response);
|
|
1507
|
-
} catch (err) {
|
|
1508
|
-
reject(err);
|
|
1509
|
-
}
|
|
1584
|
+
return dispatch({
|
|
1585
|
+
reject,
|
|
1586
|
+
resolve,
|
|
1587
|
+
...request
|
|
1588
|
+
});
|
|
1510
1589
|
});
|
|
1511
1590
|
}
|
|
1512
1591
|
};
|