@swapkit/api-sdk-typescript 1.0.5 → 1.1.0-nightly.20260703093208

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 CHANGED
@@ -10,6 +10,12 @@ npm install @swapkit/api-sdk-typescript
10
10
  bun add @swapkit/api-sdk-typescript
11
11
  ```
12
12
 
13
+ For the bleeding-edge build tracking the API's `develop` branch, install the `nightly` tag:
14
+
15
+ ```bash
16
+ npm install @swapkit/api-sdk-typescript@nightly
17
+ ```
18
+
13
19
  ## Quick Start
14
20
 
15
21
  ```typescript
package/dist/index.cjs CHANGED
@@ -502,11 +502,8 @@ var checkForExistence = (options, name) => {
502
502
  }
503
503
  return false;
504
504
  };
505
- var setAuthParams = async ({
506
- security,
507
- ...options
508
- }) => {
509
- for (const auth of security) {
505
+ async function setAuthParams(options) {
506
+ for (const auth of options.security ?? []) {
510
507
  if (checkForExistence(options, auth.name)) {
511
508
  continue;
512
509
  }
@@ -531,7 +528,7 @@ var setAuthParams = async ({
531
528
  break;
532
529
  }
533
530
  }
534
- };
531
+ }
535
532
  var buildUrl = (options) => getUrl({
536
533
  baseUrl: options.baseUrl,
537
534
  path: options.path,
@@ -659,10 +656,7 @@ var createClient = (config = {}) => {
659
656
  serializedBody: void 0
660
657
  };
661
658
  if (opts.security) {
662
- await setAuthParams({
663
- ...opts,
664
- security: opts.security
665
- });
659
+ await setAuthParams(opts);
666
660
  }
667
661
  if (opts.requestValidator) {
668
662
  await opts.requestValidator(opts);
@@ -678,127 +672,116 @@ var createClient = (config = {}) => {
678
672
  return { opts: resolvedOpts, url };
679
673
  };
680
674
  const request = async (options) => {
681
- const { opts, url } = await beforeRequest(options);
682
- const requestInit = {
683
- redirect: "follow",
684
- ...opts,
685
- body: getValidRequestBody(opts)
686
- };
687
- let request2 = new Request(url, requestInit);
688
- for (const fn of interceptors.request.fns) {
689
- if (fn) {
690
- request2 = await fn(request2, opts);
691
- }
692
- }
693
- const _fetch = opts.fetch;
675
+ const throwOnError = options.throwOnError ?? _config.throwOnError;
676
+ const responseStyle = options.responseStyle ?? _config.responseStyle;
677
+ let request2;
694
678
  let response;
695
679
  try {
696
- response = await _fetch(request2);
697
- } catch (error2) {
698
- let finalError2 = error2;
699
- for (const fn of interceptors.error.fns) {
680
+ const { opts, url } = await beforeRequest(options);
681
+ const requestInit = {
682
+ redirect: "follow",
683
+ ...opts,
684
+ body: getValidRequestBody(opts)
685
+ };
686
+ request2 = new Request(url, requestInit);
687
+ for (const fn of interceptors.request.fns) {
700
688
  if (fn) {
701
- finalError2 = await fn(error2, void 0, request2, opts);
689
+ request2 = await fn(request2, opts);
702
690
  }
703
691
  }
704
- finalError2 = finalError2 || {};
705
- if (opts.throwOnError) {
706
- throw finalError2;
692
+ const _fetch = opts.fetch;
693
+ response = await _fetch(request2);
694
+ for (const fn of interceptors.response.fns) {
695
+ if (fn) {
696
+ response = await fn(response, request2, opts);
697
+ }
707
698
  }
708
- return opts.responseStyle === "data" ? void 0 : {
709
- error: finalError2,
699
+ const result = {
710
700
  request: request2,
711
- response: void 0
701
+ response
712
702
  };
713
- }
714
- for (const fn of interceptors.response.fns) {
715
- if (fn) {
716
- response = await fn(response, request2, opts);
717
- }
718
- }
719
- const result = {
720
- request: request2,
721
- response
722
- };
723
- if (response.ok) {
724
- const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
725
- if (response.status === 204 || response.headers.get("Content-Length") === "0") {
726
- let emptyData;
703
+ if (response.ok) {
704
+ const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
705
+ if (response.status === 204 || response.headers.get("Content-Length") === "0") {
706
+ let emptyData;
707
+ switch (parseAs) {
708
+ case "arrayBuffer":
709
+ case "blob":
710
+ case "text":
711
+ emptyData = await response[parseAs]();
712
+ break;
713
+ case "formData":
714
+ emptyData = new FormData();
715
+ break;
716
+ case "stream":
717
+ emptyData = response.body;
718
+ break;
719
+ case "json":
720
+ default:
721
+ emptyData = {};
722
+ break;
723
+ }
724
+ return opts.responseStyle === "data" ? emptyData : {
725
+ data: emptyData,
726
+ ...result
727
+ };
728
+ }
729
+ let data;
727
730
  switch (parseAs) {
728
731
  case "arrayBuffer":
729
732
  case "blob":
733
+ case "formData":
730
734
  case "text":
731
- emptyData = await response[parseAs]();
735
+ data = await response[parseAs]();
732
736
  break;
733
- case "formData":
734
- emptyData = new FormData();
737
+ case "json": {
738
+ const text = await response.text();
739
+ data = text ? JSON.parse(text) : {};
735
740
  break;
741
+ }
736
742
  case "stream":
737
- emptyData = response.body;
738
- break;
739
- case "json":
740
- default:
741
- emptyData = {};
742
- break;
743
+ return opts.responseStyle === "data" ? response.body : {
744
+ data: response.body,
745
+ ...result
746
+ };
743
747
  }
744
- return opts.responseStyle === "data" ? emptyData : {
745
- data: emptyData,
748
+ if (parseAs === "json") {
749
+ if (opts.responseValidator) {
750
+ await opts.responseValidator(data);
751
+ }
752
+ if (opts.responseTransformer) {
753
+ data = await opts.responseTransformer(data);
754
+ }
755
+ }
756
+ return opts.responseStyle === "data" ? data : {
757
+ data,
746
758
  ...result
747
759
  };
748
760
  }
749
- let data;
750
- switch (parseAs) {
751
- case "arrayBuffer":
752
- case "blob":
753
- case "formData":
754
- case "text":
755
- data = await response[parseAs]();
756
- break;
757
- case "json": {
758
- const text = await response.text();
759
- data = text ? JSON.parse(text) : {};
760
- break;
761
- }
762
- case "stream":
763
- return opts.responseStyle === "data" ? response.body : {
764
- data: response.body,
765
- ...result
766
- };
761
+ const textError = await response.text();
762
+ let jsonError;
763
+ try {
764
+ jsonError = JSON.parse(textError);
765
+ } catch {
767
766
  }
768
- if (parseAs === "json") {
769
- if (opts.responseValidator) {
770
- await opts.responseValidator(data);
771
- }
772
- if (opts.responseTransformer) {
773
- data = await opts.responseTransformer(data);
767
+ throw jsonError ?? textError;
768
+ } catch (error) {
769
+ let finalError = error;
770
+ for (const fn of interceptors.error.fns) {
771
+ if (fn) {
772
+ finalError = await fn(finalError, response, request2, options);
774
773
  }
775
774
  }
776
- return opts.responseStyle === "data" ? data : {
777
- data,
778
- ...result
779
- };
780
- }
781
- const textError = await response.text();
782
- let jsonError;
783
- try {
784
- jsonError = JSON.parse(textError);
785
- } catch {
786
- }
787
- const error = jsonError ?? textError;
788
- let finalError = error;
789
- for (const fn of interceptors.error.fns) {
790
- if (fn) {
791
- finalError = await fn(error, response, request2, opts);
775
+ finalError = finalError || {};
776
+ if (throwOnError) {
777
+ throw finalError;
792
778
  }
779
+ return responseStyle === "data" ? void 0 : {
780
+ error: finalError,
781
+ request: request2,
782
+ response
783
+ };
793
784
  }
794
- finalError = finalError || {};
795
- if (opts.throwOnError) {
796
- throw finalError;
797
- }
798
- return opts.responseStyle === "data" ? void 0 : {
799
- error: finalError,
800
- ...result
801
- };
802
785
  };
803
786
  const makeMethodFn = (method) => (options) => request({ ...options, method });
804
787
  const makeSseFn = (method) => async (options) => {
@@ -806,7 +789,6 @@ var createClient = (config = {}) => {
806
789
  return createSseClient({
807
790
  ...opts,
808
791
  body: opts.body,
809
- headers: opts.headers,
810
792
  method,
811
793
  onRequest: async (url2, init) => {
812
794
  let request2 = new Request(url2, init);
@@ -923,7 +905,7 @@ var getGasHistory = (options) => (options?.client ?? client).get({
923
905
  });
924
906
  var getCachedPrice = (options) => (options.client ?? client).post({
925
907
  security: [{ name: "x-api-key", type: "apiKey" }],
926
- url: "/price/cached-price",
908
+ url: "/price",
927
909
  ...options,
928
910
  headers: {
929
911
  "Content-Type": "application/json",