glassnode-api 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/README.md +74 -0
- package/dist/glassnode-api.d.ts +45 -0
- package/dist/glassnode-api.js +92 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +19 -0
- package/dist/types/config.d.ts +25 -0
- package/dist/types/config.js +18 -0
- package/dist/types/metadata.d.ts +383 -0
- package/dist/types/metadata.js +121 -0
- package/dist/types/response.d.ts +39 -0
- package/dist/types/response.js +14 -0
- package/package.json +47 -0
package/README.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Glassnode API
|
|
2
|
+
|
|
3
|
+
A Node.js client for the [Glassnode API](https://docs.glassnode.com/).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
yarn add glassnode-api
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { GlassnodeAPI } from 'glassnode-api';
|
|
15
|
+
|
|
16
|
+
// Create an instance with your API key
|
|
17
|
+
const api = new GlassnodeAPI({
|
|
18
|
+
apiKey: 'YOUR_API_KEY',
|
|
19
|
+
// Optional: Override the API URL
|
|
20
|
+
// apiUrl: 'https://api.glassnode.com'
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// Fetch asset metadata
|
|
24
|
+
async function getAssets() {
|
|
25
|
+
try {
|
|
26
|
+
const response = await api.getAssetMetadata();
|
|
27
|
+
console.log(response.data);
|
|
28
|
+
} catch (error) {
|
|
29
|
+
console.error('Error fetching asset metadata:', error);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Fetch metric metadata
|
|
34
|
+
async function getMetrics() {
|
|
35
|
+
try {
|
|
36
|
+
const response = await api.getMetricMetadata();
|
|
37
|
+
console.log(response.data);
|
|
38
|
+
} catch (error) {
|
|
39
|
+
console.error('Error fetching metric metadata:', error);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Examples
|
|
45
|
+
|
|
46
|
+
Check the `examples` directory for usage examples. To run the examples:
|
|
47
|
+
|
|
48
|
+
1. Navigate to the examples directory
|
|
49
|
+
2. Create a `.env` file based on `.env.example` with your API key
|
|
50
|
+
3. Install dependencies with `yarn install`
|
|
51
|
+
4. Run an example with `yarn ts-node metadata.ts`
|
|
52
|
+
|
|
53
|
+
## Development
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
# Install dependencies
|
|
57
|
+
yarn install
|
|
58
|
+
|
|
59
|
+
# Build the project
|
|
60
|
+
yarn build
|
|
61
|
+
|
|
62
|
+
# Run tests
|
|
63
|
+
yarn test
|
|
64
|
+
|
|
65
|
+
# Lint code
|
|
66
|
+
yarn lint
|
|
67
|
+
|
|
68
|
+
# Format code
|
|
69
|
+
yarn format
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## License
|
|
73
|
+
|
|
74
|
+
MIT
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { GlassnodeConfig } from './types/config';
|
|
2
|
+
import { AssetMetadataResponse, MetricMetadataResponse, MetricListResponse } from './types/metadata';
|
|
3
|
+
/**
|
|
4
|
+
* Glassnode API client
|
|
5
|
+
*/
|
|
6
|
+
export declare class GlassnodeAPI {
|
|
7
|
+
private apiKey;
|
|
8
|
+
private apiUrl;
|
|
9
|
+
/**
|
|
10
|
+
* Create a new Glassnode API client
|
|
11
|
+
* @param config Configuration object
|
|
12
|
+
*/
|
|
13
|
+
constructor(config: GlassnodeConfig);
|
|
14
|
+
/**
|
|
15
|
+
* Make an API request
|
|
16
|
+
* @param endpoint API endpoint path
|
|
17
|
+
* @param params Query parameters
|
|
18
|
+
* @returns Promise resolving to the response data
|
|
19
|
+
*/
|
|
20
|
+
private request;
|
|
21
|
+
/**
|
|
22
|
+
* Get metadata for all assets
|
|
23
|
+
* @returns Promise resolving to validated asset metadata
|
|
24
|
+
*/
|
|
25
|
+
getAssetMetadata(): Promise<AssetMetadataResponse>;
|
|
26
|
+
/**
|
|
27
|
+
* Get metadata for a specific metric
|
|
28
|
+
* @param metricPath Path of the metric
|
|
29
|
+
* @param params Queried parameters for the metric
|
|
30
|
+
* @returns Promise resolving to validated metric metadata
|
|
31
|
+
*/
|
|
32
|
+
getMetricMetadata(metricPath: string, params?: Record<string, string>): Promise<MetricMetadataResponse>;
|
|
33
|
+
/**
|
|
34
|
+
* Get a list of all metrics
|
|
35
|
+
* @returns Promise resolving to validated metric metadata
|
|
36
|
+
*/
|
|
37
|
+
getMetricList(): Promise<MetricListResponse>;
|
|
38
|
+
/**
|
|
39
|
+
* Call a generic metric
|
|
40
|
+
* @param metricPath Path of the metric (e.g. /accumulation_balance)
|
|
41
|
+
* @param params Queried parameters for the metric
|
|
42
|
+
* @returns Promise resolving to the response data
|
|
43
|
+
*/
|
|
44
|
+
callMetric<T>(metricPath: string, params?: Record<string, string>): Promise<T>;
|
|
45
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GlassnodeAPI = void 0;
|
|
4
|
+
const config_1 = require("./types/config");
|
|
5
|
+
const metadata_1 = require("./types/metadata");
|
|
6
|
+
/**
|
|
7
|
+
* Glassnode API client
|
|
8
|
+
*/
|
|
9
|
+
class GlassnodeAPI {
|
|
10
|
+
apiKey;
|
|
11
|
+
apiUrl;
|
|
12
|
+
/**
|
|
13
|
+
* Create a new Glassnode API client
|
|
14
|
+
* @param config Configuration object
|
|
15
|
+
*/
|
|
16
|
+
constructor(config) {
|
|
17
|
+
// Validate config with Zod
|
|
18
|
+
const validatedConfig = config_1.GlassnodeConfigSchema.parse(config);
|
|
19
|
+
this.apiKey = validatedConfig.apiKey;
|
|
20
|
+
this.apiUrl = validatedConfig.apiUrl;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Make an API request
|
|
24
|
+
* @param endpoint API endpoint path
|
|
25
|
+
* @param params Query parameters
|
|
26
|
+
* @returns Promise resolving to the response data
|
|
27
|
+
*/
|
|
28
|
+
async request(endpoint, params = {}) {
|
|
29
|
+
// Add API key to params
|
|
30
|
+
const queryParams = new URLSearchParams({
|
|
31
|
+
...params,
|
|
32
|
+
api_key: this.apiKey,
|
|
33
|
+
});
|
|
34
|
+
const url = `${this.apiUrl}${endpoint}?${queryParams}`;
|
|
35
|
+
try {
|
|
36
|
+
const response = await fetch(url);
|
|
37
|
+
if (!response.ok) {
|
|
38
|
+
if (response.status === 400) {
|
|
39
|
+
throw new Error(`Bad request: ${response.statusText}`);
|
|
40
|
+
}
|
|
41
|
+
throw new Error(`API request failed with status ${response.status}: ${response.statusText}`);
|
|
42
|
+
}
|
|
43
|
+
return await response.json();
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
if (error instanceof Error) {
|
|
47
|
+
throw new Error(`Glassnode API error: ${error.message}`);
|
|
48
|
+
}
|
|
49
|
+
throw new Error('Unknown error occurred');
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Get metadata for all assets
|
|
54
|
+
* @returns Promise resolving to validated asset metadata
|
|
55
|
+
*/
|
|
56
|
+
async getAssetMetadata() {
|
|
57
|
+
const response = await this.request('/v1/metadata/assets');
|
|
58
|
+
// Validate response with Zod schema
|
|
59
|
+
return metadata_1.AssetMetadataResponseSchema.parse(response.data);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Get metadata for a specific metric
|
|
63
|
+
* @param metricPath Path of the metric
|
|
64
|
+
* @param params Queried parameters for the metric
|
|
65
|
+
* @returns Promise resolving to validated metric metadata
|
|
66
|
+
*/
|
|
67
|
+
async getMetricMetadata(metricPath, params = {}) {
|
|
68
|
+
const response = await this.request('/v1/metadata/metric', { path: metricPath, ...params });
|
|
69
|
+
// Validate response with Zod schema
|
|
70
|
+
return metadata_1.MetricMetadataResponseSchema.parse(response);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Get a list of all metrics
|
|
74
|
+
* @returns Promise resolving to validated metric metadata
|
|
75
|
+
*/
|
|
76
|
+
async getMetricList() {
|
|
77
|
+
const response = await this.request('/v1/metadata/metrics');
|
|
78
|
+
// Validate response with Zod schema
|
|
79
|
+
return metadata_1.MetricListResponseSchema.parse(response);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Call a generic metric
|
|
83
|
+
* @param metricPath Path of the metric (e.g. /accumulation_balance)
|
|
84
|
+
* @param params Queried parameters for the metric
|
|
85
|
+
* @returns Promise resolving to the response data
|
|
86
|
+
*/
|
|
87
|
+
async callMetric(metricPath, params = {}) {
|
|
88
|
+
const response = await this.request('https://api.glassnode.com/v1/metrics/addresses' + metricPath, params);
|
|
89
|
+
return response;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.GlassnodeAPI = GlassnodeAPI;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./glassnode-api"), exports);
|
|
18
|
+
__exportStar(require("./types/config"), exports);
|
|
19
|
+
__exportStar(require("./types/metadata"), exports);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Zod schema for Glassnode API configuration
|
|
4
|
+
*/
|
|
5
|
+
export declare const GlassnodeConfigSchema: z.ZodObject<{
|
|
6
|
+
/**
|
|
7
|
+
* API key for authentication
|
|
8
|
+
*/
|
|
9
|
+
apiKey: z.ZodString;
|
|
10
|
+
/**
|
|
11
|
+
* Base URL for the Glassnode API
|
|
12
|
+
* @default "https://api.glassnode.com"
|
|
13
|
+
*/
|
|
14
|
+
apiUrl: z.ZodDefault<z.ZodString>;
|
|
15
|
+
}, "strip", z.ZodTypeAny, {
|
|
16
|
+
apiKey: string;
|
|
17
|
+
apiUrl: string;
|
|
18
|
+
}, {
|
|
19
|
+
apiKey: string;
|
|
20
|
+
apiUrl?: string | undefined;
|
|
21
|
+
}>;
|
|
22
|
+
/**
|
|
23
|
+
* Configuration for the Glassnode API client
|
|
24
|
+
*/
|
|
25
|
+
export type GlassnodeConfig = z.input<typeof GlassnodeConfigSchema>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GlassnodeConfigSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
/**
|
|
6
|
+
* Zod schema for Glassnode API configuration
|
|
7
|
+
*/
|
|
8
|
+
exports.GlassnodeConfigSchema = zod_1.z.object({
|
|
9
|
+
/**
|
|
10
|
+
* API key for authentication
|
|
11
|
+
*/
|
|
12
|
+
apiKey: zod_1.z.string().min(1, 'API key is required'),
|
|
13
|
+
/**
|
|
14
|
+
* Base URL for the Glassnode API
|
|
15
|
+
* @default "https://api.glassnode.com"
|
|
16
|
+
*/
|
|
17
|
+
apiUrl: zod_1.z.string().url().default('https://api.glassnode.com'),
|
|
18
|
+
});
|
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Metadata response types
|
|
3
|
+
*/
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
/**
|
|
6
|
+
* External identifier sources schema
|
|
7
|
+
*/
|
|
8
|
+
export declare const ExternalIdSourceSchema: z.ZodEnum<["ccdata", "coinmarketcap", "coingecko"]>;
|
|
9
|
+
/**
|
|
10
|
+
* External identifier sources type
|
|
11
|
+
*/
|
|
12
|
+
export type ExternalIdSource = z.infer<typeof ExternalIdSourceSchema>;
|
|
13
|
+
/**
|
|
14
|
+
* External identifiers for an asset schema
|
|
15
|
+
*/
|
|
16
|
+
export declare const ExternalIdsSchema: z.ZodRecord<z.ZodEnum<["ccdata", "coinmarketcap", "coingecko"]>, z.ZodOptional<z.ZodString>>;
|
|
17
|
+
/**
|
|
18
|
+
* External identifiers for an asset type
|
|
19
|
+
*/
|
|
20
|
+
export type ExternalIds = z.infer<typeof ExternalIdsSchema>;
|
|
21
|
+
/**
|
|
22
|
+
* Blockchain information for an asset schema
|
|
23
|
+
*/
|
|
24
|
+
export declare const AssetBlockchainSchema: z.ZodObject<{
|
|
25
|
+
/**
|
|
26
|
+
* Blockchain name
|
|
27
|
+
*/
|
|
28
|
+
blockchain: z.ZodString;
|
|
29
|
+
/**
|
|
30
|
+
* Token address on the blockchain
|
|
31
|
+
*/
|
|
32
|
+
address: z.ZodString;
|
|
33
|
+
/**
|
|
34
|
+
* Number of decimal places
|
|
35
|
+
*/
|
|
36
|
+
decimals: z.ZodNumber;
|
|
37
|
+
/**
|
|
38
|
+
* Whether on-chain metrics are supported
|
|
39
|
+
*/
|
|
40
|
+
on_chain_support: z.ZodBoolean;
|
|
41
|
+
}, "strip", z.ZodTypeAny, {
|
|
42
|
+
address: string;
|
|
43
|
+
blockchain: string;
|
|
44
|
+
decimals: number;
|
|
45
|
+
on_chain_support: boolean;
|
|
46
|
+
}, {
|
|
47
|
+
address: string;
|
|
48
|
+
blockchain: string;
|
|
49
|
+
decimals: number;
|
|
50
|
+
on_chain_support: boolean;
|
|
51
|
+
}>;
|
|
52
|
+
/**
|
|
53
|
+
* Blockchain information for an asset type
|
|
54
|
+
*/
|
|
55
|
+
export type AssetBlockchain = z.infer<typeof AssetBlockchainSchema>;
|
|
56
|
+
/**
|
|
57
|
+
* Asset metadata schema
|
|
58
|
+
*/
|
|
59
|
+
export declare const AssetMetadataSchema: z.ZodObject<{
|
|
60
|
+
/**
|
|
61
|
+
* Asset identifier
|
|
62
|
+
*/
|
|
63
|
+
id: z.ZodString;
|
|
64
|
+
/**
|
|
65
|
+
* Asset symbol (e.g., "BTC", "ETH")
|
|
66
|
+
*/
|
|
67
|
+
symbol: z.ZodString;
|
|
68
|
+
/**
|
|
69
|
+
* Asset name (e.g., "Bitcoin", "Ethereum")
|
|
70
|
+
*/
|
|
71
|
+
name: z.ZodString;
|
|
72
|
+
/**
|
|
73
|
+
* Type of asset (e.g., "coin", "token")
|
|
74
|
+
*/
|
|
75
|
+
asset_type: z.ZodString;
|
|
76
|
+
/**
|
|
77
|
+
* External identifiers for this asset
|
|
78
|
+
*/
|
|
79
|
+
external_ids: z.ZodRecord<z.ZodEnum<["ccdata", "coinmarketcap", "coingecko"]>, z.ZodOptional<z.ZodString>>;
|
|
80
|
+
/**
|
|
81
|
+
* Blockchain information for this asset
|
|
82
|
+
*/
|
|
83
|
+
blockchains: z.ZodArray<z.ZodObject<{
|
|
84
|
+
/**
|
|
85
|
+
* Blockchain name
|
|
86
|
+
*/
|
|
87
|
+
blockchain: z.ZodString;
|
|
88
|
+
/**
|
|
89
|
+
* Token address on the blockchain
|
|
90
|
+
*/
|
|
91
|
+
address: z.ZodString;
|
|
92
|
+
/**
|
|
93
|
+
* Number of decimal places
|
|
94
|
+
*/
|
|
95
|
+
decimals: z.ZodNumber;
|
|
96
|
+
/**
|
|
97
|
+
* Whether on-chain metrics are supported
|
|
98
|
+
*/
|
|
99
|
+
on_chain_support: z.ZodBoolean;
|
|
100
|
+
}, "strip", z.ZodTypeAny, {
|
|
101
|
+
address: string;
|
|
102
|
+
blockchain: string;
|
|
103
|
+
decimals: number;
|
|
104
|
+
on_chain_support: boolean;
|
|
105
|
+
}, {
|
|
106
|
+
address: string;
|
|
107
|
+
blockchain: string;
|
|
108
|
+
decimals: number;
|
|
109
|
+
on_chain_support: boolean;
|
|
110
|
+
}>, "many">;
|
|
111
|
+
}, "strip", z.ZodTypeAny, {
|
|
112
|
+
symbol: string;
|
|
113
|
+
name: string;
|
|
114
|
+
id: string;
|
|
115
|
+
asset_type: string;
|
|
116
|
+
external_ids: Partial<Record<"ccdata" | "coinmarketcap" | "coingecko", string | undefined>>;
|
|
117
|
+
blockchains: {
|
|
118
|
+
address: string;
|
|
119
|
+
blockchain: string;
|
|
120
|
+
decimals: number;
|
|
121
|
+
on_chain_support: boolean;
|
|
122
|
+
}[];
|
|
123
|
+
}, {
|
|
124
|
+
symbol: string;
|
|
125
|
+
name: string;
|
|
126
|
+
id: string;
|
|
127
|
+
asset_type: string;
|
|
128
|
+
external_ids: Partial<Record<"ccdata" | "coinmarketcap" | "coingecko", string | undefined>>;
|
|
129
|
+
blockchains: {
|
|
130
|
+
address: string;
|
|
131
|
+
blockchain: string;
|
|
132
|
+
decimals: number;
|
|
133
|
+
on_chain_support: boolean;
|
|
134
|
+
}[];
|
|
135
|
+
}>;
|
|
136
|
+
/**
|
|
137
|
+
* Asset metadata type
|
|
138
|
+
*/
|
|
139
|
+
export type AssetMetadata = z.infer<typeof AssetMetadataSchema>;
|
|
140
|
+
/**
|
|
141
|
+
* Asset metadata response schema
|
|
142
|
+
*/
|
|
143
|
+
export declare const AssetMetadataResponseSchema: z.ZodArray<z.ZodObject<{
|
|
144
|
+
/**
|
|
145
|
+
* Asset identifier
|
|
146
|
+
*/
|
|
147
|
+
id: z.ZodString;
|
|
148
|
+
/**
|
|
149
|
+
* Asset symbol (e.g., "BTC", "ETH")
|
|
150
|
+
*/
|
|
151
|
+
symbol: z.ZodString;
|
|
152
|
+
/**
|
|
153
|
+
* Asset name (e.g., "Bitcoin", "Ethereum")
|
|
154
|
+
*/
|
|
155
|
+
name: z.ZodString;
|
|
156
|
+
/**
|
|
157
|
+
* Type of asset (e.g., "coin", "token")
|
|
158
|
+
*/
|
|
159
|
+
asset_type: z.ZodString;
|
|
160
|
+
/**
|
|
161
|
+
* External identifiers for this asset
|
|
162
|
+
*/
|
|
163
|
+
external_ids: z.ZodRecord<z.ZodEnum<["ccdata", "coinmarketcap", "coingecko"]>, z.ZodOptional<z.ZodString>>;
|
|
164
|
+
/**
|
|
165
|
+
* Blockchain information for this asset
|
|
166
|
+
*/
|
|
167
|
+
blockchains: z.ZodArray<z.ZodObject<{
|
|
168
|
+
/**
|
|
169
|
+
* Blockchain name
|
|
170
|
+
*/
|
|
171
|
+
blockchain: z.ZodString;
|
|
172
|
+
/**
|
|
173
|
+
* Token address on the blockchain
|
|
174
|
+
*/
|
|
175
|
+
address: z.ZodString;
|
|
176
|
+
/**
|
|
177
|
+
* Number of decimal places
|
|
178
|
+
*/
|
|
179
|
+
decimals: z.ZodNumber;
|
|
180
|
+
/**
|
|
181
|
+
* Whether on-chain metrics are supported
|
|
182
|
+
*/
|
|
183
|
+
on_chain_support: z.ZodBoolean;
|
|
184
|
+
}, "strip", z.ZodTypeAny, {
|
|
185
|
+
address: string;
|
|
186
|
+
blockchain: string;
|
|
187
|
+
decimals: number;
|
|
188
|
+
on_chain_support: boolean;
|
|
189
|
+
}, {
|
|
190
|
+
address: string;
|
|
191
|
+
blockchain: string;
|
|
192
|
+
decimals: number;
|
|
193
|
+
on_chain_support: boolean;
|
|
194
|
+
}>, "many">;
|
|
195
|
+
}, "strip", z.ZodTypeAny, {
|
|
196
|
+
symbol: string;
|
|
197
|
+
name: string;
|
|
198
|
+
id: string;
|
|
199
|
+
asset_type: string;
|
|
200
|
+
external_ids: Partial<Record<"ccdata" | "coinmarketcap" | "coingecko", string | undefined>>;
|
|
201
|
+
blockchains: {
|
|
202
|
+
address: string;
|
|
203
|
+
blockchain: string;
|
|
204
|
+
decimals: number;
|
|
205
|
+
on_chain_support: boolean;
|
|
206
|
+
}[];
|
|
207
|
+
}, {
|
|
208
|
+
symbol: string;
|
|
209
|
+
name: string;
|
|
210
|
+
id: string;
|
|
211
|
+
asset_type: string;
|
|
212
|
+
external_ids: Partial<Record<"ccdata" | "coinmarketcap" | "coingecko", string | undefined>>;
|
|
213
|
+
blockchains: {
|
|
214
|
+
address: string;
|
|
215
|
+
blockchain: string;
|
|
216
|
+
decimals: number;
|
|
217
|
+
on_chain_support: boolean;
|
|
218
|
+
}[];
|
|
219
|
+
}>, "many">;
|
|
220
|
+
/**
|
|
221
|
+
* Asset metadata response type
|
|
222
|
+
*/
|
|
223
|
+
export type AssetMetadataResponse = z.infer<typeof AssetMetadataResponseSchema>;
|
|
224
|
+
/**
|
|
225
|
+
* Metric tier schema
|
|
226
|
+
*/
|
|
227
|
+
export declare const MetricTierSchema: z.ZodEnum<["free", "tier1", "tier2", "tier3", "tier4", "tier5"]>;
|
|
228
|
+
/**
|
|
229
|
+
* Metric tier type
|
|
230
|
+
*/
|
|
231
|
+
export type MetricTier = z.infer<typeof MetricTierSchema>;
|
|
232
|
+
/**
|
|
233
|
+
* Metric data type schema
|
|
234
|
+
*/
|
|
235
|
+
export declare const MetricDataTypeSchema: z.ZodEnum<["average", "sum", "count", "percentage", "ratio"]>;
|
|
236
|
+
/**
|
|
237
|
+
* Metric data type
|
|
238
|
+
*/
|
|
239
|
+
export type MetricDataType = z.infer<typeof MetricDataTypeSchema>;
|
|
240
|
+
/**
|
|
241
|
+
* Metric metadata schema
|
|
242
|
+
*/
|
|
243
|
+
export declare const MetricMetadataSchema: z.ZodObject<{
|
|
244
|
+
/**
|
|
245
|
+
* Metric name
|
|
246
|
+
*/
|
|
247
|
+
path: z.ZodString;
|
|
248
|
+
/**
|
|
249
|
+
* Access tier required for this metric
|
|
250
|
+
*/
|
|
251
|
+
tier: z.ZodNumber;
|
|
252
|
+
/**
|
|
253
|
+
* The last date that the metadata was updated
|
|
254
|
+
*/
|
|
255
|
+
modified: z.ZodEffects<z.ZodNumber, Date, number>;
|
|
256
|
+
/**
|
|
257
|
+
* Next parameter for the metric
|
|
258
|
+
*/
|
|
259
|
+
next_param: z.ZodOptional<z.ZodString>;
|
|
260
|
+
/**
|
|
261
|
+
* Available assets for this metric
|
|
262
|
+
*/
|
|
263
|
+
refs: z.ZodObject<{
|
|
264
|
+
docs: z.ZodOptional<z.ZodString>;
|
|
265
|
+
studio: z.ZodOptional<z.ZodString>;
|
|
266
|
+
}, "strip", z.ZodTypeAny, {
|
|
267
|
+
docs?: string | undefined;
|
|
268
|
+
studio?: string | undefined;
|
|
269
|
+
}, {
|
|
270
|
+
docs?: string | undefined;
|
|
271
|
+
studio?: string | undefined;
|
|
272
|
+
}>;
|
|
273
|
+
/**
|
|
274
|
+
* Queried parameters for the metric
|
|
275
|
+
*/
|
|
276
|
+
queried: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
277
|
+
/**
|
|
278
|
+
* List of all allowed parameters and their values for the metric
|
|
279
|
+
*/
|
|
280
|
+
parameters: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString, "many">>;
|
|
281
|
+
}, "strip", z.ZodTypeAny, {
|
|
282
|
+
path: string;
|
|
283
|
+
tier: number;
|
|
284
|
+
modified: Date;
|
|
285
|
+
refs: {
|
|
286
|
+
docs?: string | undefined;
|
|
287
|
+
studio?: string | undefined;
|
|
288
|
+
};
|
|
289
|
+
queried: Record<string, any>;
|
|
290
|
+
parameters: Record<string, string[]>;
|
|
291
|
+
next_param?: string | undefined;
|
|
292
|
+
}, {
|
|
293
|
+
path: string;
|
|
294
|
+
tier: number;
|
|
295
|
+
modified: number;
|
|
296
|
+
refs: {
|
|
297
|
+
docs?: string | undefined;
|
|
298
|
+
studio?: string | undefined;
|
|
299
|
+
};
|
|
300
|
+
queried: Record<string, any>;
|
|
301
|
+
parameters: Record<string, string[]>;
|
|
302
|
+
next_param?: string | undefined;
|
|
303
|
+
}>;
|
|
304
|
+
/**
|
|
305
|
+
* Metric metadata type
|
|
306
|
+
*/
|
|
307
|
+
export type MetricMetadata = z.infer<typeof MetricMetadataSchema>;
|
|
308
|
+
/**
|
|
309
|
+
* Metric metadata response schema
|
|
310
|
+
*/
|
|
311
|
+
export declare const MetricMetadataResponseSchema: z.ZodObject<{
|
|
312
|
+
/**
|
|
313
|
+
* Metric name
|
|
314
|
+
*/
|
|
315
|
+
path: z.ZodString;
|
|
316
|
+
/**
|
|
317
|
+
* Access tier required for this metric
|
|
318
|
+
*/
|
|
319
|
+
tier: z.ZodNumber;
|
|
320
|
+
/**
|
|
321
|
+
* The last date that the metadata was updated
|
|
322
|
+
*/
|
|
323
|
+
modified: z.ZodEffects<z.ZodNumber, Date, number>;
|
|
324
|
+
/**
|
|
325
|
+
* Next parameter for the metric
|
|
326
|
+
*/
|
|
327
|
+
next_param: z.ZodOptional<z.ZodString>;
|
|
328
|
+
/**
|
|
329
|
+
* Available assets for this metric
|
|
330
|
+
*/
|
|
331
|
+
refs: z.ZodObject<{
|
|
332
|
+
docs: z.ZodOptional<z.ZodString>;
|
|
333
|
+
studio: z.ZodOptional<z.ZodString>;
|
|
334
|
+
}, "strip", z.ZodTypeAny, {
|
|
335
|
+
docs?: string | undefined;
|
|
336
|
+
studio?: string | undefined;
|
|
337
|
+
}, {
|
|
338
|
+
docs?: string | undefined;
|
|
339
|
+
studio?: string | undefined;
|
|
340
|
+
}>;
|
|
341
|
+
/**
|
|
342
|
+
* Queried parameters for the metric
|
|
343
|
+
*/
|
|
344
|
+
queried: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
345
|
+
/**
|
|
346
|
+
* List of all allowed parameters and their values for the metric
|
|
347
|
+
*/
|
|
348
|
+
parameters: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString, "many">>;
|
|
349
|
+
}, "strip", z.ZodTypeAny, {
|
|
350
|
+
path: string;
|
|
351
|
+
tier: number;
|
|
352
|
+
modified: Date;
|
|
353
|
+
refs: {
|
|
354
|
+
docs?: string | undefined;
|
|
355
|
+
studio?: string | undefined;
|
|
356
|
+
};
|
|
357
|
+
queried: Record<string, any>;
|
|
358
|
+
parameters: Record<string, string[]>;
|
|
359
|
+
next_param?: string | undefined;
|
|
360
|
+
}, {
|
|
361
|
+
path: string;
|
|
362
|
+
tier: number;
|
|
363
|
+
modified: number;
|
|
364
|
+
refs: {
|
|
365
|
+
docs?: string | undefined;
|
|
366
|
+
studio?: string | undefined;
|
|
367
|
+
};
|
|
368
|
+
queried: Record<string, any>;
|
|
369
|
+
parameters: Record<string, string[]>;
|
|
370
|
+
next_param?: string | undefined;
|
|
371
|
+
}>;
|
|
372
|
+
/**
|
|
373
|
+
* Metric list response schema
|
|
374
|
+
*/
|
|
375
|
+
export declare const MetricListResponseSchema: z.ZodArray<z.ZodString, "many">;
|
|
376
|
+
/**
|
|
377
|
+
* Metric metadata response type
|
|
378
|
+
*/
|
|
379
|
+
export type MetricMetadataResponse = z.infer<typeof MetricMetadataResponseSchema>;
|
|
380
|
+
/**
|
|
381
|
+
* Metric list response type
|
|
382
|
+
*/
|
|
383
|
+
export type MetricListResponse = z.infer<typeof MetricListResponseSchema>;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MetricListResponseSchema = exports.MetricMetadataResponseSchema = exports.MetricMetadataSchema = exports.MetricDataTypeSchema = exports.MetricTierSchema = exports.AssetMetadataResponseSchema = exports.AssetMetadataSchema = exports.AssetBlockchainSchema = exports.ExternalIdsSchema = exports.ExternalIdSourceSchema = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Metadata response types
|
|
6
|
+
*/
|
|
7
|
+
const zod_1 = require("zod");
|
|
8
|
+
/**
|
|
9
|
+
* External identifier sources schema
|
|
10
|
+
*/
|
|
11
|
+
exports.ExternalIdSourceSchema = zod_1.z.enum(['ccdata', 'coinmarketcap', 'coingecko']);
|
|
12
|
+
/**
|
|
13
|
+
* External identifiers for an asset schema
|
|
14
|
+
*/
|
|
15
|
+
exports.ExternalIdsSchema = zod_1.z.record(exports.ExternalIdSourceSchema, zod_1.z.string().optional());
|
|
16
|
+
/**
|
|
17
|
+
* Blockchain information for an asset schema
|
|
18
|
+
*/
|
|
19
|
+
exports.AssetBlockchainSchema = zod_1.z.object({
|
|
20
|
+
/**
|
|
21
|
+
* Blockchain name
|
|
22
|
+
*/
|
|
23
|
+
blockchain: zod_1.z.string(),
|
|
24
|
+
/**
|
|
25
|
+
* Token address on the blockchain
|
|
26
|
+
*/
|
|
27
|
+
address: zod_1.z.string(),
|
|
28
|
+
/**
|
|
29
|
+
* Number of decimal places
|
|
30
|
+
*/
|
|
31
|
+
decimals: zod_1.z.number().int().nonnegative(),
|
|
32
|
+
/**
|
|
33
|
+
* Whether on-chain metrics are supported
|
|
34
|
+
*/
|
|
35
|
+
on_chain_support: zod_1.z.boolean(),
|
|
36
|
+
});
|
|
37
|
+
/**
|
|
38
|
+
* Asset metadata schema
|
|
39
|
+
*/
|
|
40
|
+
exports.AssetMetadataSchema = zod_1.z.object({
|
|
41
|
+
/**
|
|
42
|
+
* Asset identifier
|
|
43
|
+
*/
|
|
44
|
+
id: zod_1.z.string(),
|
|
45
|
+
/**
|
|
46
|
+
* Asset symbol (e.g., "BTC", "ETH")
|
|
47
|
+
*/
|
|
48
|
+
symbol: zod_1.z.string(),
|
|
49
|
+
/**
|
|
50
|
+
* Asset name (e.g., "Bitcoin", "Ethereum")
|
|
51
|
+
*/
|
|
52
|
+
name: zod_1.z.string(),
|
|
53
|
+
/**
|
|
54
|
+
* Type of asset (e.g., "coin", "token")
|
|
55
|
+
*/
|
|
56
|
+
asset_type: zod_1.z.string(),
|
|
57
|
+
/**
|
|
58
|
+
* External identifiers for this asset
|
|
59
|
+
*/
|
|
60
|
+
external_ids: exports.ExternalIdsSchema,
|
|
61
|
+
/**
|
|
62
|
+
* Blockchain information for this asset
|
|
63
|
+
*/
|
|
64
|
+
blockchains: zod_1.z.array(exports.AssetBlockchainSchema),
|
|
65
|
+
});
|
|
66
|
+
/**
|
|
67
|
+
* Asset metadata response schema
|
|
68
|
+
*/
|
|
69
|
+
exports.AssetMetadataResponseSchema = zod_1.z.array(exports.AssetMetadataSchema);
|
|
70
|
+
/**
|
|
71
|
+
* Metric tier schema
|
|
72
|
+
*/
|
|
73
|
+
exports.MetricTierSchema = zod_1.z.enum(['free', 'tier1', 'tier2', 'tier3', 'tier4', 'tier5']);
|
|
74
|
+
/**
|
|
75
|
+
* Metric data type schema
|
|
76
|
+
*/
|
|
77
|
+
exports.MetricDataTypeSchema = zod_1.z.enum(['average', 'sum', 'count', 'percentage', 'ratio']);
|
|
78
|
+
/**
|
|
79
|
+
* Metric metadata schema
|
|
80
|
+
*/
|
|
81
|
+
exports.MetricMetadataSchema = zod_1.z.object({
|
|
82
|
+
/**
|
|
83
|
+
* Metric name
|
|
84
|
+
*/
|
|
85
|
+
path: zod_1.z.string(),
|
|
86
|
+
/**
|
|
87
|
+
* Access tier required for this metric
|
|
88
|
+
*/
|
|
89
|
+
tier: zod_1.z.number().int().nonnegative(),
|
|
90
|
+
/**
|
|
91
|
+
* The last date that the metadata was updated
|
|
92
|
+
*/
|
|
93
|
+
modified: zod_1.z.number().transform((val) => new Date(val * 1000)),
|
|
94
|
+
/**
|
|
95
|
+
* Next parameter for the metric
|
|
96
|
+
*/
|
|
97
|
+
next_param: zod_1.z.string().optional(),
|
|
98
|
+
/**
|
|
99
|
+
* Available assets for this metric
|
|
100
|
+
*/
|
|
101
|
+
refs: zod_1.z.object({
|
|
102
|
+
docs: zod_1.z.string().optional(),
|
|
103
|
+
studio: zod_1.z.string().optional(),
|
|
104
|
+
}),
|
|
105
|
+
/**
|
|
106
|
+
* Queried parameters for the metric
|
|
107
|
+
*/
|
|
108
|
+
queried: zod_1.z.record(zod_1.z.string(), zod_1.z.any()),
|
|
109
|
+
/**
|
|
110
|
+
* List of all allowed parameters and their values for the metric
|
|
111
|
+
*/
|
|
112
|
+
parameters: zod_1.z.record(zod_1.z.string(), zod_1.z.array(zod_1.z.string())),
|
|
113
|
+
});
|
|
114
|
+
/**
|
|
115
|
+
* Metric metadata response schema
|
|
116
|
+
*/
|
|
117
|
+
exports.MetricMetadataResponseSchema = exports.MetricMetadataSchema;
|
|
118
|
+
/**
|
|
119
|
+
* Metric list response schema
|
|
120
|
+
*/
|
|
121
|
+
exports.MetricListResponseSchema = zod_1.z.array(zod_1.z.string().startsWith('/'));
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Generic API response schema
|
|
4
|
+
*/
|
|
5
|
+
export declare const ResponseSchema: <T extends z.ZodTypeAny>(dataSchema: T) => z.ZodObject<{
|
|
6
|
+
/**
|
|
7
|
+
* Response data
|
|
8
|
+
*/
|
|
9
|
+
data: T;
|
|
10
|
+
}, "strip", z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
|
|
11
|
+
/**
|
|
12
|
+
* Response data
|
|
13
|
+
*/
|
|
14
|
+
data: T;
|
|
15
|
+
}>, any> extends infer T_1 ? { [k in keyof T_1]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
|
|
16
|
+
/**
|
|
17
|
+
* Response data
|
|
18
|
+
*/
|
|
19
|
+
data: T;
|
|
20
|
+
}>, any>[k]; } : never, z.baseObjectInputType<{
|
|
21
|
+
/**
|
|
22
|
+
* Response data
|
|
23
|
+
*/
|
|
24
|
+
data: T;
|
|
25
|
+
}> extends infer T_2 ? { [k_1 in keyof T_2]: z.baseObjectInputType<{
|
|
26
|
+
/**
|
|
27
|
+
* Response data
|
|
28
|
+
*/
|
|
29
|
+
data: T;
|
|
30
|
+
}>[k_1]; } : never>;
|
|
31
|
+
/**
|
|
32
|
+
* Generic API response type
|
|
33
|
+
*/
|
|
34
|
+
export type Response<T> = {
|
|
35
|
+
/**
|
|
36
|
+
* Response data
|
|
37
|
+
*/
|
|
38
|
+
data: T;
|
|
39
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ResponseSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
/**
|
|
6
|
+
* Generic API response schema
|
|
7
|
+
*/
|
|
8
|
+
const ResponseSchema = (dataSchema) => zod_1.z.object({
|
|
9
|
+
/**
|
|
10
|
+
* Response data
|
|
11
|
+
*/
|
|
12
|
+
data: dataSchema
|
|
13
|
+
});
|
|
14
|
+
exports.ResponseSchema = ResponseSchema;
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "glassnode-api",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Node.js client for the Glassnode API",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"test": "jest",
|
|
13
|
+
"lint": "eslint .",
|
|
14
|
+
"format": "prettier --write .",
|
|
15
|
+
"prepare": "husky",
|
|
16
|
+
"prepublishOnly": "npm run build",
|
|
17
|
+
"preversion": "npm run lint",
|
|
18
|
+
"version": "npm run format && git add -A src",
|
|
19
|
+
"postversion": "git push && git push --tags"
|
|
20
|
+
},
|
|
21
|
+
"author": "Jordi Planadecursach",
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"zod": "^3.24.4"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@eslint/js": "^9.26.0",
|
|
28
|
+
"@types/jest": "^29.5.14",
|
|
29
|
+
"@types/node": "^22.15.17",
|
|
30
|
+
"eslint": "^9.26.0",
|
|
31
|
+
"husky": "^9.1.7",
|
|
32
|
+
"jest": "^29.7.0",
|
|
33
|
+
"lint-staged": "^16.0.0",
|
|
34
|
+
"prettier": "^3.5.3",
|
|
35
|
+
"ts-jest": "^29.3.2",
|
|
36
|
+
"typescript": "^5.8.3",
|
|
37
|
+
"typescript-eslint": "^8.32.0"
|
|
38
|
+
},
|
|
39
|
+
"lint-staged": {
|
|
40
|
+
"*.{js,ts,mjs}": [
|
|
41
|
+
"eslint --fix",
|
|
42
|
+
"prettier --write",
|
|
43
|
+
"jest --findRelatedTests --passWithNoTests"
|
|
44
|
+
]
|
|
45
|
+
},
|
|
46
|
+
"module": "NodeNext"
|
|
47
|
+
}
|