@swapkit/api-sdk-typescript 1.0.3 → 1.1.0-nightly.20260701161042
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/README.md +6 -0
- package/dist/index.cjs +148 -164
- package/dist/index.d.cts +1661 -1455
- package/dist/index.d.ts +1661 -1455
- package/dist/index.js +139 -155
- package/package.json +4 -2
- package/src/client.ts +3 -3
- package/src/core/auth.ts +7 -0
- package/src/core/bodySerializer.ts +6 -8
- package/src/core/params.ts +24 -15
- package/src/core/pathSerializer.ts +6 -6
- package/src/core/queryKeySerializer.ts +1 -1
- package/src/core/serverSentEvents.ts +4 -5
- package/src/core/types.ts +7 -1
- package/src/core/utils.ts +5 -5
- package/src/http/client.ts +129 -140
- package/src/http/index.ts +2 -0
- package/src/http/types.ts +10 -6
- package/src/http/utils.ts +13 -13
- package/src/index.ts +28 -28
- package/src/sdk.ts +18 -18
- package/src/types.ts +1597 -1387
package/dist/index.js
CHANGED
|
@@ -13,7 +13,7 @@ var extraPrefixesMap = {
|
|
|
13
13
|
var extraPrefixes = Object.entries(extraPrefixesMap);
|
|
14
14
|
|
|
15
15
|
// src/core/serverSentEvents.ts
|
|
16
|
-
|
|
16
|
+
function createSseClient({
|
|
17
17
|
onRequest,
|
|
18
18
|
onSseError,
|
|
19
19
|
onSseEvent,
|
|
@@ -25,7 +25,7 @@ var createSseClient = ({
|
|
|
25
25
|
sseSleepFn,
|
|
26
26
|
url,
|
|
27
27
|
...options
|
|
28
|
-
})
|
|
28
|
+
}) {
|
|
29
29
|
let lastEventId;
|
|
30
30
|
const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
31
31
|
const createStream = async function* () {
|
|
@@ -69,7 +69,7 @@ var createSseClient = ({
|
|
|
69
69
|
const { done, value } = await reader.read();
|
|
70
70
|
if (done) break;
|
|
71
71
|
buffer += value;
|
|
72
|
-
buffer = buffer.replace(/\r\n
|
|
72
|
+
buffer = buffer.replace(/\r\n?/g, "\n");
|
|
73
73
|
const chunks = buffer.split("\n\n");
|
|
74
74
|
buffer = chunks.pop() ?? "";
|
|
75
75
|
for (const chunk of chunks) {
|
|
@@ -137,7 +137,7 @@ var createSseClient = ({
|
|
|
137
137
|
};
|
|
138
138
|
const stream = createStream();
|
|
139
139
|
return { stream };
|
|
140
|
-
}
|
|
140
|
+
}
|
|
141
141
|
|
|
142
142
|
// src/core/pathSerializer.ts
|
|
143
143
|
var separatorArrayExplode = (style) => {
|
|
@@ -454,11 +454,8 @@ var checkForExistence = (options, name) => {
|
|
|
454
454
|
}
|
|
455
455
|
return false;
|
|
456
456
|
};
|
|
457
|
-
|
|
458
|
-
security
|
|
459
|
-
...options
|
|
460
|
-
}) => {
|
|
461
|
-
for (const auth of security) {
|
|
457
|
+
async function setAuthParams(options) {
|
|
458
|
+
for (const auth of options.security ?? []) {
|
|
462
459
|
if (checkForExistence(options, auth.name)) {
|
|
463
460
|
continue;
|
|
464
461
|
}
|
|
@@ -483,7 +480,7 @@ var setAuthParams = async ({
|
|
|
483
480
|
break;
|
|
484
481
|
}
|
|
485
482
|
}
|
|
486
|
-
}
|
|
483
|
+
}
|
|
487
484
|
var buildUrl = (options) => getUrl({
|
|
488
485
|
baseUrl: options.baseUrl,
|
|
489
486
|
path: options.path,
|
|
@@ -611,10 +608,7 @@ var createClient = (config = {}) => {
|
|
|
611
608
|
serializedBody: void 0
|
|
612
609
|
};
|
|
613
610
|
if (opts.security) {
|
|
614
|
-
await setAuthParams(
|
|
615
|
-
...opts,
|
|
616
|
-
security: opts.security
|
|
617
|
-
});
|
|
611
|
+
await setAuthParams(opts);
|
|
618
612
|
}
|
|
619
613
|
if (opts.requestValidator) {
|
|
620
614
|
await opts.requestValidator(opts);
|
|
@@ -625,131 +619,121 @@ var createClient = (config = {}) => {
|
|
|
625
619
|
if (opts.body === void 0 || opts.serializedBody === "") {
|
|
626
620
|
opts.headers.delete("Content-Type");
|
|
627
621
|
}
|
|
628
|
-
const
|
|
629
|
-
|
|
622
|
+
const resolvedOpts = opts;
|
|
623
|
+
const url = buildUrl(resolvedOpts);
|
|
624
|
+
return { opts: resolvedOpts, url };
|
|
630
625
|
};
|
|
631
626
|
const request = async (options) => {
|
|
632
|
-
const
|
|
633
|
-
const
|
|
634
|
-
|
|
635
|
-
...opts,
|
|
636
|
-
body: getValidRequestBody(opts)
|
|
637
|
-
};
|
|
638
|
-
let request2 = new Request(url, requestInit);
|
|
639
|
-
for (const fn of interceptors.request.fns) {
|
|
640
|
-
if (fn) {
|
|
641
|
-
request2 = await fn(request2, opts);
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
const _fetch = opts.fetch;
|
|
627
|
+
const throwOnError = options.throwOnError ?? _config.throwOnError;
|
|
628
|
+
const responseStyle = options.responseStyle ?? _config.responseStyle;
|
|
629
|
+
let request2;
|
|
645
630
|
let response;
|
|
646
631
|
try {
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
632
|
+
const { opts, url } = await beforeRequest(options);
|
|
633
|
+
const requestInit = {
|
|
634
|
+
redirect: "follow",
|
|
635
|
+
...opts,
|
|
636
|
+
body: getValidRequestBody(opts)
|
|
637
|
+
};
|
|
638
|
+
request2 = new Request(url, requestInit);
|
|
639
|
+
for (const fn of interceptors.request.fns) {
|
|
651
640
|
if (fn) {
|
|
652
|
-
|
|
641
|
+
request2 = await fn(request2, opts);
|
|
653
642
|
}
|
|
654
643
|
}
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
644
|
+
const _fetch = opts.fetch;
|
|
645
|
+
response = await _fetch(request2);
|
|
646
|
+
for (const fn of interceptors.response.fns) {
|
|
647
|
+
if (fn) {
|
|
648
|
+
response = await fn(response, request2, opts);
|
|
649
|
+
}
|
|
658
650
|
}
|
|
659
|
-
|
|
660
|
-
error: finalError2,
|
|
651
|
+
const result = {
|
|
661
652
|
request: request2,
|
|
662
|
-
response
|
|
653
|
+
response
|
|
663
654
|
};
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
655
|
+
if (response.ok) {
|
|
656
|
+
const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
|
|
657
|
+
if (response.status === 204 || response.headers.get("Content-Length") === "0") {
|
|
658
|
+
let emptyData;
|
|
659
|
+
switch (parseAs) {
|
|
660
|
+
case "arrayBuffer":
|
|
661
|
+
case "blob":
|
|
662
|
+
case "text":
|
|
663
|
+
emptyData = await response[parseAs]();
|
|
664
|
+
break;
|
|
665
|
+
case "formData":
|
|
666
|
+
emptyData = new FormData();
|
|
667
|
+
break;
|
|
668
|
+
case "stream":
|
|
669
|
+
emptyData = response.body;
|
|
670
|
+
break;
|
|
671
|
+
case "json":
|
|
672
|
+
default:
|
|
673
|
+
emptyData = {};
|
|
674
|
+
break;
|
|
675
|
+
}
|
|
676
|
+
return opts.responseStyle === "data" ? emptyData : {
|
|
677
|
+
data: emptyData,
|
|
678
|
+
...result
|
|
679
|
+
};
|
|
680
|
+
}
|
|
681
|
+
let data;
|
|
678
682
|
switch (parseAs) {
|
|
679
683
|
case "arrayBuffer":
|
|
680
684
|
case "blob":
|
|
685
|
+
case "formData":
|
|
681
686
|
case "text":
|
|
682
|
-
|
|
687
|
+
data = await response[parseAs]();
|
|
683
688
|
break;
|
|
684
|
-
case "
|
|
685
|
-
|
|
689
|
+
case "json": {
|
|
690
|
+
const text = await response.text();
|
|
691
|
+
data = text ? JSON.parse(text) : {};
|
|
686
692
|
break;
|
|
693
|
+
}
|
|
687
694
|
case "stream":
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
695
|
+
return opts.responseStyle === "data" ? response.body : {
|
|
696
|
+
data: response.body,
|
|
697
|
+
...result
|
|
698
|
+
};
|
|
699
|
+
}
|
|
700
|
+
if (parseAs === "json") {
|
|
701
|
+
if (opts.responseValidator) {
|
|
702
|
+
await opts.responseValidator(data);
|
|
703
|
+
}
|
|
704
|
+
if (opts.responseTransformer) {
|
|
705
|
+
data = await opts.responseTransformer(data);
|
|
706
|
+
}
|
|
694
707
|
}
|
|
695
|
-
return opts.responseStyle === "data" ?
|
|
696
|
-
data
|
|
708
|
+
return opts.responseStyle === "data" ? data : {
|
|
709
|
+
data,
|
|
697
710
|
...result
|
|
698
711
|
};
|
|
699
712
|
}
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
case "text":
|
|
706
|
-
data = await response[parseAs]();
|
|
707
|
-
break;
|
|
708
|
-
case "json": {
|
|
709
|
-
const text = await response.text();
|
|
710
|
-
data = text ? JSON.parse(text) : {};
|
|
711
|
-
break;
|
|
712
|
-
}
|
|
713
|
-
case "stream":
|
|
714
|
-
return opts.responseStyle === "data" ? response.body : {
|
|
715
|
-
data: response.body,
|
|
716
|
-
...result
|
|
717
|
-
};
|
|
713
|
+
const textError = await response.text();
|
|
714
|
+
let jsonError;
|
|
715
|
+
try {
|
|
716
|
+
jsonError = JSON.parse(textError);
|
|
717
|
+
} catch {
|
|
718
718
|
}
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
if (
|
|
724
|
-
|
|
719
|
+
throw jsonError ?? textError;
|
|
720
|
+
} catch (error) {
|
|
721
|
+
let finalError = error;
|
|
722
|
+
for (const fn of interceptors.error.fns) {
|
|
723
|
+
if (fn) {
|
|
724
|
+
finalError = await fn(finalError, response, request2, options);
|
|
725
725
|
}
|
|
726
726
|
}
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
};
|
|
731
|
-
}
|
|
732
|
-
const textError = await response.text();
|
|
733
|
-
let jsonError;
|
|
734
|
-
try {
|
|
735
|
-
jsonError = JSON.parse(textError);
|
|
736
|
-
} catch {
|
|
737
|
-
}
|
|
738
|
-
const error = jsonError ?? textError;
|
|
739
|
-
let finalError = error;
|
|
740
|
-
for (const fn of interceptors.error.fns) {
|
|
741
|
-
if (fn) {
|
|
742
|
-
finalError = await fn(error, response, request2, opts);
|
|
727
|
+
finalError = finalError || {};
|
|
728
|
+
if (throwOnError) {
|
|
729
|
+
throw finalError;
|
|
743
730
|
}
|
|
731
|
+
return responseStyle === "data" ? void 0 : {
|
|
732
|
+
error: finalError,
|
|
733
|
+
request: request2,
|
|
734
|
+
response
|
|
735
|
+
};
|
|
744
736
|
}
|
|
745
|
-
finalError = finalError || {};
|
|
746
|
-
if (opts.throwOnError) {
|
|
747
|
-
throw finalError;
|
|
748
|
-
}
|
|
749
|
-
return opts.responseStyle === "data" ? void 0 : {
|
|
750
|
-
error: finalError,
|
|
751
|
-
...result
|
|
752
|
-
};
|
|
753
737
|
};
|
|
754
738
|
const makeMethodFn = (method) => (options) => request({ ...options, method });
|
|
755
739
|
const makeSseFn = (method) => async (options) => {
|
|
@@ -757,7 +741,6 @@ var createClient = (config = {}) => {
|
|
|
757
741
|
return createSseClient({
|
|
758
742
|
...opts,
|
|
759
743
|
body: opts.body,
|
|
760
|
-
headers: opts.headers,
|
|
761
744
|
method,
|
|
762
745
|
onRequest: async (url2, init) => {
|
|
763
746
|
let request2 = new Request(url2, init);
|
|
@@ -772,8 +755,9 @@ var createClient = (config = {}) => {
|
|
|
772
755
|
url
|
|
773
756
|
});
|
|
774
757
|
};
|
|
758
|
+
const _buildUrl = (options) => buildUrl({ ..._config, ...options });
|
|
775
759
|
return {
|
|
776
|
-
buildUrl,
|
|
760
|
+
buildUrl: _buildUrl,
|
|
777
761
|
connect: makeMethodFn("CONNECT"),
|
|
778
762
|
delete: makeMethodFn("DELETE"),
|
|
779
763
|
get: makeMethodFn("GET"),
|
|
@@ -802,7 +786,7 @@ var createClient = (config = {}) => {
|
|
|
802
786
|
};
|
|
803
787
|
|
|
804
788
|
// src/client.ts
|
|
805
|
-
var client = createClient(createConfig({ baseUrl: "http://localhost:
|
|
789
|
+
var client = createClient(createConfig({ baseUrl: "http://localhost:0" }));
|
|
806
790
|
|
|
807
791
|
// src/config.ts
|
|
808
792
|
function configureSwapKit(options) {
|
|
@@ -824,17 +808,17 @@ var getTokens = (options) => (options?.client ?? client).get({
|
|
|
824
808
|
url: "/tokens",
|
|
825
809
|
...options
|
|
826
810
|
});
|
|
827
|
-
var
|
|
811
|
+
var getSwapToAssets = (options) => (options.client ?? client).get({
|
|
828
812
|
security: [{ name: "x-api-key", type: "apiKey" }],
|
|
829
813
|
url: "/swapTo",
|
|
830
814
|
...options
|
|
831
815
|
});
|
|
832
|
-
var
|
|
816
|
+
var getSwapFromAssets = (options) => (options.client ?? client).get({
|
|
833
817
|
security: [{ name: "x-api-key", type: "apiKey" }],
|
|
834
818
|
url: "/swapFrom",
|
|
835
819
|
...options
|
|
836
820
|
});
|
|
837
|
-
var
|
|
821
|
+
var createBrokerChannel = (options) => (options.client ?? client).post({
|
|
838
822
|
security: [{ name: "x-api-key", type: "apiKey" }],
|
|
839
823
|
url: "/chainflip/broker/channel",
|
|
840
824
|
...options,
|
|
@@ -843,7 +827,7 @@ var postChainflipBrokerChannel = (options) => (options.client ?? client).post({
|
|
|
843
827
|
...options.headers
|
|
844
828
|
}
|
|
845
829
|
});
|
|
846
|
-
var
|
|
830
|
+
var trackTransaction = (options) => (options?.client ?? client).post({
|
|
847
831
|
security: [{ name: "x-api-key", type: "apiKey" }],
|
|
848
832
|
url: "/track",
|
|
849
833
|
...options,
|
|
@@ -852,7 +836,7 @@ var postTrack = (options) => (options?.client ?? client).post({
|
|
|
852
836
|
...options?.headers
|
|
853
837
|
}
|
|
854
838
|
});
|
|
855
|
-
var
|
|
839
|
+
var screenAddress = (options) => (options.client ?? client).post({
|
|
856
840
|
security: [{ name: "x-api-key", type: "apiKey" }],
|
|
857
841
|
url: "/screen",
|
|
858
842
|
...options,
|
|
@@ -861,17 +845,17 @@ var postScreen = (options) => (options.client ?? client).post({
|
|
|
861
845
|
...options.headers
|
|
862
846
|
}
|
|
863
847
|
});
|
|
864
|
-
var
|
|
848
|
+
var getGasPrices = (options) => (options?.client ?? client).get({
|
|
865
849
|
security: [{ name: "x-api-key", type: "apiKey" }],
|
|
866
|
-
url: "/gas
|
|
850
|
+
url: "/gas",
|
|
867
851
|
...options
|
|
868
852
|
});
|
|
869
|
-
var
|
|
853
|
+
var getGasHistory = (options) => (options?.client ?? client).get({
|
|
870
854
|
security: [{ name: "x-api-key", type: "apiKey" }],
|
|
871
|
-
url: "/gas",
|
|
855
|
+
url: "/gas/history",
|
|
872
856
|
...options
|
|
873
857
|
});
|
|
874
|
-
var
|
|
858
|
+
var getCachedPrice = (options) => (options.client ?? client).post({
|
|
875
859
|
security: [{ name: "x-api-key", type: "apiKey" }],
|
|
876
860
|
url: "/price/cached-price",
|
|
877
861
|
...options,
|
|
@@ -880,7 +864,7 @@ var postPriceCachedPrice = (options) => (options.client ?? client).post({
|
|
|
880
864
|
...options.headers
|
|
881
865
|
}
|
|
882
866
|
});
|
|
883
|
-
var
|
|
867
|
+
var getQuote = (options) => (options.client ?? client).post({
|
|
884
868
|
security: [{ name: "x-api-key", type: "apiKey" }],
|
|
885
869
|
url: "/v3/quote",
|
|
886
870
|
...options,
|
|
@@ -889,7 +873,7 @@ var postV3Quote = (options) => (options.client ?? client).post({
|
|
|
889
873
|
...options.headers
|
|
890
874
|
}
|
|
891
875
|
});
|
|
892
|
-
var
|
|
876
|
+
var executeSwap = (options) => (options.client ?? client).post({
|
|
893
877
|
security: [{ name: "x-api-key", type: "apiKey" }],
|
|
894
878
|
url: "/v3/swap",
|
|
895
879
|
...options,
|
|
@@ -904,43 +888,43 @@ var SwapKitService = class {
|
|
|
904
888
|
};
|
|
905
889
|
SwapKitService.getProviders = getProviders;
|
|
906
890
|
SwapKitService.getTokens = getTokens;
|
|
907
|
-
SwapKitService.getSwapTo =
|
|
908
|
-
SwapKitService.getSwapFrom =
|
|
909
|
-
SwapKitService.getQuote =
|
|
910
|
-
SwapKitService.getSwap =
|
|
911
|
-
SwapKitService.trackTransaction =
|
|
912
|
-
SwapKitService.screenAddress =
|
|
913
|
-
SwapKitService.getGasPrices =
|
|
891
|
+
SwapKitService.getSwapTo = getSwapToAssets;
|
|
892
|
+
SwapKitService.getSwapFrom = getSwapFromAssets;
|
|
893
|
+
SwapKitService.getQuote = getQuote;
|
|
894
|
+
SwapKitService.getSwap = executeSwap;
|
|
895
|
+
SwapKitService.trackTransaction = trackTransaction;
|
|
896
|
+
SwapKitService.screenAddress = screenAddress;
|
|
897
|
+
SwapKitService.getGasPrices = getGasPrices;
|
|
914
898
|
SwapKitService.getGasHistory = getGasHistory;
|
|
915
|
-
SwapKitService.getCachedPrice =
|
|
916
|
-
SwapKitService.createBrokerChannel =
|
|
899
|
+
SwapKitService.getCachedPrice = getCachedPrice;
|
|
900
|
+
SwapKitService.createBrokerChannel = createBrokerChannel;
|
|
917
901
|
var TokenlistService = {
|
|
918
902
|
getProviders,
|
|
919
903
|
getTokens,
|
|
920
|
-
getSwapTo,
|
|
921
|
-
getSwapFrom
|
|
904
|
+
getSwapTo: getSwapToAssets,
|
|
905
|
+
getSwapFrom: getSwapFromAssets
|
|
922
906
|
};
|
|
923
907
|
var QuoteService = {
|
|
924
|
-
getQuote
|
|
908
|
+
getQuote
|
|
925
909
|
};
|
|
926
910
|
var SwapService = {
|
|
927
|
-
getSwap:
|
|
911
|
+
getSwap: executeSwap
|
|
928
912
|
};
|
|
929
913
|
var TrackService = {
|
|
930
|
-
trackTransaction
|
|
914
|
+
trackTransaction
|
|
931
915
|
};
|
|
932
916
|
var ScreenService = {
|
|
933
|
-
screenAddress
|
|
917
|
+
screenAddress
|
|
934
918
|
};
|
|
935
919
|
var GasService = {
|
|
936
|
-
getGasPrices
|
|
920
|
+
getGasPrices,
|
|
937
921
|
getGasHistory
|
|
938
922
|
};
|
|
939
923
|
var PriceService = {
|
|
940
|
-
getCachedPrice
|
|
924
|
+
getCachedPrice
|
|
941
925
|
};
|
|
942
926
|
var ChainflipService = {
|
|
943
|
-
createBrokerChannel
|
|
927
|
+
createBrokerChannel
|
|
944
928
|
};
|
|
945
929
|
export {
|
|
946
930
|
ChainflipService,
|
|
@@ -954,16 +938,16 @@ export {
|
|
|
954
938
|
TrackService,
|
|
955
939
|
client,
|
|
956
940
|
configureSwapKit,
|
|
957
|
-
|
|
941
|
+
createBrokerChannel,
|
|
942
|
+
executeSwap,
|
|
943
|
+
getCachedPrice,
|
|
958
944
|
getGasHistory,
|
|
945
|
+
getGasPrices,
|
|
959
946
|
getProviders,
|
|
960
|
-
|
|
961
|
-
|
|
947
|
+
getQuote,
|
|
948
|
+
getSwapFromAssets,
|
|
949
|
+
getSwapToAssets,
|
|
962
950
|
getTokens,
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
postScreen,
|
|
966
|
-
postTrack,
|
|
967
|
-
postV3Quote,
|
|
968
|
-
postV3Swap
|
|
951
|
+
screenAddress,
|
|
952
|
+
trackTransaction
|
|
969
953
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@swapkit/api-sdk-typescript",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.1.0-nightly.20260701161042",
|
|
4
4
|
"description": "Type-safe TypeScript SDK for the SwapKit API",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -19,7 +19,9 @@
|
|
|
19
19
|
"access": "public"
|
|
20
20
|
},
|
|
21
21
|
"scripts": {
|
|
22
|
-
"build": "tsup src/index.ts --format cjs,esm --dts"
|
|
22
|
+
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
23
|
+
"typecheck": "tsc --noEmit",
|
|
24
|
+
"release:check": "npm run typecheck && npm run build && npm pack --dry-run"
|
|
23
25
|
},
|
|
24
26
|
"dependencies": {},
|
|
25
27
|
"devDependencies": {
|
package/src/client.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
2
|
|
|
3
|
-
import { type ClientOptions, type Config, createClient, createConfig } from './http';
|
|
3
|
+
import { type Client, type ClientOptions, type Config, createClient, createConfig } from './http';
|
|
4
4
|
import type { ClientOptions as ClientOptions2 } from './types';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -11,6 +11,6 @@ import type { ClientOptions as ClientOptions2 } from './types';
|
|
|
11
11
|
* `setConfig()`. This is useful for example if you're using Next.js
|
|
12
12
|
* to ensure your client always has the correct values.
|
|
13
13
|
*/
|
|
14
|
-
export type CreateClientConfig<T extends ClientOptions = ClientOptions2> = (override?: Config<ClientOptions & T>) => Config<Required<ClientOptions> & T
|
|
14
|
+
export type CreateClientConfig<T extends ClientOptions = ClientOptions2> = (override?: Config<ClientOptions & T>) => Config<Required<ClientOptions> & T>;
|
|
15
15
|
|
|
16
|
-
export const client = createClient(createConfig<ClientOptions2>({ baseUrl: 'http://localhost:
|
|
16
|
+
export const client: Client = createClient(createConfig<ClientOptions2>({ baseUrl: 'http://localhost:0' }));
|
package/src/core/auth.ts
CHANGED
|
@@ -9,6 +9,13 @@ export interface Auth {
|
|
|
9
9
|
* @default 'header'
|
|
10
10
|
*/
|
|
11
11
|
in?: 'header' | 'query' | 'cookie';
|
|
12
|
+
/**
|
|
13
|
+
* A unique identifier for the security scheme.
|
|
14
|
+
*
|
|
15
|
+
* Defined only when there are multiple security schemes whose `Auth`
|
|
16
|
+
* shape would otherwise be identical.
|
|
17
|
+
*/
|
|
18
|
+
key?: string;
|
|
12
19
|
/**
|
|
13
20
|
* Header or query parameter name.
|
|
14
21
|
*
|
|
@@ -4,7 +4,7 @@ import type { ArrayStyle, ObjectStyle, SerializerOptions } from './pathSerialize
|
|
|
4
4
|
|
|
5
5
|
export type QuerySerializer = (query: Record<string, unknown>) => string;
|
|
6
6
|
|
|
7
|
-
export type BodySerializer = (body:
|
|
7
|
+
export type BodySerializer = (body: unknown) => unknown;
|
|
8
8
|
|
|
9
9
|
type QuerySerializerOptionsObject = {
|
|
10
10
|
allowReserved?: boolean;
|
|
@@ -39,12 +39,10 @@ const serializeUrlSearchParamsPair = (data: URLSearchParams, key: string, value:
|
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
export const formDataBodySerializer = {
|
|
42
|
-
bodySerializer:
|
|
43
|
-
body: T,
|
|
44
|
-
): FormData => {
|
|
42
|
+
bodySerializer: (body: unknown): FormData => {
|
|
45
43
|
const data = new FormData();
|
|
46
44
|
|
|
47
|
-
Object.entries(body).forEach(([key, value]) => {
|
|
45
|
+
Object.entries(body as Record<string, unknown>).forEach(([key, value]) => {
|
|
48
46
|
if (value === undefined || value === null) {
|
|
49
47
|
return;
|
|
50
48
|
}
|
|
@@ -60,15 +58,15 @@ export const formDataBodySerializer = {
|
|
|
60
58
|
};
|
|
61
59
|
|
|
62
60
|
export const jsonBodySerializer = {
|
|
63
|
-
bodySerializer:
|
|
61
|
+
bodySerializer: (body: unknown): string =>
|
|
64
62
|
JSON.stringify(body, (_key, value) => (typeof value === 'bigint' ? value.toString() : value)),
|
|
65
63
|
};
|
|
66
64
|
|
|
67
65
|
export const urlSearchParamsBodySerializer = {
|
|
68
|
-
bodySerializer:
|
|
66
|
+
bodySerializer: (body: unknown): string => {
|
|
69
67
|
const data = new URLSearchParams();
|
|
70
68
|
|
|
71
|
-
Object.entries(body).forEach(([key, value]) => {
|
|
69
|
+
Object.entries(body as Record<string, unknown>).forEach(([key, value]) => {
|
|
72
70
|
if (value === undefined || value === null) {
|
|
73
71
|
return;
|
|
74
72
|
}
|
package/src/core/params.ts
CHANGED
|
@@ -62,7 +62,7 @@ type KeyMap = Map<
|
|
|
62
62
|
}
|
|
63
63
|
>;
|
|
64
64
|
|
|
65
|
-
|
|
65
|
+
function buildKeyMap(fields: FieldsConfig, map?: KeyMap): KeyMap {
|
|
66
66
|
if (!map) {
|
|
67
67
|
map = new Map();
|
|
68
68
|
}
|
|
@@ -85,33 +85,42 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => {
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
return map;
|
|
88
|
-
}
|
|
88
|
+
}
|
|
89
89
|
|
|
90
90
|
interface Params {
|
|
91
|
-
body
|
|
91
|
+
body?: unknown;
|
|
92
92
|
headers: Record<string, unknown>;
|
|
93
93
|
path: Record<string, unknown>;
|
|
94
94
|
query: Record<string, unknown>;
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
|
|
97
|
+
function stripEmptySlots(params: Params): void {
|
|
98
98
|
for (const [slot, value] of Object.entries(params)) {
|
|
99
|
+
if (slot === 'body') continue;
|
|
99
100
|
if (value && typeof value === 'object' && !Array.isArray(value) && !Object.keys(value).length) {
|
|
100
101
|
delete params[slot as Slot];
|
|
101
102
|
}
|
|
102
103
|
}
|
|
103
|
-
}
|
|
104
|
+
}
|
|
104
105
|
|
|
105
|
-
export
|
|
106
|
+
export function buildClientParams(args: ReadonlyArray<unknown>, fields: FieldsConfig): Params {
|
|
106
107
|
const params: Params = {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
query: {},
|
|
108
|
+
headers: Object.create(null),
|
|
109
|
+
path: Object.create(null),
|
|
110
|
+
query: Object.create(null),
|
|
111
111
|
};
|
|
112
112
|
|
|
113
113
|
const map = buildKeyMap(fields);
|
|
114
114
|
|
|
115
|
+
function writeSlot(slot: Slot, key: string, value: unknown): void {
|
|
116
|
+
let record = params[slot] as Record<string, unknown> | undefined;
|
|
117
|
+
if (record === undefined) {
|
|
118
|
+
record = Object.create(null) as Record<string, unknown>;
|
|
119
|
+
params[slot] = record;
|
|
120
|
+
}
|
|
121
|
+
record[key] = value;
|
|
122
|
+
}
|
|
123
|
+
|
|
115
124
|
let config: FieldsConfig[number] | undefined;
|
|
116
125
|
|
|
117
126
|
for (const [index, arg] of args.entries()) {
|
|
@@ -128,7 +137,7 @@ export const buildClientParams = (args: ReadonlyArray<unknown>, fields: FieldsCo
|
|
|
128
137
|
const field = map.get(config.key)!;
|
|
129
138
|
const name = field.map || config.key;
|
|
130
139
|
if (field.in) {
|
|
131
|
-
(
|
|
140
|
+
writeSlot(field.in, name, arg);
|
|
132
141
|
}
|
|
133
142
|
} else {
|
|
134
143
|
params.body = arg;
|
|
@@ -140,7 +149,7 @@ export const buildClientParams = (args: ReadonlyArray<unknown>, fields: FieldsCo
|
|
|
140
149
|
if (field) {
|
|
141
150
|
if (field.in) {
|
|
142
151
|
const name = field.map || key;
|
|
143
|
-
(
|
|
152
|
+
writeSlot(field.in, name, value);
|
|
144
153
|
} else {
|
|
145
154
|
params[field.map] = value;
|
|
146
155
|
}
|
|
@@ -149,11 +158,11 @@ export const buildClientParams = (args: ReadonlyArray<unknown>, fields: FieldsCo
|
|
|
149
158
|
|
|
150
159
|
if (extra) {
|
|
151
160
|
const [prefix, slot] = extra;
|
|
152
|
-
(
|
|
161
|
+
writeSlot(slot, key.slice(prefix.length), value);
|
|
153
162
|
} else if ('allowExtra' in config && config.allowExtra) {
|
|
154
163
|
for (const [slot, allowed] of Object.entries(config.allowExtra)) {
|
|
155
164
|
if (allowed) {
|
|
156
|
-
(
|
|
165
|
+
writeSlot(slot as Slot, key, value);
|
|
157
166
|
break;
|
|
158
167
|
}
|
|
159
168
|
}
|
|
@@ -166,4 +175,4 @@ export const buildClientParams = (args: ReadonlyArray<unknown>, fields: FieldsCo
|
|
|
166
175
|
stripEmptySlots(params);
|
|
167
176
|
|
|
168
177
|
return params;
|
|
169
|
-
}
|
|
178
|
+
}
|