@tickwise/sdk 0.1.0 → 0.1.1

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.
Files changed (42) hide show
  1. package/README.md +30 -12
  2. package/dist/cjs/client.d.ts +10 -10
  3. package/dist/cjs/client.js +6 -1
  4. package/dist/cjs/errors.d.ts +56 -8
  5. package/dist/cjs/errors.js +65 -4
  6. package/dist/cjs/generated/openapi.d.ts +129 -1
  7. package/dist/cjs/index.d.ts +1 -1
  8. package/dist/cjs/index.js +4 -1
  9. package/dist/cjs/resources/hooks.d.ts +2 -2
  10. package/dist/cjs/resources/pools.d.ts +7 -7
  11. package/dist/cjs/resources/positions.d.ts +27 -13
  12. package/dist/cjs/resources/positions.js +66 -12
  13. package/dist/cjs/resources/tokens.d.ts +9 -3
  14. package/dist/cjs/resources/tokens.js +8 -0
  15. package/dist/cjs/routes.d.ts +4 -0
  16. package/dist/cjs/routes.js +5 -0
  17. package/dist/cjs/transport.d.ts +8 -7
  18. package/dist/cjs/transport.js +8 -4
  19. package/dist/cjs/types.d.ts +26 -13
  20. package/dist/cjs/version.d.ts +1 -1
  21. package/dist/cjs/version.js +1 -1
  22. package/dist/esm/client.d.ts +10 -10
  23. package/dist/esm/client.js +6 -1
  24. package/dist/esm/errors.d.ts +56 -8
  25. package/dist/esm/errors.js +61 -3
  26. package/dist/esm/generated/openapi.d.ts +129 -1
  27. package/dist/esm/index.d.ts +1 -1
  28. package/dist/esm/index.js +1 -1
  29. package/dist/esm/resources/hooks.d.ts +2 -2
  30. package/dist/esm/resources/pools.d.ts +7 -7
  31. package/dist/esm/resources/positions.d.ts +27 -13
  32. package/dist/esm/resources/positions.js +66 -12
  33. package/dist/esm/resources/tokens.d.ts +9 -3
  34. package/dist/esm/resources/tokens.js +8 -0
  35. package/dist/esm/routes.d.ts +4 -0
  36. package/dist/esm/routes.js +5 -0
  37. package/dist/esm/transport.d.ts +8 -7
  38. package/dist/esm/transport.js +8 -4
  39. package/dist/esm/types.d.ts +26 -13
  40. package/dist/esm/version.d.ts +1 -1
  41. package/dist/esm/version.js +1 -1
  42. package/package.json +1 -1
@@ -117,9 +117,10 @@ async function readText(res, max) {
117
117
  * Whether a failed attempt is retried.
118
118
  *
119
119
  * A metered call is retried only when the API cannot have charged it: the burst rate limit (429 `rate`, refused
120
- * before any charge), a 503 (the API credits it back), a 502 (the API did not answer the gateway), and a
121
- * connection that was never opened. A timeout, a connection lost mid-request and a 504 are NOT retried on a metered
122
- * route: the API may have served, and charged, the first attempt, so a retry could be billed twice.
120
+ * before any charge), a 503 (the API credits it back), and a connection that was never opened. A timeout, a
121
+ * connection lost mid-request, a 502 and a 504 are NOT retried on a metered route: the API may have served, and
122
+ * charged, the first attempt. A 502 comes from the gateway, not the API, so the API's refund of its own 5xx never
123
+ * ran (a process stopped by a deploy after the charge answers 502), and a retry could be billed twice.
123
124
  * A free route costs nothing, so those are retried there too.
124
125
  * Never retried: the monthly quota (nothing changes until it resets), 400 / 401 / 403 / 404, and 500.
125
126
  */
@@ -130,7 +131,7 @@ export function isRetryable(e, metered) {
130
131
  return !metered || e.connectFailed;
131
132
  if (e instanceof TimeoutError)
132
133
  return !metered;
133
- return e instanceof APIError && (e.status === 502 || (e.status === 504 && !metered));
134
+ return e instanceof APIError && (e.status === 502 || e.status === 504) && !metered;
134
135
  }
