glassnode-api 0.1.4 → 0.7.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.
- package/README.md +68 -36
- package/dist/errors.d.ts +6 -0
- package/dist/errors.js +25 -0
- package/dist/{src/glassnode-api.d.ts → glassnode-api.d.ts} +12 -1
- package/dist/glassnode-api.esm.min.js +2 -0
- package/dist/glassnode-api.esm.min.js.map +1 -0
- package/dist/{src/glassnode-api.js → glassnode-api.js} +49 -14
- package/dist/glassnode-api.umd.min.js +2 -0
- package/dist/glassnode-api.umd.min.js.map +1 -0
- package/dist/{src/index.d.ts → index.d.ts} +1 -0
- package/dist/{src/index.js → index.js} +1 -0
- package/dist/types/config.d.ts +24 -0
- package/dist/types/config.js +38 -0
- package/dist/types/metadata.d.ts +242 -0
- package/dist/{src/types → types}/metadata.js +55 -5
- package/package.json +39 -28
- package/dist/examples/metadata.validation.d.ts +0 -1
- package/dist/examples/metadata.validation.js +0 -126
- package/dist/examples/metric.dump.d.ts +0 -1
- package/dist/examples/metric.dump.js +0 -28
- package/dist/src/types/config.d.ts +0 -25
- package/dist/src/types/config.js +0 -18
- package/dist/src/types/metadata.d.ts +0 -383
|
@@ -15,5 +15,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./glassnode-api"), exports);
|
|
18
|
+
__exportStar(require("./errors"), exports);
|
|
18
19
|
__exportStar(require("./types/config"), exports);
|
|
19
20
|
__exportStar(require("./types/metadata"), exports);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Logger function type for API call logging
|
|
4
|
+
*/
|
|
5
|
+
export type Logger = (message: string, ...args: unknown[]) => void;
|
|
6
|
+
/**
|
|
7
|
+
* Fetch function type matching the standard fetch API
|
|
8
|
+
*/
|
|
9
|
+
export type FetchFn = typeof fetch;
|
|
10
|
+
/**
|
|
11
|
+
* Zod schema for Glassnode API configuration
|
|
12
|
+
*/
|
|
13
|
+
export declare const GlassnodeConfigSchema: z.ZodObject<{
|
|
14
|
+
apiKey: z.ZodString;
|
|
15
|
+
apiUrl: z.ZodDefault<z.ZodString>;
|
|
16
|
+
logger: z.ZodOptional<z.ZodFunction<z.core.$ZodFunctionArgs, z.core.$ZodFunctionOut>>;
|
|
17
|
+
fetch: z.ZodOptional<z.ZodFunction<z.core.$ZodFunctionArgs, z.core.$ZodFunctionOut>>;
|
|
18
|
+
maxRetries: z.ZodDefault<z.ZodNumber>;
|
|
19
|
+
retryDelay: z.ZodDefault<z.ZodNumber>;
|
|
20
|
+
}, z.core.$strip>;
|
|
21
|
+
/**
|
|
22
|
+
* Configuration for the Glassnode API client
|
|
23
|
+
*/
|
|
24
|
+
export type GlassnodeConfig = z.input<typeof GlassnodeConfigSchema>;
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
/**
|
|
19
|
+
* Optional logger for API call debugging
|
|
20
|
+
* @example { logger: console.log }
|
|
21
|
+
*/
|
|
22
|
+
logger: zod_1.z.function().optional(),
|
|
23
|
+
/**
|
|
24
|
+
* Optional custom fetch function (e.g. for custom headers, retries, or testing)
|
|
25
|
+
* @default globalThis.fetch
|
|
26
|
+
*/
|
|
27
|
+
fetch: zod_1.z.function().optional(),
|
|
28
|
+
/**
|
|
29
|
+
* Maximum number of retries for retryable errors (429 and 5xx)
|
|
30
|
+
* @default 0 (no retries)
|
|
31
|
+
*/
|
|
32
|
+
maxRetries: zod_1.z.number().int().nonnegative().default(0),
|
|
33
|
+
/**
|
|
34
|
+
* Base delay in milliseconds between retries (doubles each attempt)
|
|
35
|
+
* @default 1000
|
|
36
|
+
*/
|
|
37
|
+
retryDelay: zod_1.z.number().int().positive().default(1000),
|
|
38
|
+
});
|
|
@@ -0,0 +1,242 @@
|
|
|
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<{
|
|
9
|
+
ccdata: "ccdata";
|
|
10
|
+
coinmarketcap: "coinmarketcap";
|
|
11
|
+
coingecko: "coingecko";
|
|
12
|
+
}>;
|
|
13
|
+
/**
|
|
14
|
+
* External identifier sources type
|
|
15
|
+
*/
|
|
16
|
+
export type ExternalIdSource = z.infer<typeof ExternalIdSourceSchema>;
|
|
17
|
+
/**
|
|
18
|
+
* External identifiers for an asset schema
|
|
19
|
+
*/
|
|
20
|
+
export declare const ExternalIdsSchema: z.ZodRecord<z.ZodEnum<{
|
|
21
|
+
ccdata: "ccdata";
|
|
22
|
+
coinmarketcap: "coinmarketcap";
|
|
23
|
+
coingecko: "coingecko";
|
|
24
|
+
}>, z.ZodOptional<z.ZodString>>;
|
|
25
|
+
/**
|
|
26
|
+
* External identifiers for an asset type
|
|
27
|
+
*/
|
|
28
|
+
export type ExternalIds = z.infer<typeof ExternalIdsSchema>;
|
|
29
|
+
/**
|
|
30
|
+
* Blockchain information for an asset schema
|
|
31
|
+
*/
|
|
32
|
+
export declare const AssetBlockchainSchema: z.ZodObject<{
|
|
33
|
+
blockchain: z.ZodString;
|
|
34
|
+
address: z.ZodString;
|
|
35
|
+
decimals: z.ZodNumber;
|
|
36
|
+
on_chain_support: z.ZodBoolean;
|
|
37
|
+
}, z.core.$strip>;
|
|
38
|
+
/**
|
|
39
|
+
* Blockchain information for an asset type
|
|
40
|
+
*/
|
|
41
|
+
export type AssetBlockchain = z.infer<typeof AssetBlockchainSchema>;
|
|
42
|
+
/**
|
|
43
|
+
* Asset metadata schema
|
|
44
|
+
*/
|
|
45
|
+
export declare const AssetMetadataSchema: z.ZodObject<{
|
|
46
|
+
id: z.ZodString;
|
|
47
|
+
symbol: z.ZodString;
|
|
48
|
+
name: z.ZodString;
|
|
49
|
+
asset_type: z.ZodString;
|
|
50
|
+
external_ids: z.ZodRecord<z.ZodEnum<{
|
|
51
|
+
ccdata: "ccdata";
|
|
52
|
+
coinmarketcap: "coinmarketcap";
|
|
53
|
+
coingecko: "coingecko";
|
|
54
|
+
}>, z.ZodOptional<z.ZodString>>;
|
|
55
|
+
blockchains: z.ZodArray<z.ZodObject<{
|
|
56
|
+
blockchain: z.ZodString;
|
|
57
|
+
address: z.ZodString;
|
|
58
|
+
decimals: z.ZodNumber;
|
|
59
|
+
on_chain_support: z.ZodBoolean;
|
|
60
|
+
}, z.core.$strip>>;
|
|
61
|
+
}, z.core.$strip>;
|
|
62
|
+
/**
|
|
63
|
+
* Asset metadata type
|
|
64
|
+
*/
|
|
65
|
+
export type AssetMetadata = z.infer<typeof AssetMetadataSchema>;
|
|
66
|
+
/**
|
|
67
|
+
* Asset metadata response schema
|
|
68
|
+
*/
|
|
69
|
+
export declare const AssetMetadataResponseSchema: z.ZodArray<z.ZodObject<{
|
|
70
|
+
id: z.ZodString;
|
|
71
|
+
symbol: z.ZodString;
|
|
72
|
+
name: z.ZodString;
|
|
73
|
+
asset_type: z.ZodString;
|
|
74
|
+
external_ids: z.ZodRecord<z.ZodEnum<{
|
|
75
|
+
ccdata: "ccdata";
|
|
76
|
+
coinmarketcap: "coinmarketcap";
|
|
77
|
+
coingecko: "coingecko";
|
|
78
|
+
}>, z.ZodOptional<z.ZodString>>;
|
|
79
|
+
blockchains: z.ZodArray<z.ZodObject<{
|
|
80
|
+
blockchain: z.ZodString;
|
|
81
|
+
address: z.ZodString;
|
|
82
|
+
decimals: z.ZodNumber;
|
|
83
|
+
on_chain_support: z.ZodBoolean;
|
|
84
|
+
}, z.core.$strip>>;
|
|
85
|
+
}, z.core.$strip>>;
|
|
86
|
+
/**
|
|
87
|
+
* Asset metadata response type
|
|
88
|
+
*/
|
|
89
|
+
export type AssetMetadataResponse = z.infer<typeof AssetMetadataResponseSchema>;
|
|
90
|
+
/**
|
|
91
|
+
* Metric tier schema
|
|
92
|
+
*/
|
|
93
|
+
export declare const MetricTierSchema: z.ZodEnum<{
|
|
94
|
+
free: "free";
|
|
95
|
+
tier1: "tier1";
|
|
96
|
+
tier2: "tier2";
|
|
97
|
+
tier3: "tier3";
|
|
98
|
+
tier4: "tier4";
|
|
99
|
+
tier5: "tier5";
|
|
100
|
+
}>;
|
|
101
|
+
/**
|
|
102
|
+
* Metric tier type
|
|
103
|
+
*/
|
|
104
|
+
export type MetricTier = z.infer<typeof MetricTierSchema>;
|
|
105
|
+
/**
|
|
106
|
+
* Metric data type schema
|
|
107
|
+
*/
|
|
108
|
+
export declare const MetricDataTypeSchema: z.ZodEnum<{
|
|
109
|
+
ratio: "ratio";
|
|
110
|
+
sum: "sum";
|
|
111
|
+
average: "average";
|
|
112
|
+
count: "count";
|
|
113
|
+
percentage: "percentage";
|
|
114
|
+
}>;
|
|
115
|
+
/**
|
|
116
|
+
* Metric data type
|
|
117
|
+
*/
|
|
118
|
+
export type MetricDataType = z.infer<typeof MetricDataTypeSchema>;
|
|
119
|
+
/**
|
|
120
|
+
* Metric descriptors schema (human-readable names, tags, descriptions)
|
|
121
|
+
*/
|
|
122
|
+
export declare const MetricDescriptorsSchema: z.ZodObject<{
|
|
123
|
+
name: z.ZodOptional<z.ZodString>;
|
|
124
|
+
short_name: z.ZodOptional<z.ZodString>;
|
|
125
|
+
group: z.ZodOptional<z.ZodString>;
|
|
126
|
+
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
127
|
+
description: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
128
|
+
data_sharing_group: z.ZodOptional<z.ZodString>;
|
|
129
|
+
}, z.core.$strip>;
|
|
130
|
+
/**
|
|
131
|
+
* Metric descriptors type
|
|
132
|
+
*/
|
|
133
|
+
export type MetricDescriptors = z.infer<typeof MetricDescriptorsSchema>;
|
|
134
|
+
/**
|
|
135
|
+
* Metric metadata schema
|
|
136
|
+
*/
|
|
137
|
+
export declare const MetricMetadataSchema: z.ZodObject<{
|
|
138
|
+
path: z.ZodString;
|
|
139
|
+
tier: z.ZodNumber;
|
|
140
|
+
modified: z.ZodPipe<z.ZodOptional<z.ZodNumber>, z.ZodTransform<Date | undefined, number | undefined>>;
|
|
141
|
+
is_pit: z.ZodOptional<z.ZodBoolean>;
|
|
142
|
+
bulk_supported: z.ZodOptional<z.ZodBoolean>;
|
|
143
|
+
timerange: z.ZodOptional<z.ZodObject<{
|
|
144
|
+
min: z.ZodNumber;
|
|
145
|
+
max: z.ZodNumber;
|
|
146
|
+
}, z.core.$strip>>;
|
|
147
|
+
refs: z.ZodObject<{
|
|
148
|
+
docs: z.ZodOptional<z.ZodString>;
|
|
149
|
+
studio: z.ZodOptional<z.ZodString>;
|
|
150
|
+
metric_variant: z.ZodOptional<z.ZodObject<{
|
|
151
|
+
base: z.ZodOptional<z.ZodString>;
|
|
152
|
+
bulk: z.ZodOptional<z.ZodString>;
|
|
153
|
+
pit: z.ZodOptional<z.ZodString>;
|
|
154
|
+
}, z.core.$strip>>;
|
|
155
|
+
}, z.core.$strip>;
|
|
156
|
+
queried: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
157
|
+
parameters: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>;
|
|
158
|
+
descriptors: z.ZodOptional<z.ZodObject<{
|
|
159
|
+
name: z.ZodOptional<z.ZodString>;
|
|
160
|
+
short_name: z.ZodOptional<z.ZodString>;
|
|
161
|
+
group: z.ZodOptional<z.ZodString>;
|
|
162
|
+
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
163
|
+
description: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
164
|
+
data_sharing_group: z.ZodOptional<z.ZodString>;
|
|
165
|
+
}, z.core.$strip>>;
|
|
166
|
+
}, z.core.$strip>;
|
|
167
|
+
/**
|
|
168
|
+
* Metric metadata type
|
|
169
|
+
*/
|
|
170
|
+
export type MetricMetadata = z.infer<typeof MetricMetadataSchema>;
|
|
171
|
+
/**
|
|
172
|
+
* Metric metadata response schema
|
|
173
|
+
*/
|
|
174
|
+
export declare const MetricMetadataResponseSchema: z.ZodObject<{
|
|
175
|
+
path: z.ZodString;
|
|
176
|
+
tier: z.ZodNumber;
|
|
177
|
+
modified: z.ZodPipe<z.ZodOptional<z.ZodNumber>, z.ZodTransform<Date | undefined, number | undefined>>;
|
|
178
|
+
is_pit: z.ZodOptional<z.ZodBoolean>;
|
|
179
|
+
bulk_supported: z.ZodOptional<z.ZodBoolean>;
|
|
180
|
+
timerange: z.ZodOptional<z.ZodObject<{
|
|
181
|
+
min: z.ZodNumber;
|
|
182
|
+
max: z.ZodNumber;
|
|
183
|
+
}, z.core.$strip>>;
|
|
184
|
+
refs: z.ZodObject<{
|
|
185
|
+
docs: z.ZodOptional<z.ZodString>;
|
|
186
|
+
studio: z.ZodOptional<z.ZodString>;
|
|
187
|
+
metric_variant: z.ZodOptional<z.ZodObject<{
|
|
188
|
+
base: z.ZodOptional<z.ZodString>;
|
|
189
|
+
bulk: z.ZodOptional<z.ZodString>;
|
|
190
|
+
pit: z.ZodOptional<z.ZodString>;
|
|
191
|
+
}, z.core.$strip>>;
|
|
192
|
+
}, z.core.$strip>;
|
|
193
|
+
queried: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
194
|
+
parameters: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>;
|
|
195
|
+
descriptors: z.ZodOptional<z.ZodObject<{
|
|
196
|
+
name: z.ZodOptional<z.ZodString>;
|
|
197
|
+
short_name: z.ZodOptional<z.ZodString>;
|
|
198
|
+
group: z.ZodOptional<z.ZodString>;
|
|
199
|
+
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
200
|
+
description: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
201
|
+
data_sharing_group: z.ZodOptional<z.ZodString>;
|
|
202
|
+
}, z.core.$strip>>;
|
|
203
|
+
}, z.core.$strip>;
|
|
204
|
+
/**
|
|
205
|
+
* Metric list response schema
|
|
206
|
+
*/
|
|
207
|
+
export declare const MetricListResponseSchema: z.ZodArray<z.ZodString>;
|
|
208
|
+
/**
|
|
209
|
+
* Metric metadata response type
|
|
210
|
+
*/
|
|
211
|
+
export type MetricMetadataResponse = z.infer<typeof MetricMetadataResponseSchema>;
|
|
212
|
+
/**
|
|
213
|
+
* Metric list response type
|
|
214
|
+
*/
|
|
215
|
+
export type MetricListResponse = z.infer<typeof MetricListResponseSchema>;
|
|
216
|
+
/**
|
|
217
|
+
* Bulk entry schema (one asset's value in a bulk response)
|
|
218
|
+
*/
|
|
219
|
+
export declare const BulkEntrySchema: z.ZodObject<{
|
|
220
|
+
a: z.ZodString;
|
|
221
|
+
v: z.ZodNumber;
|
|
222
|
+
network: z.ZodOptional<z.ZodString>;
|
|
223
|
+
}, z.core.$strip>;
|
|
224
|
+
/**
|
|
225
|
+
* Bulk entry type
|
|
226
|
+
*/
|
|
227
|
+
export type BulkEntry = z.infer<typeof BulkEntrySchema>;
|
|
228
|
+
/**
|
|
229
|
+
* Bulk response schema (array of timestamped bulk entries)
|
|
230
|
+
*/
|
|
231
|
+
export declare const BulkResponseSchema: z.ZodArray<z.ZodObject<{
|
|
232
|
+
t: z.ZodNumber;
|
|
233
|
+
bulk: z.ZodArray<z.ZodObject<{
|
|
234
|
+
a: z.ZodString;
|
|
235
|
+
v: z.ZodNumber;
|
|
236
|
+
network: z.ZodOptional<z.ZodString>;
|
|
237
|
+
}, z.core.$strip>>;
|
|
238
|
+
}, z.core.$strip>>;
|
|
239
|
+
/**
|
|
240
|
+
* Bulk response type
|
|
241
|
+
*/
|
|
242
|
+
export type BulkResponse = z.infer<typeof BulkResponseSchema>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
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;
|
|
3
|
+
exports.BulkResponseSchema = exports.BulkEntrySchema = exports.MetricListResponseSchema = exports.MetricMetadataResponseSchema = exports.MetricMetadataSchema = exports.MetricDescriptorsSchema = exports.MetricDataTypeSchema = exports.MetricTierSchema = exports.AssetMetadataResponseSchema = exports.AssetMetadataSchema = exports.AssetBlockchainSchema = exports.ExternalIdsSchema = exports.ExternalIdSourceSchema = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Metadata response types
|
|
6
6
|
*/
|
|
@@ -75,12 +75,23 @@ exports.MetricTierSchema = zod_1.z.enum(['free', 'tier1', 'tier2', 'tier3', 'tie
|
|
|
75
75
|
* Metric data type schema
|
|
76
76
|
*/
|
|
77
77
|
exports.MetricDataTypeSchema = zod_1.z.enum(['average', 'sum', 'count', 'percentage', 'ratio']);
|
|
78
|
+
/**
|
|
79
|
+
* Metric descriptors schema (human-readable names, tags, descriptions)
|
|
80
|
+
*/
|
|
81
|
+
exports.MetricDescriptorsSchema = zod_1.z.object({
|
|
82
|
+
name: zod_1.z.string().optional(),
|
|
83
|
+
short_name: zod_1.z.string().optional(),
|
|
84
|
+
group: zod_1.z.string().optional(),
|
|
85
|
+
tags: zod_1.z.array(zod_1.z.string()).optional(),
|
|
86
|
+
description: zod_1.z.record(zod_1.z.string(), zod_1.z.string()).optional(),
|
|
87
|
+
data_sharing_group: zod_1.z.string().optional(),
|
|
88
|
+
});
|
|
78
89
|
/**
|
|
79
90
|
* Metric metadata schema
|
|
80
91
|
*/
|
|
81
92
|
exports.MetricMetadataSchema = zod_1.z.object({
|
|
82
93
|
/**
|
|
83
|
-
* Metric
|
|
94
|
+
* Metric path
|
|
84
95
|
*/
|
|
85
96
|
path: zod_1.z.string(),
|
|
86
97
|
/**
|
|
@@ -95,15 +106,35 @@ exports.MetricMetadataSchema = zod_1.z.object({
|
|
|
95
106
|
.optional()
|
|
96
107
|
.transform((val) => (val ? new Date(val * 1000) : undefined)),
|
|
97
108
|
/**
|
|
98
|
-
*
|
|
109
|
+
* Whether this is a point-in-time metric
|
|
110
|
+
*/
|
|
111
|
+
is_pit: zod_1.z.boolean().optional(),
|
|
112
|
+
/**
|
|
113
|
+
* Whether bulk queries are supported for this metric
|
|
114
|
+
*/
|
|
115
|
+
bulk_supported: zod_1.z.boolean().optional(),
|
|
116
|
+
/**
|
|
117
|
+
* Available time range for this metric (Unix timestamps)
|
|
99
118
|
*/
|
|
100
|
-
|
|
119
|
+
timerange: zod_1.z
|
|
120
|
+
.object({
|
|
121
|
+
min: zod_1.z.number(),
|
|
122
|
+
max: zod_1.z.number(),
|
|
123
|
+
})
|
|
124
|
+
.optional(),
|
|
101
125
|
/**
|
|
102
|
-
*
|
|
126
|
+
* Reference links for this metric
|
|
103
127
|
*/
|
|
104
128
|
refs: zod_1.z.object({
|
|
105
129
|
docs: zod_1.z.string().optional(),
|
|
106
130
|
studio: zod_1.z.string().optional(),
|
|
131
|
+
metric_variant: zod_1.z
|
|
132
|
+
.object({
|
|
133
|
+
base: zod_1.z.string().optional(),
|
|
134
|
+
bulk: zod_1.z.string().optional(),
|
|
135
|
+
pit: zod_1.z.string().optional(),
|
|
136
|
+
})
|
|
137
|
+
.optional(),
|
|
107
138
|
}),
|
|
108
139
|
/**
|
|
109
140
|
* Queried parameters for the metric
|
|
@@ -113,6 +144,10 @@ exports.MetricMetadataSchema = zod_1.z.object({
|
|
|
113
144
|
* List of all allowed parameters and their values for the metric
|
|
114
145
|
*/
|
|
115
146
|
parameters: zod_1.z.record(zod_1.z.string(), zod_1.z.array(zod_1.z.string())),
|
|
147
|
+
/**
|
|
148
|
+
* Human-readable descriptors (name, tags, description)
|
|
149
|
+
*/
|
|
150
|
+
descriptors: exports.MetricDescriptorsSchema.optional(),
|
|
116
151
|
});
|
|
117
152
|
/**
|
|
118
153
|
* Metric metadata response schema
|
|
@@ -122,3 +157,18 @@ exports.MetricMetadataResponseSchema = exports.MetricMetadataSchema;
|
|
|
122
157
|
* Metric list response schema
|
|
123
158
|
*/
|
|
124
159
|
exports.MetricListResponseSchema = zod_1.z.array(zod_1.z.string().startsWith('/'));
|
|
160
|
+
/**
|
|
161
|
+
* Bulk entry schema (one asset's value in a bulk response)
|
|
162
|
+
*/
|
|
163
|
+
exports.BulkEntrySchema = zod_1.z.object({
|
|
164
|
+
a: zod_1.z.string(),
|
|
165
|
+
v: zod_1.z.number(),
|
|
166
|
+
network: zod_1.z.string().optional(),
|
|
167
|
+
});
|
|
168
|
+
/**
|
|
169
|
+
* Bulk response schema (array of timestamped bulk entries)
|
|
170
|
+
*/
|
|
171
|
+
exports.BulkResponseSchema = zod_1.z.array(zod_1.z.object({
|
|
172
|
+
t: zod_1.z.number(),
|
|
173
|
+
bulk: zod_1.z.array(exports.BulkEntrySchema),
|
|
174
|
+
}));
|
package/package.json
CHANGED
|
@@ -1,44 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "glassnode-api",
|
|
3
|
-
"version": "0.1
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.7.1",
|
|
4
|
+
"description": "Typescript client for the Glassnode API (Node.js and Browser)",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
+
"browser": "dist/glassnode-api.umd.min.js",
|
|
8
|
+
"module": "dist/glassnode-api.esm.min.js",
|
|
7
9
|
"files": [
|
|
8
|
-
"dist"
|
|
10
|
+
"dist/*.js",
|
|
11
|
+
"dist/*.d.ts",
|
|
12
|
+
"dist/glassnode-api.*.min.js",
|
|
13
|
+
"dist/glassnode-api.*.min.js.map",
|
|
14
|
+
"dist/types"
|
|
9
15
|
],
|
|
10
16
|
"repository": {
|
|
11
17
|
"type": "git",
|
|
12
|
-
"url": "git+https://github.com/planadecu/glassnode-api
|
|
13
|
-
},
|
|
14
|
-
"scripts": {
|
|
15
|
-
"build": "tsc",
|
|
16
|
-
"test": "jest",
|
|
17
|
-
"lint": "eslint .",
|
|
18
|
-
"format": "prettier --write .",
|
|
19
|
-
"prepare": "husky",
|
|
20
|
-
"prepublishOnly": "npm run build",
|
|
21
|
-
"preversion": "npm run lint",
|
|
22
|
-
"version": "npm run format && git add -A src",
|
|
23
|
-
"postversion": "git push && git push --tags"
|
|
18
|
+
"url": "git+https://github.com/planadecu/glassnode-api.git"
|
|
24
19
|
},
|
|
25
20
|
"author": "Jordi Planadecursach",
|
|
26
21
|
"license": "MIT",
|
|
27
22
|
"dependencies": {
|
|
28
|
-
"zod": "^3.
|
|
23
|
+
"zod": "^4.3.6"
|
|
29
24
|
},
|
|
30
25
|
"devDependencies": {
|
|
31
|
-
"@eslint/js": "^
|
|
32
|
-
"@
|
|
33
|
-
"@
|
|
34
|
-
"
|
|
26
|
+
"@eslint/js": "^10.0.1",
|
|
27
|
+
"@rollup/plugin-commonjs": "^29.0.2",
|
|
28
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
29
|
+
"@rollup/plugin-typescript": "^12.3.0",
|
|
30
|
+
"@types/jest": "^30.0.0",
|
|
31
|
+
"@types/node": "^24.12.0",
|
|
32
|
+
"eslint": "^10.0.3",
|
|
35
33
|
"husky": "^9.1.7",
|
|
36
|
-
"jest": "^
|
|
37
|
-
"lint-staged": "^16.
|
|
38
|
-
"prettier": "^3.
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
34
|
+
"jest": "^30.2.0",
|
|
35
|
+
"lint-staged": "^16.3.2",
|
|
36
|
+
"prettier": "^3.8.1",
|
|
37
|
+
"rollup": "^4.59.0",
|
|
38
|
+
"@rollup/plugin-terser": "^1.0.0",
|
|
39
|
+
"ts-jest": "^29.4.6",
|
|
40
|
+
"tslib": "^2.8.1",
|
|
41
|
+
"typescript": "^5.9.3",
|
|
42
|
+
"typescript-eslint": "^8.57.0"
|
|
42
43
|
},
|
|
43
44
|
"lint-staged": {
|
|
44
45
|
"*.{js,ts,mjs}": [
|
|
@@ -47,5 +48,15 @@
|
|
|
47
48
|
"jest --findRelatedTests --passWithNoTests"
|
|
48
49
|
]
|
|
49
50
|
},
|
|
50
|
-
"
|
|
51
|
-
|
|
51
|
+
"scripts": {
|
|
52
|
+
"build": "tsc",
|
|
53
|
+
"build:browser": "rollup -c",
|
|
54
|
+
"test": "jest",
|
|
55
|
+
"test:coverage": "jest --coverage",
|
|
56
|
+
"lint": "eslint .",
|
|
57
|
+
"format": "prettier --write .",
|
|
58
|
+
"preversion": "pnpm run lint",
|
|
59
|
+
"version": "pnpm run format && git add -A src",
|
|
60
|
+
"postversion": "git push && git push --tags"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import 'dotenv/config';
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const src_1 = require("../src");
|
|
4
|
-
const zod_1 = require("zod");
|
|
5
|
-
require("dotenv/config");
|
|
6
|
-
// Create an instance of the API client
|
|
7
|
-
const api = new src_1.GlassnodeAPI({
|
|
8
|
-
apiKey: process.env.GLASSNODE_API_KEY || '', // Get API key from .env file
|
|
9
|
-
});
|
|
10
|
-
async function fetchAssetMetadata() {
|
|
11
|
-
try {
|
|
12
|
-
// Get asset metadata
|
|
13
|
-
console.log('Fetching asset metadata...');
|
|
14
|
-
const assetMetadata = await api.getAssetMetadata();
|
|
15
|
-
// Show total number of assets
|
|
16
|
-
console.log(`Found ${assetMetadata.length} assets in total`);
|
|
17
|
-
// Custom validation: Check if USDC is present in the response
|
|
18
|
-
const USDCSchema = zod_1.z.object({
|
|
19
|
-
symbol: zod_1.z.literal('USDC'),
|
|
20
|
-
name: zod_1.z.literal('USDC'),
|
|
21
|
-
asset_type: zod_1.z.literal('TOKEN'),
|
|
22
|
-
});
|
|
23
|
-
// Create a refine function that looks for USDC
|
|
24
|
-
const usdc = assetMetadata.find((asset) => asset.symbol === 'USDC');
|
|
25
|
-
if (usdc) {
|
|
26
|
-
try {
|
|
27
|
-
USDCSchema.parse(usdc);
|
|
28
|
-
console.log('✅ USDC validation successful');
|
|
29
|
-
// Print 3 first blockchains for USDC
|
|
30
|
-
console.log('First 3 blockchains for USDC:');
|
|
31
|
-
usdc.blockchains.slice(0, 3).forEach((blockchain) => {
|
|
32
|
-
console.log(` - ${blockchain.blockchain} - ${blockchain.address}`);
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
catch (error) {
|
|
36
|
-
if (error instanceof zod_1.z.ZodError) {
|
|
37
|
-
console.error('❌ Schema validation failed:', error.errors);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
throw error;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
console.log('❌ USDC not found in response');
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
catch (error) {
|
|
49
|
-
console.error('Error fetching asset metadata:', error);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
async function fetchMetricList() {
|
|
53
|
-
try {
|
|
54
|
-
console.log('\nFetching metric list...');
|
|
55
|
-
const metricList = await api.getMetricList();
|
|
56
|
-
// Display basic metrics information
|
|
57
|
-
console.log(`Found ${metricList.length} metrics in total`);
|
|
58
|
-
// Check for market metrics
|
|
59
|
-
const marketMetrics = metricList.filter((metric) => metric.startsWith('/market/'));
|
|
60
|
-
if (marketMetrics.length > 0) {
|
|
61
|
-
console.log(`✅ Found ${marketMetrics.length} market metrics`);
|
|
62
|
-
console.log(`First 3 market metrics:`);
|
|
63
|
-
marketMetrics.slice(0, 3).forEach((metric) => console.log(` - ${metric}`));
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
console.log('❌ No market metrics found');
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
catch (error) {
|
|
70
|
-
console.error('Error fetching metric list:', error);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
async function fetchExchangeBalanceMetadata() {
|
|
74
|
-
try {
|
|
75
|
-
console.log('\nFetching exchange balance metadata...');
|
|
76
|
-
const metricPath = '/distribution/balance_exchanges';
|
|
77
|
-
const metadata = await api.getMetricMetadata(metricPath);
|
|
78
|
-
console.log('✅ Exchange balance metadata:');
|
|
79
|
-
console.log(` Path: ${metadata.path}`);
|
|
80
|
-
console.log(` Tier: ${metadata.tier}`);
|
|
81
|
-
console.log(` Modified: ${metadata.modified?.toISOString()}`);
|
|
82
|
-
// Display available parameters
|
|
83
|
-
console.log('\nAvailable parameters:');
|
|
84
|
-
// Only print the firt 3 values per parameter
|
|
85
|
-
Object.entries(metadata.parameters).forEach(([key, values]) => {
|
|
86
|
-
console.log(` ${key}: ${values.slice(0, 3).join(', ')}`);
|
|
87
|
-
});
|
|
88
|
-
// Display documentation links
|
|
89
|
-
if (metadata.refs.docs) {
|
|
90
|
-
console.log(`\nDocumentation: ${metadata.refs.docs}`);
|
|
91
|
-
}
|
|
92
|
-
if (metadata.refs.studio) {
|
|
93
|
-
console.log(`Studio: ${metadata.refs.studio}`);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
catch (error) {
|
|
97
|
-
console.error('Error fetching exchange balance metadata:', error);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
async function fetchExchangeBalanceWithParams() {
|
|
101
|
-
try {
|
|
102
|
-
console.log('\nFetching exchange balance metadata with specific parameters...');
|
|
103
|
-
const metricPath = '/distribution/balance_exchanges';
|
|
104
|
-
const params = { a: 'BTC' };
|
|
105
|
-
const metadata = await api.getMetricMetadata(metricPath, params);
|
|
106
|
-
console.log('✅ Exchange balance metadata for BTC:');
|
|
107
|
-
console.log(` Path: ${metadata.path}`);
|
|
108
|
-
console.log(` Tier: ${metadata.tier}`);
|
|
109
|
-
// Display queried parameters
|
|
110
|
-
console.log('\nQueried parameters:');
|
|
111
|
-
Object.entries(metadata.queried).forEach(([key, value]) => {
|
|
112
|
-
console.log(` ${key}: ${value}`);
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
catch (error) {
|
|
116
|
-
console.error('Error fetching exchange balance metadata with parameters:', error);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
// Execute the examples
|
|
120
|
-
async function runExamples() {
|
|
121
|
-
await fetchAssetMetadata();
|
|
122
|
-
await fetchMetricList();
|
|
123
|
-
await fetchExchangeBalanceMetadata();
|
|
124
|
-
await fetchExchangeBalanceWithParams();
|
|
125
|
-
}
|
|
126
|
-
runExamples();
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import 'dotenv/config';
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const src_1 = require("../src");
|
|
4
|
-
require("dotenv/config");
|
|
5
|
-
// Create an instance of the API client
|
|
6
|
-
const api = new src_1.GlassnodeAPI({
|
|
7
|
-
apiKey: process.env.GLASSNODE_API_KEY || '', // Get API key from .env file
|
|
8
|
-
});
|
|
9
|
-
// Execute the examples
|
|
10
|
-
async function runExamples() {
|
|
11
|
-
//const assetMetadata = await api.getAssetMetadata();
|
|
12
|
-
const metricList = await api.getMetricList();
|
|
13
|
-
for (const metric of metricList.slice(0, 10)) {
|
|
14
|
-
const metricMetadata = await api.getMetricMetadata(metric);
|
|
15
|
-
const params = metricMetadata.parameters;
|
|
16
|
-
// create params object from params array
|
|
17
|
-
const paramsObject = {};
|
|
18
|
-
for (const param of Object.keys(params)) {
|
|
19
|
-
// Fix: params[param] is an array of strings, not an object with values property
|
|
20
|
-
if (Array.isArray(params[param]) && params[param].length > 0) {
|
|
21
|
-
paramsObject[param] = params[param][0];
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
const result = (await api.callMetric(metric, paramsObject));
|
|
25
|
-
console.log(result[0]);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
runExamples();
|