torque-intelligence 0.1.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/LICENSE +21 -0
- package/README.md +84 -0
- package/dist/errors.d.ts +15 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/http.d.ts +8 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.esm.js +225 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +230 -0
- package/dist/index.js.map +1 -0
- package/dist/query.d.ts +5 -0
- package/dist/query.d.ts.map +1 -0
- package/package.json +57 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Torque
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# torque-intelligence
|
|
2
|
+
|
|
3
|
+
Official **read-only** client for Torque Intelligence (Platform API v1).
|
|
4
|
+
|
|
5
|
+
Uses the same business API key as Checkout (`sk_live_…`). No wallet JWT required.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
yarn add torque-intelligence @torquefi/types
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick start
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { createTorqueIntelligenceFromEnv } from 'torque-intelligence'
|
|
17
|
+
|
|
18
|
+
const ti = createTorqueIntelligenceFromEnv()
|
|
19
|
+
|
|
20
|
+
const feed = await ti.getFeed({
|
|
21
|
+
walletAddress: '0x…', // optional — personalization
|
|
22
|
+
chainId: 8453,
|
|
23
|
+
lanes: ['timely', 'desk'],
|
|
24
|
+
includeBrief: true,
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
const angles = await ti.getTradeAngles({ walletAddress: '0x…' })
|
|
28
|
+
const now = await ti.getHappeningNow({ chainId: 8453 })
|
|
29
|
+
|
|
30
|
+
const caps = await ti.getCapabilities()
|
|
31
|
+
ti.assertManifestCompatibility(caps.manifestVersion)
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Configuration
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { createTorqueIntelligence } from 'torque-intelligence'
|
|
38
|
+
|
|
39
|
+
const ti = createTorqueIntelligence({
|
|
40
|
+
apiKey: process.env.TORQUE_API_KEY!,
|
|
41
|
+
baseUrl: 'https://app.torque.fi', // optional
|
|
42
|
+
timeout: 30_000, // optional
|
|
43
|
+
cooldownRetries: 1, // retry once on 429 COOLDOWN
|
|
44
|
+
})
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
**Environment variables:** `TORQUE_API_KEY`, optional `TORQUE_BASE_URL`.
|
|
48
|
+
|
|
49
|
+
## Endpoints
|
|
50
|
+
|
|
51
|
+
| Method | SDK | HTTP |
|
|
52
|
+
|--------|-----|------|
|
|
53
|
+
| `getFeed` | Primary feed | `GET /api/v1/intelligence/feed` |
|
|
54
|
+
| `getTradeAngles` | Desk angles | `GET /api/v1/intelligence/trade-angles` |
|
|
55
|
+
| `getHappeningNow` | Timely signals | `GET /api/v1/intelligence/happening-now` |
|
|
56
|
+
| `getCapabilities` | Manifest probe | `GET /api/v1/capabilities` |
|
|
57
|
+
|
|
58
|
+
## Errors
|
|
59
|
+
|
|
60
|
+
v1 JSON errors map to `TorqueIntelligenceError` with `code`, `statusCode`, and optional `details`.
|
|
61
|
+
|
|
62
|
+
On **`429 COOLDOWN`**, the client waits `retryAfterMs` from `error.details` and retries up to `cooldownRetries` (default **1**).
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
import { TorqueIntelligenceError } from 'torque-intelligence'
|
|
66
|
+
|
|
67
|
+
try {
|
|
68
|
+
await ti.getFeed({ force: true })
|
|
69
|
+
} catch (e) {
|
|
70
|
+
if (e instanceof TorqueIntelligenceError && e.code === 'COOLDOWN') {
|
|
71
|
+
console.log('Retry after', e.retryAfterMs, 'ms')
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Docs
|
|
77
|
+
|
|
78
|
+
- [SDK roadmap](../../public/docs/developer/SDK_ROADMAP.md)
|
|
79
|
+
- [Intelligence integrator guide](../../public/docs/developer/INTELLIGENCE_INTEGRATOR_V7.md)
|
|
80
|
+
- [Torque API v1](../../public/docs/developer/TORQUE_API_V1.md)
|
|
81
|
+
|
|
82
|
+
## License
|
|
83
|
+
|
|
84
|
+
MIT
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface TorqueIntelligenceErrorDetails {
|
|
2
|
+
code: string;
|
|
3
|
+
statusCode: number;
|
|
4
|
+
details?: Record<string, unknown>;
|
|
5
|
+
retryAfterMs?: number;
|
|
6
|
+
}
|
|
7
|
+
export declare class TorqueIntelligenceError extends Error {
|
|
8
|
+
code: string;
|
|
9
|
+
statusCode: number;
|
|
10
|
+
details?: Record<string, unknown>;
|
|
11
|
+
retryAfterMs?: number;
|
|
12
|
+
constructor(message: string, options: TorqueIntelligenceErrorDetails);
|
|
13
|
+
}
|
|
14
|
+
export declare function parseTorqueV1ErrorBody(body: unknown, statusCode: number, fallbackMessage: string): TorqueIntelligenceError;
|
|
15
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,8BAA8B;IAC7C,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,MAAM,CAAA;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACjC,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB;AAED,qBAAa,uBAAwB,SAAQ,KAAK;IAChD,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,MAAM,CAAA;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACjC,YAAY,CAAC,EAAE,MAAM,CAAA;gBAET,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,8BAA8B;CASrE;AAED,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,OAAO,EACb,UAAU,EAAE,MAAM,EAClB,eAAe,EAAE,MAAM,GACtB,uBAAuB,CAkBzB"}
|
package/dist/http.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface TorqueIntelligenceHttpConfig {
|
|
2
|
+
apiKey: string;
|
|
3
|
+
baseUrl: string;
|
|
4
|
+
timeout: number;
|
|
5
|
+
cooldownRetries: number;
|
|
6
|
+
}
|
|
7
|
+
export declare function torqueIntelligenceGet<T>(config: TorqueIntelligenceHttpConfig, path: string, attempt?: number): Promise<T>;
|
|
8
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,4BAA4B;IAC3C,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,MAAM,CAAA;IACf,eAAe,EAAE,MAAM,CAAA;CACxB;AAMD,wBAAsB,qBAAqB,CAAC,CAAC,EAC3C,MAAM,EAAE,4BAA4B,EACpC,IAAI,EAAE,MAAM,EACZ,OAAO,SAAI,GACV,OAAO,CAAC,CAAC,CAAC,CAgEZ"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { GetHappeningNowParams, GetIntelligenceFeedParams, GetTradeAnglesParams, HappeningNowResponseV1, IntelligenceFeedResponseV1, TradeAnglesResponseV1 } from '@torquefi/types/intelligence';
|
|
2
|
+
import type { TorqueCapabilitiesProbe, TorquePlatformClientConfig } from '@torquefi/types/platform';
|
|
3
|
+
import { TorqueIntelligenceError } from './errors';
|
|
4
|
+
export interface TorqueIntelligenceOptions extends TorquePlatformClientConfig {
|
|
5
|
+
/** Automatic retries after 429 COOLDOWN (default 1). */
|
|
6
|
+
cooldownRetries?: number;
|
|
7
|
+
}
|
|
8
|
+
export type { TorquePlatformClientConfig as TorqueIntelligenceConfig } from '@torquefi/types/platform';
|
|
9
|
+
export { TorqueIntelligenceError };
|
|
10
|
+
export type { GetHappeningNowParams, GetIntelligenceFeedParams, GetTradeAnglesParams, HappeningNowResponseV1, IntelligenceFeedResponseV1, IntelligenceItemV1, TradeAnglesResponseV1, } from '@torquefi/types/intelligence';
|
|
11
|
+
export declare class TorqueIntelligence {
|
|
12
|
+
private readonly http;
|
|
13
|
+
constructor(config: TorqueIntelligenceOptions);
|
|
14
|
+
/**
|
|
15
|
+
* Primary integrator feed — normalized IntelligenceItemV1[], lanes, optional brief.
|
|
16
|
+
* GET /api/v1/intelligence/feed
|
|
17
|
+
*/
|
|
18
|
+
getFeed(params?: GetIntelligenceFeedParams): Promise<IntelligenceFeedResponseV1>;
|
|
19
|
+
/** Ranked trade angles (desk lane). GET /api/v1/intelligence/trade-angles */
|
|
20
|
+
getTradeAngles(params?: GetTradeAnglesParams): Promise<TradeAnglesResponseV1>;
|
|
21
|
+
/** Timely macro/crypto signals. GET /api/v1/intelligence/happening-now */
|
|
22
|
+
getHappeningNow(params?: GetHappeningNowParams): Promise<HappeningNowResponseV1>;
|
|
23
|
+
/** Capability manifest probe. GET /api/v1/capabilities */
|
|
24
|
+
getCapabilities(): Promise<TorqueCapabilitiesProbe>;
|
|
25
|
+
/**
|
|
26
|
+
* Throws if the server manifest is older than the SDK's expected Intelligence schema version.
|
|
27
|
+
*/
|
|
28
|
+
assertManifestCompatibility(manifestVersion: number): void;
|
|
29
|
+
}
|
|
30
|
+
export declare function createTorqueIntelligence(config: TorqueIntelligenceOptions): TorqueIntelligence;
|
|
31
|
+
/**
|
|
32
|
+
* Reads TORQUE_API_KEY and optional TORQUE_BASE_URL from the environment.
|
|
33
|
+
*/
|
|
34
|
+
export declare function createTorqueIntelligenceFromEnv(overrides?: Partial<TorqueIntelligenceOptions>): TorqueIntelligence;
|
|
35
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EACrB,yBAAyB,EACzB,oBAAoB,EACpB,sBAAsB,EACtB,0BAA0B,EAC1B,qBAAqB,EACtB,MAAM,8BAA8B,CAAA;AACrC,OAAO,KAAK,EAAE,uBAAuB,EAAE,0BAA0B,EAAE,MA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{
|
|
4
|
+
constructor(message, options) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = 'TorqueIntelligenceError';
|
|
7
|
+
this.code = options.code;
|
|
8
|
+
this.statusCode = options.statusCode;
|
|
9
|
+
this.details = options.details;
|
|
10
|
+
this.retryAfterMs = options.retryAfterMs;
|
|
11
|
+
Object.setPrototypeOf(this, TorqueIntelligenceError.prototype);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function parseTorqueV1ErrorBody(body, statusCode, fallbackMessage) {
|
|
15
|
+
const envelope = body;
|
|
16
|
+
const err = envelope?.error;
|
|
17
|
+
const code = typeof err?.code === 'string' ? err.code : 'API_ERROR';
|
|
18
|
+
const message = typeof err?.message === 'string' ? err.message : fallbackMessage;
|
|
19
|
+
const details = err?.details;
|
|
20
|
+
const retryAfterRaw = details?.retryAfterMs;
|
|
21
|
+
const retryAfterMs = code === 'COOLDOWN' && typeof retryAfterRaw === 'number' && Number.isFinite(retryAfterRaw)
|
|
22
|
+
? retryAfterRaw
|
|
23
|
+
: undefined;
|
|
24
|
+
return new TorqueIntelligenceError(message, {
|
|
25
|
+
code,
|
|
26
|
+
statusCode,
|
|
27
|
+
details,
|
|
28
|
+
retryAfterMs,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function sleep(ms) {
|
|
33
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
34
|
+
}
|
|
35
|
+
async function torqueIntelligenceGet(config, path, attempt = 0) {
|
|
36
|
+
const url = `${config.baseUrl}${path}`;
|
|
37
|
+
const controller = new AbortController();
|
|
38
|
+
const timeoutId = setTimeout(() => controller.abort(), config.timeout);
|
|
39
|
+
try {
|
|
40
|
+
const response = await fetch(url, {
|
|
41
|
+
method: 'GET',
|
|
42
|
+
headers: {
|
|
43
|
+
Accept: 'application/json',
|
|
44
|
+
Authorization: `Bearer ${config.apiKey}`,
|
|
45
|
+
},
|
|
46
|
+
signal: controller.signal,
|
|
47
|
+
});
|
|
48
|
+
clearTimeout(timeoutId);
|
|
49
|
+
const body = await response.json().catch(() => ({}));
|
|
50
|
+
if (!response.ok) {
|
|
51
|
+
const error = parseTorqueV1ErrorBody(body, response.status, `HTTP ${response.status}: ${response.statusText}`);
|
|
52
|
+
if (error.code === 'COOLDOWN' &&
|
|
53
|
+
error.retryAfterMs != null &&
|
|
54
|
+
attempt < config.cooldownRetries) {
|
|
55
|
+
await sleep(error.retryAfterMs);
|
|
56
|
+
return torqueIntelligenceGet(config, path, attempt + 1);
|
|
57
|
+
}
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
60
|
+
return body;
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
clearTimeout(timeoutId);
|
|
64
|
+
if (error instanceof TorqueIntelligenceError) {
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
if (error instanceof Error) {
|
|
68
|
+
if (error.name === 'AbortError') {
|
|
69
|
+
throw new TorqueIntelligenceError('Request timeout', {
|
|
70
|
+
code: 'TIMEOUT',
|
|
71
|
+
statusCode: 408,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
throw new TorqueIntelligenceError(error.message, {
|
|
75
|
+
code: 'NETWORK_ERROR',
|
|
76
|
+
statusCode: 500,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
throw new TorqueIntelligenceError('Request failed', {
|
|
80
|
+
code: 'UNKNOWN_ERROR',
|
|
81
|
+
statusCode: 500,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function appendCsv(params, key, values) {
|
|
87
|
+
if (values?.length) {
|
|
88
|
+
params.set(key, values.join(','));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function buildFeedQuery(params = {}) {
|
|
92
|
+
const sp = new URLSearchParams();
|
|
93
|
+
if (params.walletAddress?.trim()) {
|
|
94
|
+
sp.set('walletAddress', params.walletAddress.trim());
|
|
95
|
+
}
|
|
96
|
+
if (params.chainId != null && Number.isFinite(params.chainId)) {
|
|
97
|
+
sp.set('chainId', String(params.chainId));
|
|
98
|
+
}
|
|
99
|
+
appendCsv(sp, 'lanes', params.lanes);
|
|
100
|
+
appendCsv(sp, 'kinds', params.kinds);
|
|
101
|
+
if (params.limit != null && Number.isFinite(params.limit)) {
|
|
102
|
+
sp.set('limit', String(params.limit));
|
|
103
|
+
}
|
|
104
|
+
if (params.includeBrief) {
|
|
105
|
+
sp.set('includeBrief', '1');
|
|
106
|
+
}
|
|
107
|
+
if (params.force) {
|
|
108
|
+
sp.set('force', '1');
|
|
109
|
+
}
|
|
110
|
+
const qs = sp.toString();
|
|
111
|
+
return qs ? `?${qs}` : '';
|
|
112
|
+
}
|
|
113
|
+
function buildTradeAnglesQuery(params = {}) {
|
|
114
|
+
const sp = new URLSearchParams();
|
|
115
|
+
if (params.walletAddress?.trim()) {
|
|
116
|
+
sp.set('walletAddress', params.walletAddress.trim());
|
|
117
|
+
}
|
|
118
|
+
if (params.force) {
|
|
119
|
+
sp.set('force', '1');
|
|
120
|
+
}
|
|
121
|
+
const qs = sp.toString();
|
|
122
|
+
return qs ? `?${qs}` : '';
|
|
123
|
+
}
|
|
124
|
+
function buildHappeningNowQuery(params = {}) {
|
|
125
|
+
const sp = new URLSearchParams();
|
|
126
|
+
if (params.chainId != null && Number.isFinite(params.chainId)) {
|
|
127
|
+
sp.set('chainId', String(params.chainId));
|
|
128
|
+
}
|
|
129
|
+
const qs = sp.toString();
|
|
130
|
+
return qs ? `?${qs}` : '';
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function validateConfig(config) {
|
|
134
|
+
if (!config.apiKey?.trim()) {
|
|
135
|
+
throw new TorqueIntelligenceError('API key is required', {
|
|
136
|
+
code: 'INVALID_CONFIG',
|
|
137
|
+
statusCode: 400,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
if (config.timeout != null && (typeof config.timeout !== 'number' || config.timeout <= 0)) {
|
|
141
|
+
throw new TorqueIntelligenceError('Timeout must be a positive number', {
|
|
142
|
+
code: 'INVALID_CONFIG',
|
|
143
|
+
statusCode: 400,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
if (config.cooldownRetries != null &&
|
|
147
|
+
(typeof config.cooldownRetries !== 'number' || config.cooldownRetries < 0)) {
|
|
148
|
+
throw new TorqueIntelligenceError('cooldownRetries must be a non-negative number', {
|
|
149
|
+
code: 'INVALID_CONFIG',
|
|
150
|
+
statusCode: 400,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
function toHttpConfig(config) {
|
|
155
|
+
return {
|
|
156
|
+
apiKey: config.apiKey.trim(),
|
|
157
|
+
baseUrl: (config.baseUrl || 'https://app.torque.fi').replace(/\/$/, ''),
|
|
158
|
+
timeout: config.timeout ?? 30000,
|
|
159
|
+
cooldownRetries: config.cooldownRetries ?? 1,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
class TorqueIntelligence {
|
|
163
|
+
constructor(config) {
|
|
164
|
+
validateConfig(config);
|
|
165
|
+
this.http = toHttpConfig(config);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Primary integrator feed — normalized IntelligenceItemV1[], lanes, optional brief.
|
|
169
|
+
* GET /api/v1/intelligence/feed
|
|
170
|
+
*/
|
|
171
|
+
async getFeed(params) {
|
|
172
|
+
return torqueIntelligenceGet(this.http, `/api/v1/intelligence/feed${buildFeedQuery(params)}`);
|
|
173
|
+
}
|
|
174
|
+
/** Ranked trade angles (desk lane). GET /api/v1/intelligence/trade-angles */
|
|
175
|
+
async getTradeAngles(params) {
|
|
176
|
+
return torqueIntelligenceGet(this.http, `/api/v1/intelligence/trade-angles${buildTradeAnglesQuery(params)}`);
|
|
177
|
+
}
|
|
178
|
+
/** Timely macro/crypto signals. GET /api/v1/intelligence/happening-now */
|
|
179
|
+
async getHappeningNow(params) {
|
|
180
|
+
return torqueIntelligenceGet(this.http, `/api/v1/intelligence/happening-now${buildHappeningNowQuery(params)}`);
|
|
181
|
+
}
|
|
182
|
+
/** Capability manifest probe. GET /api/v1/capabilities */
|
|
183
|
+
async getCapabilities() {
|
|
184
|
+
return torqueIntelligenceGet(this.http, '/api/v1/capabilities');
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Throws if the server manifest is older than the SDK's expected Intelligence schema version.
|
|
188
|
+
*/
|
|
189
|
+
assertManifestCompatibility(manifestVersion) {
|
|
190
|
+
if (manifestVersion < INTELLIGENCE_MANIFEST_VERSION) {
|
|
191
|
+
throw new TorqueIntelligenceError(`Server manifest v${manifestVersion} is older than client expectation v${INTELLIGENCE_MANIFEST_VERSION}`, {
|
|
192
|
+
code: 'MANIFEST_MISMATCH',
|
|
193
|
+
statusCode: 400,
|
|
194
|
+
details: {
|
|
195
|
+
serverVersion: manifestVersion,
|
|
196
|
+
clientVersion: INTELLIGENCE_MANIFEST_VERSION,
|
|
197
|
+
},
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
function createTorqueIntelligence(config) {
|
|
203
|
+
return new TorqueIntelligence(config);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Reads TORQUE_API_KEY and optional TORQUE_BASE_URL from the environment.
|
|
207
|
+
*/
|
|
208
|
+
function createTorqueIntelligenceFromEnv(overrides) {
|
|
209
|
+
const apiKey = process.env.TORQUE_API_KEY || overrides?.apiKey;
|
|
210
|
+
if (!apiKey) {
|
|
211
|
+
throw new TorqueIntelligenceError('TORQUE_API_KEY environment variable is required', {
|
|
212
|
+
code: 'MISSING_ENV_VARS',
|
|
213
|
+
statusCode: 400,
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
return new TorqueIntelligence({
|
|
217
|
+
apiKey,
|
|
218
|
+
baseUrl: process.env.TORQUE_BASE_URL || overrides?.baseUrl,
|
|
219
|
+
timeout: overrides?.timeout,
|
|
220
|
+
cooldownRetries: overrides?.cooldownRetries,
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export { TorqueIntelligence, TorqueIntelligenceError, createTorqueIntelligence, createTorqueIntelligenceFromEnv };
|
|
225
|
+
//# sourceMappingURL=index.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["../src/errors.ts","../src/http.ts","../src/query.ts","../src/index.ts"],"sourcesContent":["export interface TorqueIntelligenceErrorDetails {\n code: string\n statusCode: number\n details?: Record<string, unknown>\n retryAfterMs?: number\n}\n\nexport class TorqueIntelligenceError extends Error {\n code: string\n statusCode: number\n details?: Record<string, unknown>\n retryAfterMs?: number\n\n constructor(message: string, options: TorqueIntelligenceErrorDetails) {\n super(message)\n this.name = 'TorqueIntelligenceError'\n this.code = options.code\n this.statusCode = options.statusCode\n this.details = options.details\n this.retryAfterMs = options.retryAfterMs\n Object.setPrototypeOf(this, TorqueIntelligenceError.prototype)\n }\n}\n\nexport function parseTorqueV1ErrorBody(\n body: unknown,\n statusCode: number,\n fallbackMessage: string,\n): TorqueIntelligenceError {\n const envelope = body as { error?: { code?: string; message?: string; details?: Record<string, unknown> } } | null\n const err = envelope?.error\n const code = typeof err?.code === 'string' ? err.code : 'API_ERROR'\n const message = typeof err?.message === 'string' ? err.message : fallbackMessage\n const details = err?.details\n const retryAfterRaw = details?.retryAfterMs\n const retryAfterMs =\n code === 'COOLDOWN' && typeof retryAfterRaw === 'number' && Number.isFinite(retryAfterRaw)\n ? retryAfterRaw\n : undefined\n\n return new TorqueIntelligenceError(message, {\n code,\n statusCode,\n details,\n retryAfterMs,\n })\n}\n","import { parseTorqueV1ErrorBody, TorqueIntelligenceError } from './errors'\n\nexport interface TorqueIntelligenceHttpConfig {\n apiKey: string\n baseUrl: string\n timeout: number\n cooldownRetries: number\n}\n\nfunction sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms))\n}\n\nexport async function torqueIntelligenceGet<T>(\n config: TorqueIntelligenceHttpConfig,\n path: string,\n attempt = 0,\n): Promise<T> {\n const url = `${config.baseUrl}${path}`\n const controller = new AbortController()\n const timeoutId = setTimeout(() => controller.abort(), config.timeout)\n\n try {\n const response = await fetch(url, {\n method: 'GET',\n headers: {\n Accept: 'application/json',\n Authorization: `Bearer ${config.apiKey}`,\n },\n signal: controller.signal,\n })\n\n clearTimeout(timeoutId)\n\n const body: unknown = await response.json().catch(() => ({}))\n\n if (!response.ok) {\n const error = parseTorqueV1ErrorBody(\n body,\n response.status,\n `HTTP ${response.status}: ${response.statusText}`,\n )\n\n if (\n error.code === 'COOLDOWN' &&\n error.retryAfterMs != null &&\n attempt < config.cooldownRetries\n ) {\n await sleep(error.retryAfterMs)\n return torqueIntelligenceGet<T>(config, path, attempt + 1)\n }\n\n throw error\n }\n\n return body as T\n } catch (error) {\n clearTimeout(timeoutId)\n\n if (error instanceof TorqueIntelligenceError) {\n throw error\n }\n\n if (error instanceof Error) {\n if (error.name === 'AbortError') {\n throw new TorqueIntelligenceError('Request timeout', {\n code: 'TIMEOUT',\n statusCode: 408,\n })\n }\n throw new TorqueIntelligenceError(error.message, {\n code: 'NETWORK_ERROR',\n statusCode: 500,\n })\n }\n\n throw new TorqueIntelligenceError('Request failed', {\n code: 'UNKNOWN_ERROR',\n statusCode: 500,\n })\n }\n}\n","import type {\n GetHappeningNowParams,\n GetIntelligenceFeedParams,\n GetTradeAnglesParams,\n IntelligenceItemKind,\n IntelligenceLaneId,\n} from '@torquefi/types/intelligence'\n\nfunction appendCsv(\n params: URLSearchParams,\n key: string,\n values: readonly string[] | undefined,\n): void {\n if (values?.length) {\n params.set(key, values.join(','))\n }\n}\n\nexport function buildFeedQuery(params: GetIntelligenceFeedParams = {}): string {\n const sp = new URLSearchParams()\n\n if (params.walletAddress?.trim()) {\n sp.set('walletAddress', params.walletAddress.trim())\n }\n if (params.chainId != null && Number.isFinite(params.chainId)) {\n sp.set('chainId', String(params.chainId))\n }\n appendCsv(sp, 'lanes', params.lanes as IntelligenceLaneId[] | undefined)\n appendCsv(sp, 'kinds', params.kinds as IntelligenceItemKind[] | undefined)\n if (params.limit != null && Number.isFinite(params.limit)) {\n sp.set('limit', String(params.limit))\n }\n if (params.includeBrief) {\n sp.set('includeBrief', '1')\n }\n if (params.force) {\n sp.set('force', '1')\n }\n\n const qs = sp.toString()\n return qs ? `?${qs}` : ''\n}\n\nexport function buildTradeAnglesQuery(params: GetTradeAnglesParams = {}): string {\n const sp = new URLSearchParams()\n\n if (params.walletAddress?.trim()) {\n sp.set('walletAddress', params.walletAddress.trim())\n }\n if (params.force) {\n sp.set('force', '1')\n }\n\n const qs = sp.toString()\n return qs ? `?${qs}` : ''\n}\n\nexport function buildHappeningNowQuery(params: GetHappeningNowParams = {}): string {\n const sp = new URLSearchParams()\n\n if (params.chainId != null && Number.isFinite(params.chainId)) {\n sp.set('chainId', String(params.chainId))\n }\n\n const qs = sp.toString()\n return qs ? `?${qs}` : ''\n}\n","import type {\n GetHappeningNowParams,\n GetIntelligenceFeedParams,\n GetTradeAnglesParams,\n HappeningNowResponseV1,\n IntelligenceFeedResponseV1,\n TradeAnglesResponseV1,\n} from '@torquefi/types/intelligence'\nimport type { TorqueCapabilitiesProbe, TorquePlatformClientConfig } from '@torquefi/types/platform'\nimport { INTELLIGENCE_MANIFEST_VERSION } from '@torquefi/types/intelligence'\n\nimport { TorqueIntelligenceError } from './errors'\nimport { torqueIntelligenceGet, type TorqueIntelligenceHttpConfig } from './http'\nimport {\n buildFeedQuery,\n buildHappeningNowQuery,\n buildTradeAnglesQuery,\n} from './query'\n\nexport interface TorqueIntelligenceOptions extends TorquePlatformClientConfig {\n /** Automatic retries after 429 COOLDOWN (default 1). */\n cooldownRetries?: number\n}\n\nexport type { TorquePlatformClientConfig as TorqueIntelligenceConfig } from '@torquefi/types/platform'\n\nexport { TorqueIntelligenceError }\nexport type {\n GetHappeningNowParams,\n GetIntelligenceFeedParams,\n GetTradeAnglesParams,\n HappeningNowResponseV1,\n IntelligenceFeedResponseV1,\n IntelligenceItemV1,\n TradeAnglesResponseV1,\n} from '@torquefi/types/intelligence'\n\nfunction validateConfig(config: TorqueIntelligenceOptions): void {\n if (!config.apiKey?.trim()) {\n throw new TorqueIntelligenceError('API key is required', {\n code: 'INVALID_CONFIG',\n statusCode: 400,\n })\n }\n if (config.timeout != null && (typeof config.timeout !== 'number' || config.timeout <= 0)) {\n throw new TorqueIntelligenceError('Timeout must be a positive number', {\n code: 'INVALID_CONFIG',\n statusCode: 400,\n })\n }\n if (\n config.cooldownRetries != null &&\n (typeof config.cooldownRetries !== 'number' || config.cooldownRetries < 0)\n ) {\n throw new TorqueIntelligenceError('cooldownRetries must be a non-negative number', {\n code: 'INVALID_CONFIG',\n statusCode: 400,\n })\n }\n}\n\nfunction toHttpConfig(config: TorqueIntelligenceOptions): TorqueIntelligenceHttpConfig {\n return {\n apiKey: config.apiKey.trim(),\n baseUrl: (config.baseUrl || 'https://app.torque.fi').replace(/\\/$/, ''),\n timeout: config.timeout ?? 30_000,\n cooldownRetries: config.cooldownRetries ?? 1,\n }\n}\n\nexport class TorqueIntelligence {\n private readonly http: TorqueIntelligenceHttpConfig\n\n constructor(config: TorqueIntelligenceOptions) {\n validateConfig(config)\n this.http = toHttpConfig(config)\n }\n\n /**\n * Primary integrator feed — normalized IntelligenceItemV1[], lanes, optional brief.\n * GET /api/v1/intelligence/feed\n */\n async getFeed(params?: GetIntelligenceFeedParams): Promise<IntelligenceFeedResponseV1> {\n return torqueIntelligenceGet<IntelligenceFeedResponseV1>(\n this.http,\n `/api/v1/intelligence/feed${buildFeedQuery(params)}`,\n )\n }\n\n /** Ranked trade angles (desk lane). GET /api/v1/intelligence/trade-angles */\n async getTradeAngles(params?: GetTradeAnglesParams): Promise<TradeAnglesResponseV1> {\n return torqueIntelligenceGet<TradeAnglesResponseV1>(\n this.http,\n `/api/v1/intelligence/trade-angles${buildTradeAnglesQuery(params)}`,\n )\n }\n\n /** Timely macro/crypto signals. GET /api/v1/intelligence/happening-now */\n async getHappeningNow(params?: GetHappeningNowParams): Promise<HappeningNowResponseV1> {\n return torqueIntelligenceGet<HappeningNowResponseV1>(\n this.http,\n `/api/v1/intelligence/happening-now${buildHappeningNowQuery(params)}`,\n )\n }\n\n /** Capability manifest probe. GET /api/v1/capabilities */\n async getCapabilities(): Promise<TorqueCapabilitiesProbe> {\n return torqueIntelligenceGet<TorqueCapabilitiesProbe>(this.http, '/api/v1/capabilities')\n }\n\n /**\n * Throws if the server manifest is older than the SDK's expected Intelligence schema version.\n */\n assertManifestCompatibility(manifestVersion: number): void {\n if (manifestVersion < INTELLIGENCE_MANIFEST_VERSION) {\n throw new TorqueIntelligenceError(\n `Server manifest v${manifestVersion} is older than client expectation v${INTELLIGENCE_MANIFEST_VERSION}`,\n {\n code: 'MANIFEST_MISMATCH',\n statusCode: 400,\n details: {\n serverVersion: manifestVersion,\n clientVersion: INTELLIGENCE_MANIFEST_VERSION,\n },\n },\n )\n }\n }\n}\n\nexport function createTorqueIntelligence(config: TorqueIntelligenceOptions): TorqueIntelligence {\n return new TorqueIntelligence(config)\n}\n\n/**\n * Reads TORQUE_API_KEY and optional TORQUE_BASE_URL from the environment.\n */\nexport function createTorqueIntelligenceFromEnv(\n overrides?: Partial<TorqueIntelligenceOptions>,\n): TorqueIntelligence {\n const apiKey = process.env.TORQUE_API_KEY || overrides?.apiKey\n if (!apiKey) {\n throw new TorqueIntelligenceError('TORQUE_API_KEY environment variable is required', {\n code: 'MISSING_ENV_VARS',\n statusCode: 400,\n })\n }\n\n return new TorqueIntelligence({\n apiKey,\n baseUrl: process.env.TORQUE_BASE_URL || overrides?.baseUrl,\n timeout: overrides?.timeout,\n cooldownRetries: overrides?.cooldownRetries,\n })\n}\n"],"names":[],"mappings":";;AAOM,MAAO,uBAAwB,SAAQ,KAAK,CAAA;IAMhD,WAAA,CAAY,OAAe,EAAE,OAAuC,EAAA;QAClE,KAAK,CAAC,OAAO,CAAC;AACd,QAAA,IAAI,CAAC,IAAI,GAAG,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AA6B,EAAE;YACnD,MAAM,IAAI,uBAAuB,CAC/B,CAAA,iBAAA,EAAoB,eAAe,CAAA,mCAAA,EAAsC,6BAA6B,EAAE,EACxG;AACE,gBAAA,IAAI,EAAE,mBAAmB;AACzB,gBAAA,UAAU,EAAE,GAAG;AACf,gBAAA,OAAO,EAAE;AACP,oBAAA,aAAa,EAAE,eAAe;AAC9B,oBAAA,aAAa,EAAE,6BAA6B;AAC7C,iBAAA;AACF,aAAA,CACF;QACH;IACF;AACD;AAEK,SAAU,wBAAwB,CAAC,MAAiC,EAAA;AACxE,IAAA,OAAO,IAAI,kBAAkB,CAAC,MAAM,CAAC;AACvC;AAEA;;AAEG;AACG,SAAU,+BAA+B,CAC7C,SAA8C,EAAA;IAE9C,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,SAAS,EAAE,MAAM;IAC9D,IAAI,CAAC,MAAM,EAAE;AACX,QAAA,MAAM,IAAI,uBAAuB,CAAC,iDAAiD,EAAE;AACnF,YAAA,IAAI,EAAE,kBAAkB;AACxB,YAAA,UAAU,EAAE,GAAG;AAChB,SAAA,CAAC;IACJ;IAEA,OAAO,IAAI,kBAAkB,CAAC;QAC5B,MAAM;QACN,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,SAAS,EAAE,OAAO;QAC1D,OAAO,EAAE,SAAS,EAAE,OAAO;QAC3B,eAAe,EAAE,SAAS,EAAE,eAAe;AAC5C,KAAA,CAAC;AACJ;;;;"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var intelligence = require('@torquefi/types/intelligence');
|
|
4
|
+
|
|
5
|
+
class TorqueIntelligenceError extends Error {
|
|
6
|
+
constructor(message, options) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = 'TorqueIntelligenceError';
|
|
9
|
+
this.code = options.code;
|
|
10
|
+
this.statusCode = options.statusCode;
|
|
11
|
+
this.details = options.details;
|
|
12
|
+
this.retryAfterMs = options.retryAfterMs;
|
|
13
|
+
Object.setPrototypeOf(this, TorqueIntelligenceError.prototype);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function parseTorqueV1ErrorBody(body, statusCode, fallbackMessage) {
|
|
17
|
+
const envelope = body;
|
|
18
|
+
const err = envelope?.error;
|
|
19
|
+
const code = typeof err?.code === 'string' ? err.code : 'API_ERROR';
|
|
20
|
+
const message = typeof err?.message === 'string' ? err.message : fallbackMessage;
|
|
21
|
+
const details = err?.details;
|
|
22
|
+
const retryAfterRaw = details?.retryAfterMs;
|
|
23
|
+
const retryAfterMs = code === 'COOLDOWN' && typeof retryAfterRaw === 'number' && Number.isFinite(retryAfterRaw)
|
|
24
|
+
? retryAfterRaw
|
|
25
|
+
: undefined;
|
|
26
|
+
return new TorqueIntelligenceError(message, {
|
|
27
|
+
code,
|
|
28
|
+
statusCode,
|
|
29
|
+
details,
|
|
30
|
+
retryAfterMs,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function sleep(ms) {
|
|
35
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
36
|
+
}
|
|
37
|
+
async function torqueIntelligenceGet(config, path, attempt = 0) {
|
|
38
|
+
const url = `${config.baseUrl}${path}`;
|
|
39
|
+
const controller = new AbortController();
|
|
40
|
+
const timeoutId = setTimeout(() => controller.abort(), config.timeout);
|
|
41
|
+
try {
|
|
42
|
+
const response = await fetch(url, {
|
|
43
|
+
method: 'GET',
|
|
44
|
+
headers: {
|
|
45
|
+
Accept: 'application/json',
|
|
46
|
+
Authorization: `Bearer ${config.apiKey}`,
|
|
47
|
+
},
|
|
48
|
+
signal: controller.signal,
|
|
49
|
+
});
|
|
50
|
+
clearTimeout(timeoutId);
|
|
51
|
+
const body = await response.json().catch(() => ({}));
|
|
52
|
+
if (!response.ok) {
|
|
53
|
+
const error = parseTorqueV1ErrorBody(body, response.status, `HTTP ${response.status}: ${response.statusText}`);
|
|
54
|
+
if (error.code === 'COOLDOWN' &&
|
|
55
|
+
error.retryAfterMs != null &&
|
|
56
|
+
attempt < config.cooldownRetries) {
|
|
57
|
+
await sleep(error.retryAfterMs);
|
|
58
|
+
return torqueIntelligenceGet(config, path, attempt + 1);
|
|
59
|
+
}
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
return body;
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
clearTimeout(timeoutId);
|
|
66
|
+
if (error instanceof TorqueIntelligenceError) {
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
if (error instanceof Error) {
|
|
70
|
+
if (error.name === 'AbortError') {
|
|
71
|
+
throw new TorqueIntelligenceError('Request timeout', {
|
|
72
|
+
code: 'TIMEOUT',
|
|
73
|
+
statusCode: 408,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
throw new TorqueIntelligenceError(error.message, {
|
|
77
|
+
code: 'NETWORK_ERROR',
|
|
78
|
+
statusCode: 500,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
throw new TorqueIntelligenceError('Request failed', {
|
|
82
|
+
code: 'UNKNOWN_ERROR',
|
|
83
|
+
statusCode: 500,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function appendCsv(params, key, values) {
|
|
89
|
+
if (values?.length) {
|
|
90
|
+
params.set(key, values.join(','));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function buildFeedQuery(params = {}) {
|
|
94
|
+
const sp = new URLSearchParams();
|
|
95
|
+
if (params.walletAddress?.trim()) {
|
|
96
|
+
sp.set('walletAddress', params.walletAddress.trim());
|
|
97
|
+
}
|
|
98
|
+
if (params.chainId != null && Number.isFinite(params.chainId)) {
|
|
99
|
+
sp.set('chainId', String(params.chainId));
|
|
100
|
+
}
|
|
101
|
+
appendCsv(sp, 'lanes', params.lanes);
|
|
102
|
+
appendCsv(sp, 'kinds', params.kinds);
|
|
103
|
+
if (params.limit != null && Number.isFinite(params.limit)) {
|
|
104
|
+
sp.set('limit', String(params.limit));
|
|
105
|
+
}
|
|
106
|
+
if (params.includeBrief) {
|
|
107
|
+
sp.set('includeBrief', '1');
|
|
108
|
+
}
|
|
109
|
+
if (params.force) {
|
|
110
|
+
sp.set('force', '1');
|
|
111
|
+
}
|
|
112
|
+
const qs = sp.toString();
|
|
113
|
+
return qs ? `?${qs}` : '';
|
|
114
|
+
}
|
|
115
|
+
function buildTradeAnglesQuery(params = {}) {
|
|
116
|
+
const sp = new URLSearchParams();
|
|
117
|
+
if (params.walletAddress?.trim()) {
|
|
118
|
+
sp.set('walletAddress', params.walletAddress.trim());
|
|
119
|
+
}
|
|
120
|
+
if (params.force) {
|
|
121
|
+
sp.set('force', '1');
|
|
122
|
+
}
|
|
123
|
+
const qs = sp.toString();
|
|
124
|
+
return qs ? `?${qs}` : '';
|
|
125
|
+
}
|
|
126
|
+
function buildHappeningNowQuery(params = {}) {
|
|
127
|
+
const sp = new URLSearchParams();
|
|
128
|
+
if (params.chainId != null && Number.isFinite(params.chainId)) {
|
|
129
|
+
sp.set('chainId', String(params.chainId));
|
|
130
|
+
}
|
|
131
|
+
const qs = sp.toString();
|
|
132
|
+
return qs ? `?${qs}` : '';
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function validateConfig(config) {
|
|
136
|
+
if (!config.apiKey?.trim()) {
|
|
137
|
+
throw new TorqueIntelligenceError('API key is required', {
|
|
138
|
+
code: 'INVALID_CONFIG',
|
|
139
|
+
statusCode: 400,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
if (config.timeout != null && (typeof config.timeout !== 'number' || config.timeout <= 0)) {
|
|
143
|
+
throw new TorqueIntelligenceError('Timeout must be a positive number', {
|
|
144
|
+
code: 'INVALID_CONFIG',
|
|
145
|
+
statusCode: 400,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
if (config.cooldownRetries != null &&
|
|
149
|
+
(typeof config.cooldownRetries !== 'number' || config.cooldownRetries < 0)) {
|
|
150
|
+
throw new TorqueIntelligenceError('cooldownRetries must be a non-negative number', {
|
|
151
|
+
code: 'INVALID_CONFIG',
|
|
152
|
+
statusCode: 400,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function toHttpConfig(config) {
|
|
157
|
+
return {
|
|
158
|
+
apiKey: config.apiKey.trim(),
|
|
159
|
+
baseUrl: (config.baseUrl || 'https://app.torque.fi').replace(/\/$/, ''),
|
|
160
|
+
timeout: config.timeout ?? 30000,
|
|
161
|
+
cooldownRetries: config.cooldownRetries ?? 1,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
class TorqueIntelligence {
|
|
165
|
+
constructor(config) {
|
|
166
|
+
validateConfig(config);
|
|
167
|
+
this.http = toHttpConfig(config);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Primary integrator feed — normalized IntelligenceItemV1[], lanes, optional brief.
|
|
171
|
+
* GET /api/v1/intelligence/feed
|
|
172
|
+
*/
|
|
173
|
+
async getFeed(params) {
|
|
174
|
+
return torqueIntelligenceGet(this.http, `/api/v1/intelligence/feed${buildFeedQuery(params)}`);
|
|
175
|
+
}
|
|
176
|
+
/** Ranked trade angles (desk lane). GET /api/v1/intelligence/trade-angles */
|
|
177
|
+
async getTradeAngles(params) {
|
|
178
|
+
return torqueIntelligenceGet(this.http, `/api/v1/intelligence/trade-angles${buildTradeAnglesQuery(params)}`);
|
|
179
|
+
}
|
|
180
|
+
/** Timely macro/crypto signals. GET /api/v1/intelligence/happening-now */
|
|
181
|
+
async getHappeningNow(params) {
|
|
182
|
+
return torqueIntelligenceGet(this.http, `/api/v1/intelligence/happening-now${buildHappeningNowQuery(params)}`);
|
|
183
|
+
}
|
|
184
|
+
/** Capability manifest probe. GET /api/v1/capabilities */
|
|
185
|
+
async getCapabilities() {
|
|
186
|
+
return torqueIntelligenceGet(this.http, '/api/v1/capabilities');
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Throws if the server manifest is older than the SDK's expected Intelligence schema version.
|
|
190
|
+
*/
|
|
191
|
+
assertManifestCompatibility(manifestVersion) {
|
|
192
|
+
if (manifestVersion < intelligence.INTELLIGENCE_MANIFEST_VERSION) {
|
|
193
|
+
throw new TorqueIntelligenceError(`Server manifest v${manifestVersion} is older than client expectation v${intelligence.INTELLIGENCE_MANIFEST_VERSION}`, {
|
|
194
|
+
code: 'MANIFEST_MISMATCH',
|
|
195
|
+
statusCode: 400,
|
|
196
|
+
details: {
|
|
197
|
+
serverVersion: manifestVersion,
|
|
198
|
+
clientVersion: intelligence.INTELLIGENCE_MANIFEST_VERSION,
|
|
199
|
+
},
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
function createTorqueIntelligence(config) {
|
|
205
|
+
return new TorqueIntelligence(config);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Reads TORQUE_API_KEY and optional TORQUE_BASE_URL from the environment.
|
|
209
|
+
*/
|
|
210
|
+
function createTorqueIntelligenceFromEnv(overrides) {
|
|
211
|
+
const apiKey = process.env.TORQUE_API_KEY || overrides?.apiKey;
|
|
212
|
+
if (!apiKey) {
|
|
213
|
+
throw new TorqueIntelligenceError('TORQUE_API_KEY environment variable is required', {
|
|
214
|
+
code: 'MISSING_ENV_VARS',
|
|
215
|
+
statusCode: 400,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
return new TorqueIntelligence({
|
|
219
|
+
apiKey,
|
|
220
|
+
baseUrl: process.env.TORQUE_BASE_URL || overrides?.baseUrl,
|
|
221
|
+
timeout: overrides?.timeout,
|
|
222
|
+
cooldownRetries: overrides?.cooldownRetries,
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
exports.TorqueIntelligence = TorqueIntelligence;
|
|
227
|
+
exports.TorqueIntelligenceError = TorqueIntelligenceError;
|
|
228
|
+
exports.createTorqueIntelligence = createTorqueIntelligence;
|
|
229
|
+
exports.createTorqueIntelligenceFromEnv = createTorqueIntelligenceFromEnv;
|
|
230
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/errors.ts","../src/http.ts","../src/query.ts","../src/index.ts"],"sourcesContent":["export interface TorqueIntelligenceErrorDetails {\n code: string\n statusCode: number\n details?: Record<string, unknown>\n retryAfterMs?: number\n}\n\nexport class TorqueIntelligenceError extends Error {\n code: string\n statusCode: number\n details?: Record<string, unknown>\n retryAfterMs?: number\n\n constructor(message: string, options: TorqueIntelligenceErrorDetails) {\n super(message)\n this.name = 'TorqueIntelligenceError'\n this.code = options.code\n this.statusCode = options.statusCode\n this.details = options.details\n this.retryAfterMs = options.retryAfterMs\n Object.setPrototypeOf(this, TorqueIntelligenceError.prototype)\n }\n}\n\nexport function parseTorqueV1ErrorBody(\n body: unknown,\n statusCode: number,\n fallbackMessage: string,\n): TorqueIntelligenceError {\n const envelope = body as { error?: { code?: string; message?: string; details?: Record<string, unknown> } } | null\n const err = envelope?.error\n const code = typeof err?.code === 'string' ? err.code : 'API_ERROR'\n const message = typeof err?.message === 'string' ? err.message : fallbackMessage\n const details = err?.details\n const retryAfterRaw = details?.retryAfterMs\n const retryAfterMs =\n code === 'COOLDOWN' && typeof retryAfterRaw === 'number' && Number.isFinite(retryAfterRaw)\n ? retryAfterRaw\n : undefined\n\n return new TorqueIntelligenceError(message, {\n code,\n statusCode,\n details,\n retryAfterMs,\n })\n}\n","import { parseTorqueV1ErrorBody, TorqueIntelligenceError } from './errors'\n\nexport interface TorqueIntelligenceHttpConfig {\n apiKey: string\n baseUrl: string\n timeout: number\n cooldownRetries: number\n}\n\nfunction sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms))\n}\n\nexport async function torqueIntelligenceGet<T>(\n config: TorqueIntelligenceHttpConfig,\n path: string,\n attempt = 0,\n): Promise<T> {\n const url = `${config.baseUrl}${path}`\n const controller = new AbortController()\n const timeoutId = setTimeout(() => controller.abort(), config.timeout)\n\n try {\n const response = await fetch(url, {\n method: 'GET',\n headers: {\n Accept: 'application/json',\n Authorization: `Bearer ${config.apiKey}`,\n },\n signal: controller.signal,\n })\n\n clearTimeout(timeoutId)\n\n const body: unknown = await response.json().catch(() => ({}))\n\n if (!response.ok) {\n const error = parseTorqueV1ErrorBody(\n body,\n response.status,\n `HTTP ${response.status}: ${response.statusText}`,\n )\n\n if (\n error.code === 'COOLDOWN' &&\n error.retryAfterMs != null &&\n attempt < config.cooldownRetries\n ) {\n await sleep(error.retryAfterMs)\n return torqueIntelligenceGet<T>(config, path, attempt + 1)\n }\n\n throw error\n }\n\n return body as T\n } catch (error) {\n clearTimeout(timeoutId)\n\n if (error instanceof TorqueIntelligenceError) {\n throw error\n }\n\n if (error instanceof Error) {\n if (error.name === 'AbortError') {\n throw new TorqueIntelligenceError('Request timeout', {\n code: 'TIMEOUT',\n statusCode: 408,\n })\n }\n throw new TorqueIntelligenceError(error.message, {\n code: 'NETWORK_ERROR',\n statusCode: 500,\n })\n }\n\n throw new TorqueIntelligenceError('Request failed', {\n code: 'UNKNOWN_ERROR',\n statusCode: 500,\n })\n }\n}\n","import type {\n GetHappeningNowParams,\n GetIntelligenceFeedParams,\n GetTradeAnglesParams,\n IntelligenceItemKind,\n IntelligenceLaneId,\n} from '@torquefi/types/intelligence'\n\nfunction appendCsv(\n params: URLSearchParams,\n key: string,\n values: readonly string[] | undefined,\n): void {\n if (values?.length) {\n params.set(key, values.join(','))\n }\n}\n\nexport function buildFeedQuery(params: GetIntelligenceFeedParams = {}): string {\n const sp = new URLSearchParams()\n\n if (params.walletAddress?.trim()) {\n sp.set('walletAddress', params.walletAddress.trim())\n }\n if (params.chainId != null && Number.isFinite(params.chainId)) {\n sp.set('chainId', String(params.chainId))\n }\n appendCsv(sp, 'lanes', params.lanes as IntelligenceLaneId[] | undefined)\n appendCsv(sp, 'kinds', params.kinds as IntelligenceItemKind[] | undefined)\n if (params.limit != null && Number.isFinite(params.limit)) {\n sp.set('limit', String(params.limit))\n }\n if (params.includeBrief) {\n sp.set('includeBrief', '1')\n }\n if (params.force) {\n sp.set('force', '1')\n }\n\n const qs = sp.toString()\n return qs ? `?${qs}` : ''\n}\n\nexport function buildTradeAnglesQuery(params: GetTradeAnglesParams = {}): string {\n const sp = new URLSearchParams()\n\n if (params.walletAddress?.trim()) {\n sp.set('walletAddress', params.walletAddress.trim())\n }\n if (params.force) {\n sp.set('force', '1')\n }\n\n const qs = sp.toString()\n return qs ? `?${qs}` : ''\n}\n\nexport function buildHappeningNowQuery(params: GetHappeningNowParams = {}): string {\n const sp = new URLSearchParams()\n\n if (params.chainId != null && Number.isFinite(params.chainId)) {\n sp.set('chainId', String(params.chainId))\n }\n\n const qs = sp.toString()\n return qs ? `?${qs}` : ''\n}\n","import type {\n GetHappeningNowParams,\n GetIntelligenceFeedParams,\n GetTradeAnglesParams,\n HappeningNowResponseV1,\n IntelligenceFeedResponseV1,\n TradeAnglesResponseV1,\n} from '@torquefi/types/intelligence'\nimport type { TorqueCapabilitiesProbe, TorquePlatformClientConfig } from '@torquefi/types/platform'\nimport { INTELLIGENCE_MANIFEST_VERSION } from '@torquefi/types/intelligence'\n\nimport { TorqueIntelligenceError } from './errors'\nimport { torqueIntelligenceGet, type TorqueIntelligenceHttpConfig } from './http'\nimport {\n buildFeedQuery,\n buildHappeningNowQuery,\n buildTradeAnglesQuery,\n} from './query'\n\nexport interface TorqueIntelligenceOptions extends TorquePlatformClientConfig {\n /** Automatic retries after 429 COOLDOWN (default 1). */\n cooldownRetries?: number\n}\n\nexport type { TorquePlatformClientConfig as TorqueIntelligenceConfig } from '@torquefi/types/platform'\n\nexport { TorqueIntelligenceError }\nexport type {\n GetHappeningNowParams,\n GetIntelligenceFeedParams,\n GetTradeAnglesParams,\n HappeningNowResponseV1,\n IntelligenceFeedResponseV1,\n IntelligenceItemV1,\n TradeAnglesResponseV1,\n} from '@torquefi/types/intelligence'\n\nfunction validateConfig(config: TorqueIntelligenceOptions): void {\n if (!config.apiKey?.trim()) {\n throw new TorqueIntelligenceError('API key is required', {\n code: 'INVALID_CONFIG',\n statusCode: 400,\n })\n }\n if (config.timeout != null && (typeof config.timeout !== 'number' || config.timeout <= 0)) {\n throw new TorqueIntelligenceError('Timeout must be a positive number', {\n code: 'INVALID_CONFIG',\n statusCode: 400,\n })\n }\n if (\n config.cooldownRetries != null &&\n (typeof config.cooldownRetries !== 'number' || config.cooldownRetries < 0)\n ) {\n throw new TorqueIntelligenceError('cooldownRetries must be a non-negative number', {\n code: 'INVALID_CONFIG',\n statusCode: 400,\n })\n }\n}\n\nfunction toHttpConfig(config: TorqueIntelligenceOptions): TorqueIntelligenceHttpConfig {\n return {\n apiKey: config.apiKey.trim(),\n baseUrl: (config.baseUrl || 'https://app.torque.fi').replace(/\\/$/, ''),\n timeout: config.timeout ?? 30_000,\n cooldownRetries: config.cooldownRetries ?? 1,\n }\n}\n\nexport class TorqueIntelligence {\n private readonly http: TorqueIntelligenceHttpConfig\n\n constructor(config: TorqueIntelligenceOptions) {\n validateConfig(config)\n this.http = toHttpConfig(config)\n }\n\n /**\n * Primary integrator feed — normalized IntelligenceItemV1[], lanes, optional brief.\n * GET /api/v1/intelligence/feed\n */\n async getFeed(params?: GetIntelligenceFeedParams): Promise<IntelligenceFeedResponseV1> {\n return torqueIntelligenceGet<IntelligenceFeedResponseV1>(\n this.http,\n `/api/v1/intelligence/feed${buildFeedQuery(params)}`,\n )\n }\n\n /** Ranked trade angles (desk lane). GET /api/v1/intelligence/trade-angles */\n async getTradeAngles(params?: GetTradeAnglesParams): Promise<TradeAnglesResponseV1> {\n return torqueIntelligenceGet<TradeAnglesResponseV1>(\n this.http,\n `/api/v1/intelligence/trade-angles${buildTradeAnglesQuery(params)}`,\n )\n }\n\n /** Timely macro/crypto signals. GET /api/v1/intelligence/happening-now */\n async getHappeningNow(params?: GetHappeningNowParams): Promise<HappeningNowResponseV1> {\n return torqueIntelligenceGet<HappeningNowResponseV1>(\n this.http,\n `/api/v1/intelligence/happening-now${buildHappeningNowQuery(params)}`,\n )\n }\n\n /** Capability manifest probe. GET /api/v1/capabilities */\n async getCapabilities(): Promise<TorqueCapabilitiesProbe> {\n return torqueIntelligenceGet<TorqueCapabilitiesProbe>(this.http, '/api/v1/capabilities')\n }\n\n /**\n * Throws if the server manifest is older than the SDK's expected Intelligence schema version.\n */\n assertManifestCompatibility(manifestVersion: number): void {\n if (manifestVersion < INTELLIGENCE_MANIFEST_VERSION) {\n throw new TorqueIntelligenceError(\n `Server manifest v${manifestVersion} is older than client expectation v${INTELLIGENCE_MANIFEST_VERSION}`,\n {\n code: 'MANIFEST_MISMATCH',\n statusCode: 400,\n details: {\n serverVersion: manifestVersion,\n clientVersion: INTELLIGENCE_MANIFEST_VERSION,\n },\n },\n )\n }\n }\n}\n\nexport function createTorqueIntelligence(config: TorqueIntelligenceOptions): TorqueIntelligence {\n return new TorqueIntelligence(config)\n}\n\n/**\n * Reads TORQUE_API_KEY and optional TORQUE_BASE_URL from the environment.\n */\nexport function createTorqueIntelligenceFromEnv(\n overrides?: Partial<TorqueIntelligenceOptions>,\n): TorqueIntelligence {\n const apiKey = process.env.TORQUE_API_KEY || overrides?.apiKey\n if (!apiKey) {\n throw new TorqueIntelligenceError('TORQUE_API_KEY environment variable is required', {\n code: 'MISSING_ENV_VARS',\n statusCode: 400,\n })\n }\n\n return new TorqueIntelligence({\n apiKey,\n baseUrl: process.env.TORQUE_BASE_URL || overrides?.baseUrl,\n timeout: overrides?.timeout,\n cooldownRetries: overrides?.cooldownRetries,\n })\n}\n"],"names":["INTELLIGENCE_MANIFEST_VERSION"],"mappings":";;;;AAOM,MAAO,uBAAwB,SAAQ,KAAK,CAAA;IAMhD,WAAA,CAAY,OAAe,EAAE,OAAuC,EAAA;QAClE,KAAK,CAAC,OAAO,CAAC;AACd,QAAA,IAAI,CAAC,IAA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GAAGA,0CAA6B,EAAE;YACnD,MAAM,IAAI,uBAAuB,CAC/B,CAAA,iBAAA,EAAoB,eAAe,CAAA,mCAAA,EAAsCA,0CAA6B,EAAE,EACxG;AACE,gBAAA,IAAI,EAAE,mBAAmB;AACzB,gBAAA,UAAU,EAAE,GAAG;AACf,gBAAA,OAAO,EAAE;AACP,oBAAA,aAAa,EAAE,eAAe;AAC9B,oBAAA,aAAa,EAAEA,0CAA6B;AAC7C,iBAAA;AACF,aAAA,CACF;QACH;IACF;AACD;AAEK,SAAU,wBAAwB,CAAC,MAAiC,EAAA;AACxE,IAAA,OAAO,IAAI,kBAAkB,CAAC,MAAM,CAAC;AACvC;AAEA;;AAEG;AACG,SAAU,+BAA+B,CAC7C,SAA8C,EAAA;IAE9C,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,SAAS,EAAE,MAAM;IAC9D,IAAI,CAAC,MAAM,EAAE;AACX,QAAA,MAAM,IAAI,uBAAuB,CAAC,iDAAiD,EAAE;AACnF,YAAA,IAAI,EAAE,kBAAkB;AACxB,YAAA,UAAU,EAAE,GAAG;AAChB,SAAA,CAAC;IACJ;IAEA,OAAO,IAAI,kBAAkB,CAAC;QAC5B,MAAM;QACN,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,SAAS,EAAE,OAAO;QAC1D,OAAO,EAAE,SAAS,EAAE,OAAO;QAC3B,eAAe,EAAE,SAAS,EAAE,eAAe;AAC5C,KAAA,CAAC;AACJ;;;;;;;"}
|
package/dist/query.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { GetHappeningNowParams, GetIntelligenceFeedParams, GetTradeAnglesParams } from '@torquefi/types/intelligence';
|
|
2
|
+
export declare function buildFeedQuery(params?: GetIntelligenceFeedParams): string;
|
|
3
|
+
export declare function buildTradeAnglesQuery(params?: GetTradeAnglesParams): string;
|
|
4
|
+
export declare function buildHappeningNowQuery(params?: GetHappeningNowParams): string;
|
|
5
|
+
//# sourceMappingURL=query.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EACrB,yBAAyB,EACzB,oBAAoB,EAGrB,MAAM,8BAA8B,CAAA;AAYrC,wBAAgB,cAAc,CAAC,MAAM,GAAE,yBAA8B,GAAG,MAAM,CAuB7E;AAED,wBAAgB,qBAAqB,CAAC,MAAM,GAAE,oBAAyB,GAAG,MAAM,CAY/E;AAED,wBAAgB,sBAAsB,CAAC,MAAM,GAAE,qBAA0B,GAAG,MAAM,CASjF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "torque-intelligence",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Official Torque Intelligence SDK — read-only feed client for Platform API v1",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.esm.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.esm.js",
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
},
|
|
14
|
+
"./package.json": "./package.json"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"README.md",
|
|
19
|
+
"LICENSE"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "rollup -c",
|
|
23
|
+
"dev": "rollup -c -w",
|
|
24
|
+
"clean": "rimraf dist",
|
|
25
|
+
"prepublishOnly": "yarn clean && yarn build"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"torque",
|
|
29
|
+
"intelligence",
|
|
30
|
+
"feed",
|
|
31
|
+
"fintech",
|
|
32
|
+
"api",
|
|
33
|
+
"typescript",
|
|
34
|
+
"sdk"
|
|
35
|
+
],
|
|
36
|
+
"author": "Torque <hello@torque.fi>",
|
|
37
|
+
"license": "MIT",
|
|
38
|
+
"homepage": "https://torque.fi",
|
|
39
|
+
"repository": {
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": "git+https://github.com/torque-fi/torque_webapp.git",
|
|
42
|
+
"directory": "packages/torque-intelligence"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@torquefi/types": "^0.1.0"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@rollup/plugin-typescript": "^12.1.4",
|
|
49
|
+
"@types/node": "^20.0.0",
|
|
50
|
+
"rimraf": "^5.0.0",
|
|
51
|
+
"rollup": "^4.0.0",
|
|
52
|
+
"typescript": "^5.0.0"
|
|
53
|
+
},
|
|
54
|
+
"engines": {
|
|
55
|
+
"node": ">=16.0.0"
|
|
56
|
+
}
|
|
57
|
+
}
|