135
136
  /** Error codes that mean no connection was made, so nothing reached the API (Node / undici names). */
136
137
  const CONNECT_FAILED_CODES = new Set([
@@ -257,6 +258,9 @@ export class Transport {
257
258
  });
258
259
  }
259
260
  const text = await readText(res, this.#config.maxBodyBytes);
261
+ // An error answer over the cap still gets its own class (and `Retry-After`), so a 429 / 503 is still retried.
262
+ if (text === null && (res.status < 200 || res.status >= 300))
263
+ throw errorFromResponse(res.status, res.headers, undefined, url);
260
264
  if (text === null) {
261
265
  throw new APIError('api_error', `The response is larger than maxBodyBytes (${this.#config.maxBodyBytes})`, {
262
266
  status: res.status,
@@ -18,6 +18,9 @@ export type TokenPrice = S['TokenPrice'];
18
18
  export type TokenSecurity = S['TokenSecurity'];
19
19
  export type TokenTrust = S['TokenTrust'];
20
20
  export type TokenLookup = S['TokenLookup'];
21
+ export type TokenSearch = S['TokenSearch'];
22
+ export type TokenSearchMatch = S['TokenSearchMatch'];
23
+ export type TokenSearchPool = S['TokenSearchPool'];
21
24
  export type Hook = S['Hook'];
22
25
  export type HookList = S['HookList'];
23
26
  export type WalletFigures = S['WalletFigures'];
@@ -36,7 +39,10 @@ export type ErrorBody = S['Error'];
36
39
  * type error. `GET /v1/protocols` (`tw.protocols()`) is the live list.
37
40
  */
38
41
  export type ProtocolKey = 'uniswap-v4' | (string & {});
39
- /** A position id (an ERC-721 token id): digits. A `bigint` or `number` is sent as its decimal string. */
42
+ /**
43
+ * A position id (an ERC-721 token id): digits. A `bigint` or `number` is sent as its decimal string. A `number` must
44
+ * be a safe integer (at most 2^53 − 1): a larger one has already lost digits, so it is refused with a `TypeError`.
45
+ */
40
46
  export type PositionId = string | bigint | number;
41
47
  /** Dotted field paths, e.g. `['positionId', 'metrics.apr']` or `'positionId,metrics.apr'`. At most 60. */
42
48
  export type Fields = string | readonly string[];
@@ -45,10 +51,14 @@ type RawQuery<Op extends keyof operations> = NonNullable<operations[Op]['paramet
45
51
  export type OmitKeys<T, K extends PropertyKey> = {
46
52
  [P in keyof T as P extends K ? never : P]: T[P];
47
53
  };
48
- type Widen<Q> = OmitKeys<Q, 'protocol' | 'fields' | 'format'> & ('protocol' extends keyof Q ? {
49
- protocol?: ProtocolKey;
54
+ /** Every optional key also takes `undefined` (dropped from the URL), so `{ owner: maybeOwner }` compiles under `exactOptionalPropertyTypes`. */
55
+ type Loose<Q, K extends PropertyKey> = {
56
+ [P in keyof Q as P extends K ? never : P]: {} extends Pick<Q, P> ? Q[P] | undefined : Q[P];
57
+ };
58
+ type Widen<Q> = Loose<Q, 'protocol' | 'fields' | 'format'> & ('protocol' extends keyof Q ? {
59
+ protocol?: ProtocolKey | undefined;
50
60
  } : unknown) & ('fields' extends keyof Q ? {
51
- fields?: Fields;
61
+ fields?: Fields | undefined;
52
62
  } : unknown);
53
63
  export type PositionsListQuery = Widen<RawQuery<'positions.list'>>;
54
64
  export type PositionsBatchQuery = OmitKeys<Widen<RawQuery<'positions.batch'>>, 'ids'> & {
@@ -62,21 +72,22 @@ export type PoolsListQuery = Widen<RawQuery<'pools.list'>>;
62
72
  export type PoolDetailQuery = Widen<RawQuery<'pools.detail'>>;
63
73
  export type PoolChartsQuery = Widen<RawQuery<'pools.charts'>>;
64
74
  export type TokenQuery = Widen<RawQuery<'tokens.detail'>>;
75
+ export type TokenSearchQuery = Widen<RawQuery<'tokens.search'>>;
65
76
  export type WalletSummaryQuery = Widen<RawQuery<'wallets.summary'>>;
66
77
  export type HooksListQuery = Widen<RawQuery<'hooks.list'>>;
67
78
  /** Every property optional, all the way down. */
68
79
  export type DeepPartial<T> = T extends readonly (infer U)[] ? DeepPartial<U>[] : T extends object ? {
69
80
  [K in keyof T]?: DeepPartial<T[K]>;
70
81
  } : T;
82
+ /** True when `Q` has no key `K`, or its value can only be one of `Allowed`. */
83
+ type KeyOff<Q, K extends PropertyKey, Allowed> = K extends keyof Q ? ([Q[K]] extends [Allowed] ? true : false) : true;
71
84
  /**
72
- * True when the query asks for less than the whole row: a `fields` list, or `view: 'compact'`. The server then
73
- * sends only what was asked for, so the rows are typed `DeepPartial`.
85
+ * True unless the query provably asks for the whole row. The rows are typed `DeepPartial` whenever `fields` may be
86
+ * set or `view` may be `'compact'`, including a value only known at run time (`fields: string[] | undefined`,
87
+ * `view: 'compact' | 'full'`, a query typed as the whole `PositionsListQuery`): the server then sends only what was
88
+ * asked for. A query with no `fields` and no `view`, or with `view: 'full'`, gets full rows.
74
89
  */
75
- export type IsProjected<Q> = Q extends {
76
- fields: Fields;
77
- } ? true : Q extends {
78
- view: 'compact';
79
- } ? true : false;
90
+ export type IsProjected<Q> = KeyOff<Q, 'fields', undefined> extends true ? (KeyOff<Q, 'view', 'full' | undefined> extends true ? false : true) : true;
80
91
  type ElementOf<A> = A extends readonly (infer U)[] ? U : never;
81
92
  /** `L` with the rows under `K` made `DeepPartial` when `Q` projects them. */
82
93
  export type WithRows<L, K extends keyof L, Q> = IsProjected<Q> extends true ? OmitKeys<L, K> & {
@@ -92,8 +103,10 @@ export type RowOf<T, Q> = IsProjected<Q> extends true ? DeepPartial<T> : T;
92
103
  */
93
104
  export interface PagingOptions {
94
105
  /** Stop after this many pages. */
95
- maxPages?: number;
106
+ maxPages?: number | undefined;
96
107
  /** Stop after this many rows (`iterate*` only). */
97
- maxItems?: number;
108
+ maxItems?: number | undefined;
98
109
  }
110
+ /** Limits for `exportCsvPages`: a CSV page is counted whole, so only `maxPages` applies. */
111
+ export type CsvPagingOptions = Pick<PagingOptions, 'maxPages'>;
99
112
  export {};
@@ -1,2 +1,2 @@
1
1
  /** The package version, sent in `User-Agent`. `test/version.spec.ts` holds it to `package.json`. */
2
- export declare const VERSION = "0.1.0";
2
+ export declare const VERSION = "0.1.1";
@@ -1,2 +1,2 @@
1
1
  /** The package version, sent in `User-Agent`. `test/version.spec.ts` holds it to `package.json`. */
2
- export const VERSION = '0.1.0';
2
+ export const VERSION = '0.1.1';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tickwise/sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Typed TypeScript client for the Tickwise API: Uniswap v4 positions, pools, tokens, wallets and hooks",
5
5
  "keywords": [
6
6
  "tickwise",