@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/dist/index.js CHANGED
@@ -454,11 +454,8 @@ var checkForExistence = (options, name) => {
454
454
  }
455
455
  return false;
456
456
  };
457
- var setAuthParams = async ({
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);
@@ -630,127 +624,116 @@ var createClient = (config = {}) => {
630
624
  return { opts: resolvedOpts, url };
631
625
  };
632
626
  const request = async (options) => {
633
- const { opts, url } = await beforeRequest(options);
634
- const requestInit = {
635
- redirect: "follow",
636
- ...opts,
637
- body: getValidRequestBody(opts)
638
- };
639
- let request2 = new Request(url, requestInit);
640
- for (const fn of interceptors.request.fns) {
641
- if (fn) {
642
- request2 = await fn(request2, opts);
643
- }
644
- }
645
- const _fetch = opts.fetch;
627
+ const throwOnError = options.throwOnError ?? _config.throwOnError;
628
+ const responseStyle = options.responseStyle ?? _config.responseStyle;
629
+ let request2;
646
630
  let response;
647
631
  try {
648
- response = await _fetch(request2);
649
- } catch (error2) {
650
- let finalError2 = error2;
651
- for (const fn of interceptors.error.fns) {
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) {
652
640
  if (fn) {
653
- finalError2 = await fn(error2, void 0, request2, opts);
641
+ request2 = await fn(request2, opts);
654
642
  }
655
643
  }
656
- finalError2 = finalError2 || {};
657
- if (opts.throwOnError) {
658
- throw finalError2;
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
+ }
659
650
  }
660
- return opts.responseStyle === "data" ? void 0 : {
661
- error: finalError2,
651
+ const result = {
662
652
  request: request2,
663
- response: void 0
653
+ response
664
654
  };
665
- }
666
- for (const fn of interceptors.response.fns) {
667
- if (fn) {
668
- response = await fn(response, request2, opts);
669
- }
670
- }
671
- const result = {
672
- request: request2,
673
- response
674
- };
675
- if (response.ok) {
676
- const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
677
- if (response.status === 204 || response.headers.get("Content-Length") === "0") {
678
- let emptyData;
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;
679
682
  switch (parseAs) {
680
683
  case "arrayBuffer":
681
684
  case "blob":
685
+ case "formData":
682
686
  case "text":
683
- emptyData = await response[parseAs]();
687
+ data = await response[parseAs]();
684
688
  break;
685
- case "formData":
686
- emptyData = new FormData();
689
+ case "json": {
690
+ const text = await response.text();
691
+ data = text ? JSON.parse(text) : {};
687
692
  break;
693
+ }
688
694
  case "stream":
689
- emptyData = response.body;
690
- break;
691
- case "json":
692
- default:
693
- emptyData = {};
694
- break;
695
+ return opts.responseStyle === "data" ? response.body : {
696
+ data: response.body,
697
+ ...result
698
+ };
695
699
  }
696
- return opts.responseStyle === "data" ? emptyData : {
697
- data: emptyData,
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
+ }
707
+ }
708
+ return opts.responseStyle === "data" ? data : {
709
+ data,
698
710
  ...result
699
711
  };
700
712
  }
701
- let data;
702
- switch (parseAs) {
703
- case "arrayBuffer":
704
- case "blob":
705
- case "formData":
706
- case "text":
707
- data = await response[parseAs]();
708
- break;
709
- case "json": {
710
- const text = await response.text();
711
- data = text ? JSON.parse(text) : {};
712
- break;
713
- }
714
- case "stream":
715
- return opts.responseStyle === "data" ? response.body : {
716
- data: response.body,
717
- ...result
718
- };
713
+ const textError = await response.text();
714
+ let jsonError;
715
+ try {
716
+ jsonError = JSON.parse(textError);
717
+ } catch {
719
718
  }
720
- if (parseAs === "json") {
721
- if (opts.responseValidator) {
722
- await opts.responseValidator(data);
723
- }
724
- if (opts.responseTransformer) {
725
- data = await opts.responseTransformer(data);
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);
726
725
  }
727
726
  }
728
- return opts.responseStyle === "data" ? data : {
729
- data,
730
- ...result
731
- };
732
- }
733
- const textError = await response.text();
734
- let jsonError;
735
- try {
736
- jsonError = JSON.parse(textError);
737
- } catch {
738
- }
739
- const error = jsonError ?? textError;
740
- let finalError = error;
741
- for (const fn of interceptors.error.fns) {
742
- if (fn) {
743
- finalError = await fn(error, response, request2, opts);
727
+ finalError = finalError || {};
728
+ if (throwOnError) {
729
+ throw finalError;
744
730
  }
731
+ return responseStyle === "data" ? void 0 : {
732
+ error: finalError,
733
+ request: request2,
734
+ response
735
+ };
745
736
  }
746
- finalError = finalError || {};
747
- if (opts.throwOnError) {
748
- throw finalError;
749
- }
750
- return opts.responseStyle === "data" ? void 0 : {
751
- error: finalError,
752
- ...result
753
- };
754
737
  };
755
738
  const makeMethodFn = (method) => (options) => request({ ...options, method });
756
739
  const makeSseFn = (method) => async (options) => {
@@ -758,7 +741,6 @@ var createClient = (config = {}) => {
758
741
  return createSseClient({
759
742
  ...opts,
760
743
  body: opts.body,
761
- headers: opts.headers,
762
744
  method,
763
745
  onRequest: async (url2, init) => {
764
746
  let request2 = new Request(url2, init);
@@ -875,7 +857,7 @@ var getGasHistory = (options) => (options?.client ?? client).get({
875
857
  });
876
858
  var getCachedPrice = (options) => (options.client ?? client).post({
877
859
  security: [{ name: "x-api-key", type: "apiKey" }],
878
- url: "/price/cached-price",
860
+ url: "/price",
879
861
  ...options,
880
862
  headers: {
881
863
  "Content-Type": "application/json",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swapkit/api-sdk-typescript",
3
- "version": "1.0.5",
3
+ "version": "1.1.0-nightly.20260703093208",
4
4
  "description": "Type-safe TypeScript SDK for the SwapKit API",
5
5
  "license": "MIT",
6
6
  "type": "module",
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
  /**
@@ -13,4 +13,4 @@ import type { ClientOptions as ClientOptions2 } from './types';
13
13
  */
14
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:0' }));
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
  *
@@ -62,7 +62,7 @@ type KeyMap = Map<
62
62
  }
63
63
  >;
64
64
 
65
- const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => {
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: unknown;
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
- const stripEmptySlots = (params: Params) => {
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 const buildClientParams = (args: ReadonlyArray<unknown>, fields: FieldsConfig) => {
106
+ export function buildClientParams(args: ReadonlyArray<unknown>, fields: FieldsConfig): Params {
106
107
  const params: Params = {
107
- body: {},
108
- headers: {},
109
- path: {},
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
- (params[field.in] as Record<string, unknown>)[name] = arg;
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
- (params[field.in] as Record<string, unknown>)[name] = value;
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
- (params[slot] as Record<string, unknown>)[key.slice(prefix.length)] = value;
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
- (params[slot as Slot] as Record<string, unknown>)[key] = value;
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
+ }
@@ -25,7 +25,7 @@ interface SerializePrimitiveParam extends SerializePrimitiveOptions {
25
25
  value: string;
26
26
  }
27
27
 
28
- export const separatorArrayExplode = (style: ArraySeparatorStyle) => {
28
+ export const separatorArrayExplode = (style: ArraySeparatorStyle): '.' | ';' | ',' | '&' => {
29
29
  switch (style) {
30
30
  case 'label':
31
31
  return '.';
@@ -38,7 +38,7 @@ export const separatorArrayExplode = (style: ArraySeparatorStyle) => {
38
38
  }
39
39
  };
40
40
 
41
- export const separatorArrayNoExplode = (style: ArraySeparatorStyle) => {
41
+ export const separatorArrayNoExplode = (style: ArraySeparatorStyle): ',' | '|' | '%20' => {
42
42
  switch (style) {
43
43
  case 'form':
44
44
  return ',';
@@ -51,7 +51,7 @@ export const separatorArrayNoExplode = (style: ArraySeparatorStyle) => {
51
51
  }
52
52
  };
53
53
 
54
- export const separatorObjectExplode = (style: ObjectSeparatorStyle) => {
54
+ export const separatorObjectExplode = (style: ObjectSeparatorStyle): '.' | ';' | ',' | '&' => {
55
55
  switch (style) {
56
56
  case 'label':
57
57
  return '.';
@@ -72,7 +72,7 @@ export const serializeArrayParam = ({
72
72
  value,
73
73
  }: SerializeOptions<ArraySeparatorStyle> & {
74
74
  value: unknown[];
75
- }) => {
75
+ }): string => {
76
76
  if (!explode) {
77
77
  const joinedValues = (
78
78
  allowReserved ? value : value.map((v) => encodeURIComponent(v as string))
@@ -110,7 +110,7 @@ export const serializePrimitiveParam = ({
110
110
  allowReserved,
111
111
  name,
112
112
  value,
113
- }: SerializePrimitiveParam) => {
113
+ }: SerializePrimitiveParam): string => {
114
114
  if (value === undefined || value === null) {
115
115
  return '';
116
116
  }
@@ -134,7 +134,7 @@ export const serializeObjectParam = ({
134
134
  }: SerializeOptions<ObjectSeparatorStyle> & {
135
135
  value: Record<string, unknown> | Date;
136
136
  valueOnly?: boolean;
137
- }) => {
137
+ }): string => {
138
138
  if (value instanceof Date) {
139
139
  return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
140
140
  }
@@ -14,7 +14,7 @@ export type JsonValue =
14
14
  /**
15
15
  * Replacer that converts non-JSON values (bigint, Date, etc.) to safe substitutes.
16
16
  */
17
- export const queryKeyJsonReplacer = (_key: string, value: unknown) => {
17
+ export const queryKeyJsonReplacer = (_key: string, value: unknown): unknown | undefined => {
18
18
  if (value === undefined || typeof value === 'function' || typeof value === 'symbol') {
19
19
  return undefined;
20
20
  }
package/src/core/types.ts CHANGED
@@ -91,6 +91,12 @@ export interface Config {
91
91
  responseValidator?: (data: unknown) => Promise<unknown>;
92
92
  }
93
93
 
94
+ /**
95
+ * Arbitrary metadata passed through the `meta` request option.
96
+ */
97
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type
98
+ export interface ClientMeta {}
99
+
94
100
  type IsExactlyNeverOrNeverUndefined<T> = [T] extends [never]
95
101
  ? true
96
102
  : [T] extends [never | undefined]
package/src/core/utils.ts CHANGED
@@ -13,9 +13,9 @@ export interface PathSerializer {
13
13
  url: string;
14
14
  }
15
15
 
16
- export const PATH_PARAM_RE = /\{[^{}]+\}/g;
16
+ export const PATH_PARAM_RE: RegExp = /\{[^{}]+\}/g;
17
17
 
18
- export const defaultPathSerializer = ({ path, url: _url }: PathSerializer) => {
18
+ export const defaultPathSerializer = ({ path, url: _url }: PathSerializer): string => {
19
19
  let url = _url;
20
20
  const matches = _url.match(PATH_PARAM_RE);
21
21
  if (matches) {
@@ -94,7 +94,7 @@ export const getUrl = ({
94
94
  query?: Record<string, unknown>;
95
95
  querySerializer: QuerySerializer;
96
96
  url: string;
97
- }) => {
97
+ }): string => {
98
98
  const pathUrl = _url.startsWith('/') ? _url : `/${_url}`;
99
99
  let url = (baseUrl ?? '') + pathUrl;
100
100
  if (path) {
@@ -114,7 +114,7 @@ export function getValidRequestBody(options: {
114
114
  body?: unknown;
115
115
  bodySerializer?: BodySerializer | null;
116
116
  serializedBody?: unknown;
117
- }) {
117
+ }): unknown {
118
118
  const hasBody = options.body !== undefined;
119
119
  const isSerializedBody = hasBody && options.bodySerializer;
120
120