@covalenthq/client-sdk 0.7.6 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/README.md +5 -0
  2. package/dist/cjs/index.js +2762 -199
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/services/BalanceService.d.ts +14 -13
  5. package/dist/cjs/services/BaseService.d.ts +12 -11
  6. package/dist/cjs/services/CovalentClient.d.ts +5 -3
  7. package/dist/cjs/services/NftService.d.ts +18 -17
  8. package/dist/cjs/services/PricingService.d.ts +4 -3
  9. package/dist/cjs/services/SecurityService.d.ts +5 -4
  10. package/dist/cjs/services/TransactionService.d.ts +79 -12
  11. package/dist/cjs/services/XykService.d.ts +226 -15
  12. package/dist/cjs/util/ApiHelpers.d.ts +2 -1
  13. package/dist/cjs/util/backoff.d.ts +2 -1
  14. package/dist/cjs/util/types/TransactionServiceTypes.d.ts +11 -0
  15. package/dist/cjs/util/types/XykServiceTypes.d.ts +114 -0
  16. package/dist/es/index.js +2762 -199
  17. package/dist/es/index.js.map +1 -1
  18. package/dist/es/services/BalanceService.d.ts +14 -13
  19. package/dist/es/services/BaseService.d.ts +12 -11
  20. package/dist/es/services/CovalentClient.d.ts +5 -3
  21. package/dist/es/services/NftService.d.ts +18 -17
  22. package/dist/es/services/PricingService.d.ts +4 -3
  23. package/dist/es/services/SecurityService.d.ts +5 -4
  24. package/dist/es/services/TransactionService.d.ts +79 -12
  25. package/dist/es/services/XykService.d.ts +226 -15
  26. package/dist/es/util/ApiHelpers.d.ts +2 -1
  27. package/dist/es/util/backoff.d.ts +2 -1
  28. package/dist/es/util/types/TransactionServiceTypes.d.ts +11 -0
  29. package/dist/es/util/types/XykServiceTypes.d.ts +114 -0
  30. package/dist/esm/index.js +2762 -199
  31. package/dist/esm/index.js.map +1 -1
  32. package/dist/esm/services/BalanceService.d.ts +14 -13
  33. package/dist/esm/services/BaseService.d.ts +12 -11
  34. package/dist/esm/services/CovalentClient.d.ts +5 -3
  35. package/dist/esm/services/NftService.d.ts +18 -17
  36. package/dist/esm/services/PricingService.d.ts +4 -3
  37. package/dist/esm/services/SecurityService.d.ts +5 -4
  38. package/dist/esm/services/TransactionService.d.ts +79 -12
  39. package/dist/esm/services/XykService.d.ts +226 -15
  40. package/dist/esm/util/ApiHelpers.d.ts +2 -1
  41. package/dist/esm/util/backoff.d.ts +2 -1
  42. package/dist/esm/util/types/TransactionServiceTypes.d.ts +11 -0
  43. package/dist/esm/util/types/XykServiceTypes.d.ts +114 -0
  44. package/dist/services/BalanceService.d.ts +14 -13
  45. package/dist/services/BalanceService.js +16 -15
  46. package/dist/services/BalanceService.js.map +1 -1
  47. package/dist/services/BaseService.d.ts +12 -11
  48. package/dist/services/BaseService.js +25 -24
  49. package/dist/services/BaseService.js.map +1 -1
  50. package/dist/services/CovalentClient.d.ts +5 -3
  51. package/dist/services/CovalentClient.js +17 -17
  52. package/dist/services/CovalentClient.js.map +1 -1
  53. package/dist/services/NftService.d.ts +18 -17
  54. package/dist/services/NftService.js +30 -29
  55. package/dist/services/NftService.js.map +1 -1
  56. package/dist/services/PricingService.d.ts +4 -3
  57. package/dist/services/PricingService.js +4 -3
  58. package/dist/services/PricingService.js.map +1 -1
  59. package/dist/services/SecurityService.d.ts +5 -4
  60. package/dist/services/SecurityService.js +6 -5
  61. package/dist/services/SecurityService.js.map +1 -1
  62. package/dist/services/TransactionService.d.ts +79 -12
  63. package/dist/services/TransactionService.js +369 -41
  64. package/dist/services/TransactionService.js.map +1 -1
  65. package/dist/services/XykService.d.ts +226 -15
  66. package/dist/services/XykService.js +335 -34
  67. package/dist/services/XykService.js.map +1 -1
  68. package/dist/util/ApiHelpers.d.ts +2 -1
  69. package/dist/util/ApiHelpers.js +3 -3
  70. package/dist/util/ApiHelpers.js.map +1 -1
  71. package/dist/util/backoff.d.ts +2 -1
  72. package/dist/util/backoff.js +3 -3
  73. package/dist/util/backoff.js.map +1 -1
  74. package/dist/util/types/TransactionServiceTypes.d.ts +11 -0
  75. package/dist/util/types/XykServiceTypes.d.ts +114 -0
  76. package/package.json +2 -2
package/dist/es/index.js CHANGED
@@ -1,4 +1,5 @@
1
- import chalk from 'chalk';
1
+ import require$$0 from 'os';
2
+ import require$$1 from 'tty';
2
3
  import { parseISO } from 'date-fns';
3
4
  import Big from 'big.js';
4
5
 
@@ -11,7 +12,7 @@ class ExponentialBackoff {
11
12
  this._apiKey = apiKey;
12
13
  this._debug = debug;
13
14
  }
14
- async backOff(url) {
15
+ async backOff(url, source) {
15
16
  try {
16
17
  let startTime;
17
18
  if (this._debug) {
@@ -20,7 +21,7 @@ class ExponentialBackoff {
20
21
  const response = await fetch(url, {
21
22
  headers: {
22
23
  "Authorization": `Bearer ${this._apiKey}`,
23
- "X-Requested-With": userAgent
24
+ "X-Requested-With": source ? source + " " + "(" + userAgent + ")" : userAgent
24
25
  }
25
26
  });
26
27
  debugOutput(response.url, response.status ?? 429, startTime);
@@ -36,7 +37,7 @@ class ExponentialBackoff {
36
37
  this.retryCount++;
37
38
  const delayMs = Math.pow(2, this.retryCount) * BASE_DELAY_MS;
38
39
  await new Promise((resolve) => setTimeout(resolve, delayMs));
39
- return this.backOff(url);
40
+ return this.backOff(url, source);
40
41
  }
41
42
  return Promise.reject(new Error(`Max retries exceeded: ${this.maxRetries}`));
42
43
  }
@@ -51,6 +52,1934 @@ function getDefaultExportFromCjs (x) {
51
52
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
52
53
  }
53
54
 
55
+ var ansiStyles$1 = {exports: {}};
56
+
57
+ var colorName;
58
+ var hasRequiredColorName;
59
+
60
+ function requireColorName () {
61
+ if (hasRequiredColorName) return colorName;
62
+ hasRequiredColorName = 1;
63
+
64
+ colorName = {
65
+ "aliceblue": [240, 248, 255],
66
+ "antiquewhite": [250, 235, 215],
67
+ "aqua": [0, 255, 255],
68
+ "aquamarine": [127, 255, 212],
69
+ "azure": [240, 255, 255],
70
+ "beige": [245, 245, 220],
71
+ "bisque": [255, 228, 196],
72
+ "black": [0, 0, 0],
73
+ "blanchedalmond": [255, 235, 205],
74
+ "blue": [0, 0, 255],
75
+ "blueviolet": [138, 43, 226],
76
+ "brown": [165, 42, 42],
77
+ "burlywood": [222, 184, 135],
78
+ "cadetblue": [95, 158, 160],
79
+ "chartreuse": [127, 255, 0],
80
+ "chocolate": [210, 105, 30],
81
+ "coral": [255, 127, 80],
82
+ "cornflowerblue": [100, 149, 237],
83
+ "cornsilk": [255, 248, 220],
84
+ "crimson": [220, 20, 60],
85
+ "cyan": [0, 255, 255],
86
+ "darkblue": [0, 0, 139],
87
+ "darkcyan": [0, 139, 139],
88
+ "darkgoldenrod": [184, 134, 11],
89
+ "darkgray": [169, 169, 169],
90
+ "darkgreen": [0, 100, 0],
91
+ "darkgrey": [169, 169, 169],
92
+ "darkkhaki": [189, 183, 107],
93
+ "darkmagenta": [139, 0, 139],
94
+ "darkolivegreen": [85, 107, 47],
95
+ "darkorange": [255, 140, 0],
96
+ "darkorchid": [153, 50, 204],
97
+ "darkred": [139, 0, 0],
98
+ "darksalmon": [233, 150, 122],
99
+ "darkseagreen": [143, 188, 143],
100
+ "darkslateblue": [72, 61, 139],
101
+ "darkslategray": [47, 79, 79],
102
+ "darkslategrey": [47, 79, 79],
103
+ "darkturquoise": [0, 206, 209],
104
+ "darkviolet": [148, 0, 211],
105
+ "deeppink": [255, 20, 147],
106
+ "deepskyblue": [0, 191, 255],
107
+ "dimgray": [105, 105, 105],
108
+ "dimgrey": [105, 105, 105],
109
+ "dodgerblue": [30, 144, 255],
110
+ "firebrick": [178, 34, 34],
111
+ "floralwhite": [255, 250, 240],
112
+ "forestgreen": [34, 139, 34],
113
+ "fuchsia": [255, 0, 255],
114
+ "gainsboro": [220, 220, 220],
115
+ "ghostwhite": [248, 248, 255],
116
+ "gold": [255, 215, 0],
117
+ "goldenrod": [218, 165, 32],
118
+ "gray": [128, 128, 128],
119
+ "green": [0, 128, 0],
120
+ "greenyellow": [173, 255, 47],
121
+ "grey": [128, 128, 128],
122
+ "honeydew": [240, 255, 240],
123
+ "hotpink": [255, 105, 180],
124
+ "indianred": [205, 92, 92],
125
+ "indigo": [75, 0, 130],
126
+ "ivory": [255, 255, 240],
127
+ "khaki": [240, 230, 140],
128
+ "lavender": [230, 230, 250],
129
+ "lavenderblush": [255, 240, 245],
130
+ "lawngreen": [124, 252, 0],
131
+ "lemonchiffon": [255, 250, 205],
132
+ "lightblue": [173, 216, 230],
133
+ "lightcoral": [240, 128, 128],
134
+ "lightcyan": [224, 255, 255],
135
+ "lightgoldenrodyellow": [250, 250, 210],
136
+ "lightgray": [211, 211, 211],
137
+ "lightgreen": [144, 238, 144],
138
+ "lightgrey": [211, 211, 211],
139
+ "lightpink": [255, 182, 193],
140
+ "lightsalmon": [255, 160, 122],
141
+ "lightseagreen": [32, 178, 170],
142
+ "lightskyblue": [135, 206, 250],
143
+ "lightslategray": [119, 136, 153],
144
+ "lightslategrey": [119, 136, 153],
145
+ "lightsteelblue": [176, 196, 222],
146
+ "lightyellow": [255, 255, 224],
147
+ "lime": [0, 255, 0],
148
+ "limegreen": [50, 205, 50],
149
+ "linen": [250, 240, 230],
150
+ "magenta": [255, 0, 255],
151
+ "maroon": [128, 0, 0],
152
+ "mediumaquamarine": [102, 205, 170],
153
+ "mediumblue": [0, 0, 205],
154
+ "mediumorchid": [186, 85, 211],
155
+ "mediumpurple": [147, 112, 219],
156
+ "mediumseagreen": [60, 179, 113],
157
+ "mediumslateblue": [123, 104, 238],
158
+ "mediumspringgreen": [0, 250, 154],
159
+ "mediumturquoise": [72, 209, 204],
160
+ "mediumvioletred": [199, 21, 133],
161
+ "midnightblue": [25, 25, 112],
162
+ "mintcream": [245, 255, 250],
163
+ "mistyrose": [255, 228, 225],
164
+ "moccasin": [255, 228, 181],
165
+ "navajowhite": [255, 222, 173],
166
+ "navy": [0, 0, 128],
167
+ "oldlace": [253, 245, 230],
168
+ "olive": [128, 128, 0],
169
+ "olivedrab": [107, 142, 35],
170
+ "orange": [255, 165, 0],
171
+ "orangered": [255, 69, 0],
172
+ "orchid": [218, 112, 214],
173
+ "palegoldenrod": [238, 232, 170],
174
+ "palegreen": [152, 251, 152],
175
+ "paleturquoise": [175, 238, 238],
176
+ "palevioletred": [219, 112, 147],
177
+ "papayawhip": [255, 239, 213],
178
+ "peachpuff": [255, 218, 185],
179
+ "peru": [205, 133, 63],
180
+ "pink": [255, 192, 203],
181
+ "plum": [221, 160, 221],
182
+ "powderblue": [176, 224, 230],
183
+ "purple": [128, 0, 128],
184
+ "rebeccapurple": [102, 51, 153],
185
+ "red": [255, 0, 0],
186
+ "rosybrown": [188, 143, 143],
187
+ "royalblue": [65, 105, 225],
188
+ "saddlebrown": [139, 69, 19],
189
+ "salmon": [250, 128, 114],
190
+ "sandybrown": [244, 164, 96],
191
+ "seagreen": [46, 139, 87],
192
+ "seashell": [255, 245, 238],
193
+ "sienna": [160, 82, 45],
194
+ "silver": [192, 192, 192],
195
+ "skyblue": [135, 206, 235],
196
+ "slateblue": [106, 90, 205],
197
+ "slategray": [112, 128, 144],
198
+ "slategrey": [112, 128, 144],
199
+ "snow": [255, 250, 250],
200
+ "springgreen": [0, 255, 127],
201
+ "steelblue": [70, 130, 180],
202
+ "tan": [210, 180, 140],
203
+ "teal": [0, 128, 128],
204
+ "thistle": [216, 191, 216],
205
+ "tomato": [255, 99, 71],
206
+ "turquoise": [64, 224, 208],
207
+ "violet": [238, 130, 238],
208
+ "wheat": [245, 222, 179],
209
+ "white": [255, 255, 255],
210
+ "whitesmoke": [245, 245, 245],
211
+ "yellow": [255, 255, 0],
212
+ "yellowgreen": [154, 205, 50]
213
+ };
214
+ return colorName;
215
+ }
216
+
217
+ /* MIT license */
218
+
219
+ var conversions;
220
+ var hasRequiredConversions;
221
+
222
+ function requireConversions () {
223
+ if (hasRequiredConversions) return conversions;
224
+ hasRequiredConversions = 1;
225
+ /* eslint-disable no-mixed-operators */
226
+ const cssKeywords = requireColorName();
227
+
228
+ // NOTE: conversions should only return primitive values (i.e. arrays, or
229
+ // values that give correct `typeof` results).
230
+ // do not use box values types (i.e. Number(), String(), etc.)
231
+
232
+ const reverseKeywords = {};
233
+ for (const key of Object.keys(cssKeywords)) {
234
+ reverseKeywords[cssKeywords[key]] = key;
235
+ }
236
+
237
+ const convert = {
238
+ rgb: {channels: 3, labels: 'rgb'},
239
+ hsl: {channels: 3, labels: 'hsl'},
240
+ hsv: {channels: 3, labels: 'hsv'},
241
+ hwb: {channels: 3, labels: 'hwb'},
242
+ cmyk: {channels: 4, labels: 'cmyk'},
243
+ xyz: {channels: 3, labels: 'xyz'},
244
+ lab: {channels: 3, labels: 'lab'},
245
+ lch: {channels: 3, labels: 'lch'},
246
+ hex: {channels: 1, labels: ['hex']},
247
+ keyword: {channels: 1, labels: ['keyword']},
248
+ ansi16: {channels: 1, labels: ['ansi16']},
249
+ ansi256: {channels: 1, labels: ['ansi256']},
250
+ hcg: {channels: 3, labels: ['h', 'c', 'g']},
251
+ apple: {channels: 3, labels: ['r16', 'g16', 'b16']},
252
+ gray: {channels: 1, labels: ['gray']}
253
+ };
254
+
255
+ conversions = convert;
256
+
257
+ // Hide .channels and .labels properties
258
+ for (const model of Object.keys(convert)) {
259
+ if (!('channels' in convert[model])) {
260
+ throw new Error('missing channels property: ' + model);
261
+ }
262
+
263
+ if (!('labels' in convert[model])) {
264
+ throw new Error('missing channel labels property: ' + model);
265
+ }
266
+
267
+ if (convert[model].labels.length !== convert[model].channels) {
268
+ throw new Error('channel and label counts mismatch: ' + model);
269
+ }
270
+
271
+ const {channels, labels} = convert[model];
272
+ delete convert[model].channels;
273
+ delete convert[model].labels;
274
+ Object.defineProperty(convert[model], 'channels', {value: channels});
275
+ Object.defineProperty(convert[model], 'labels', {value: labels});
276
+ }
277
+
278
+ convert.rgb.hsl = function (rgb) {
279
+ const r = rgb[0] / 255;
280
+ const g = rgb[1] / 255;
281
+ const b = rgb[2] / 255;
282
+ const min = Math.min(r, g, b);
283
+ const max = Math.max(r, g, b);
284
+ const delta = max - min;
285
+ let h;
286
+ let s;
287
+
288
+ if (max === min) {
289
+ h = 0;
290
+ } else if (r === max) {
291
+ h = (g - b) / delta;
292
+ } else if (g === max) {
293
+ h = 2 + (b - r) / delta;
294
+ } else if (b === max) {
295
+ h = 4 + (r - g) / delta;
296
+ }
297
+
298
+ h = Math.min(h * 60, 360);
299
+
300
+ if (h < 0) {
301
+ h += 360;
302
+ }
303
+
304
+ const l = (min + max) / 2;
305
+
306
+ if (max === min) {
307
+ s = 0;
308
+ } else if (l <= 0.5) {
309
+ s = delta / (max + min);
310
+ } else {
311
+ s = delta / (2 - max - min);
312
+ }
313
+
314
+ return [h, s * 100, l * 100];
315
+ };
316
+
317
+ convert.rgb.hsv = function (rgb) {
318
+ let rdif;
319
+ let gdif;
320
+ let bdif;
321
+ let h;
322
+ let s;
323
+
324
+ const r = rgb[0] / 255;
325
+ const g = rgb[1] / 255;
326
+ const b = rgb[2] / 255;
327
+ const v = Math.max(r, g, b);
328
+ const diff = v - Math.min(r, g, b);
329
+ const diffc = function (c) {
330
+ return (v - c) / 6 / diff + 1 / 2;
331
+ };
332
+
333
+ if (diff === 0) {
334
+ h = 0;
335
+ s = 0;
336
+ } else {
337
+ s = diff / v;
338
+ rdif = diffc(r);
339
+ gdif = diffc(g);
340
+ bdif = diffc(b);
341
+
342
+ if (r === v) {
343
+ h = bdif - gdif;
344
+ } else if (g === v) {
345
+ h = (1 / 3) + rdif - bdif;
346
+ } else if (b === v) {
347
+ h = (2 / 3) + gdif - rdif;
348
+ }
349
+
350
+ if (h < 0) {
351
+ h += 1;
352
+ } else if (h > 1) {
353
+ h -= 1;
354
+ }
355
+ }
356
+
357
+ return [
358
+ h * 360,
359
+ s * 100,
360
+ v * 100
361
+ ];
362
+ };
363
+
364
+ convert.rgb.hwb = function (rgb) {
365
+ const r = rgb[0];
366
+ const g = rgb[1];
367
+ let b = rgb[2];
368
+ const h = convert.rgb.hsl(rgb)[0];
369
+ const w = 1 / 255 * Math.min(r, Math.min(g, b));
370
+
371
+ b = 1 - 1 / 255 * Math.max(r, Math.max(g, b));
372
+
373
+ return [h, w * 100, b * 100];
374
+ };
375
+
376
+ convert.rgb.cmyk = function (rgb) {
377
+ const r = rgb[0] / 255;
378
+ const g = rgb[1] / 255;
379
+ const b = rgb[2] / 255;
380
+
381
+ const k = Math.min(1 - r, 1 - g, 1 - b);
382
+ const c = (1 - r - k) / (1 - k) || 0;
383
+ const m = (1 - g - k) / (1 - k) || 0;
384
+ const y = (1 - b - k) / (1 - k) || 0;
385
+
386
+ return [c * 100, m * 100, y * 100, k * 100];
387
+ };
388
+
389
+ function comparativeDistance(x, y) {
390
+ /*
391
+ See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
392
+ */
393
+ return (
394
+ ((x[0] - y[0]) ** 2) +
395
+ ((x[1] - y[1]) ** 2) +
396
+ ((x[2] - y[2]) ** 2)
397
+ );
398
+ }
399
+
400
+ convert.rgb.keyword = function (rgb) {
401
+ const reversed = reverseKeywords[rgb];
402
+ if (reversed) {
403
+ return reversed;
404
+ }
405
+
406
+ let currentClosestDistance = Infinity;
407
+ let currentClosestKeyword;
408
+
409
+ for (const keyword of Object.keys(cssKeywords)) {
410
+ const value = cssKeywords[keyword];
411
+
412
+ // Compute comparative distance
413
+ const distance = comparativeDistance(rgb, value);
414
+
415
+ // Check if its less, if so set as closest
416
+ if (distance < currentClosestDistance) {
417
+ currentClosestDistance = distance;
418
+ currentClosestKeyword = keyword;
419
+ }
420
+ }
421
+
422
+ return currentClosestKeyword;
423
+ };
424
+
425
+ convert.keyword.rgb = function (keyword) {
426
+ return cssKeywords[keyword];
427
+ };
428
+
429
+ convert.rgb.xyz = function (rgb) {
430
+ let r = rgb[0] / 255;
431
+ let g = rgb[1] / 255;
432
+ let b = rgb[2] / 255;
433
+
434
+ // Assume sRGB
435
+ r = r > 0.04045 ? (((r + 0.055) / 1.055) ** 2.4) : (r / 12.92);
436
+ g = g > 0.04045 ? (((g + 0.055) / 1.055) ** 2.4) : (g / 12.92);
437
+ b = b > 0.04045 ? (((b + 0.055) / 1.055) ** 2.4) : (b / 12.92);
438
+
439
+ const x = (r * 0.4124) + (g * 0.3576) + (b * 0.1805);
440
+ const y = (r * 0.2126) + (g * 0.7152) + (b * 0.0722);
441
+ const z = (r * 0.0193) + (g * 0.1192) + (b * 0.9505);
442
+
443
+ return [x * 100, y * 100, z * 100];
444
+ };
445
+
446
+ convert.rgb.lab = function (rgb) {
447
+ const xyz = convert.rgb.xyz(rgb);
448
+ let x = xyz[0];
449
+ let y = xyz[1];
450
+ let z = xyz[2];
451
+
452
+ x /= 95.047;
453
+ y /= 100;
454
+ z /= 108.883;
455
+
456
+ x = x > 0.008856 ? (x ** (1 / 3)) : (7.787 * x) + (16 / 116);
457
+ y = y > 0.008856 ? (y ** (1 / 3)) : (7.787 * y) + (16 / 116);
458
+ z = z > 0.008856 ? (z ** (1 / 3)) : (7.787 * z) + (16 / 116);
459
+
460
+ const l = (116 * y) - 16;
461
+ const a = 500 * (x - y);
462
+ const b = 200 * (y - z);
463
+
464
+ return [l, a, b];
465
+ };
466
+
467
+ convert.hsl.rgb = function (hsl) {
468
+ const h = hsl[0] / 360;
469
+ const s = hsl[1] / 100;
470
+ const l = hsl[2] / 100;
471
+ let t2;
472
+ let t3;
473
+ let val;
474
+
475
+ if (s === 0) {
476
+ val = l * 255;
477
+ return [val, val, val];
478
+ }
479
+
480
+ if (l < 0.5) {
481
+ t2 = l * (1 + s);
482
+ } else {
483
+ t2 = l + s - l * s;
484
+ }
485
+
486
+ const t1 = 2 * l - t2;
487
+
488
+ const rgb = [0, 0, 0];
489
+ for (let i = 0; i < 3; i++) {
490
+ t3 = h + 1 / 3 * -(i - 1);
491
+ if (t3 < 0) {
492
+ t3++;
493
+ }
494
+
495
+ if (t3 > 1) {
496
+ t3--;
497
+ }
498
+
499
+ if (6 * t3 < 1) {
500
+ val = t1 + (t2 - t1) * 6 * t3;
501
+ } else if (2 * t3 < 1) {
502
+ val = t2;
503
+ } else if (3 * t3 < 2) {
504
+ val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
505
+ } else {
506
+ val = t1;
507
+ }
508
+
509
+ rgb[i] = val * 255;
510
+ }
511
+
512
+ return rgb;
513
+ };
514
+
515
+ convert.hsl.hsv = function (hsl) {
516
+ const h = hsl[0];
517
+ let s = hsl[1] / 100;
518
+ let l = hsl[2] / 100;
519
+ let smin = s;
520
+ const lmin = Math.max(l, 0.01);
521
+
522
+ l *= 2;
523
+ s *= (l <= 1) ? l : 2 - l;
524
+ smin *= lmin <= 1 ? lmin : 2 - lmin;
525
+ const v = (l + s) / 2;
526
+ const sv = l === 0 ? (2 * smin) / (lmin + smin) : (2 * s) / (l + s);
527
+
528
+ return [h, sv * 100, v * 100];
529
+ };
530
+
531
+ convert.hsv.rgb = function (hsv) {
532
+ const h = hsv[0] / 60;
533
+ const s = hsv[1] / 100;
534
+ let v = hsv[2] / 100;
535
+ const hi = Math.floor(h) % 6;
536
+
537
+ const f = h - Math.floor(h);
538
+ const p = 255 * v * (1 - s);
539
+ const q = 255 * v * (1 - (s * f));
540
+ const t = 255 * v * (1 - (s * (1 - f)));
541
+ v *= 255;
542
+
543
+ switch (hi) {
544
+ case 0:
545
+ return [v, t, p];
546
+ case 1:
547
+ return [q, v, p];
548
+ case 2:
549
+ return [p, v, t];
550
+ case 3:
551
+ return [p, q, v];
552
+ case 4:
553
+ return [t, p, v];
554
+ case 5:
555
+ return [v, p, q];
556
+ }
557
+ };
558
+
559
+ convert.hsv.hsl = function (hsv) {
560
+ const h = hsv[0];
561
+ const s = hsv[1] / 100;
562
+ const v = hsv[2] / 100;
563
+ const vmin = Math.max(v, 0.01);
564
+ let sl;
565
+ let l;
566
+
567
+ l = (2 - s) * v;
568
+ const lmin = (2 - s) * vmin;
569
+ sl = s * vmin;
570
+ sl /= (lmin <= 1) ? lmin : 2 - lmin;
571
+ sl = sl || 0;
572
+ l /= 2;
573
+
574
+ return [h, sl * 100, l * 100];
575
+ };
576
+
577
+ // http://dev.w3.org/csswg/css-color/#hwb-to-rgb
578
+ convert.hwb.rgb = function (hwb) {
579
+ const h = hwb[0] / 360;
580
+ let wh = hwb[1] / 100;
581
+ let bl = hwb[2] / 100;
582
+ const ratio = wh + bl;
583
+ let f;
584
+
585
+ // Wh + bl cant be > 1
586
+ if (ratio > 1) {
587
+ wh /= ratio;
588
+ bl /= ratio;
589
+ }
590
+
591
+ const i = Math.floor(6 * h);
592
+ const v = 1 - bl;
593
+ f = 6 * h - i;
594
+
595
+ if ((i & 0x01) !== 0) {
596
+ f = 1 - f;
597
+ }
598
+
599
+ const n = wh + f * (v - wh); // Linear interpolation
600
+
601
+ let r;
602
+ let g;
603
+ let b;
604
+ /* eslint-disable max-statements-per-line,no-multi-spaces */
605
+ switch (i) {
606
+ default:
607
+ case 6:
608
+ case 0: r = v; g = n; b = wh; break;
609
+ case 1: r = n; g = v; b = wh; break;
610
+ case 2: r = wh; g = v; b = n; break;
611
+ case 3: r = wh; g = n; b = v; break;
612
+ case 4: r = n; g = wh; b = v; break;
613
+ case 5: r = v; g = wh; b = n; break;
614
+ }
615
+ /* eslint-enable max-statements-per-line,no-multi-spaces */
616
+
617
+ return [r * 255, g * 255, b * 255];
618
+ };
619
+
620
+ convert.cmyk.rgb = function (cmyk) {
621
+ const c = cmyk[0] / 100;
622
+ const m = cmyk[1] / 100;
623
+ const y = cmyk[2] / 100;
624
+ const k = cmyk[3] / 100;
625
+
626
+ const r = 1 - Math.min(1, c * (1 - k) + k);
627
+ const g = 1 - Math.min(1, m * (1 - k) + k);
628
+ const b = 1 - Math.min(1, y * (1 - k) + k);
629
+
630
+ return [r * 255, g * 255, b * 255];
631
+ };
632
+
633
+ convert.xyz.rgb = function (xyz) {
634
+ const x = xyz[0] / 100;
635
+ const y = xyz[1] / 100;
636
+ const z = xyz[2] / 100;
637
+ let r;
638
+ let g;
639
+ let b;
640
+
641
+ r = (x * 3.2406) + (y * -1.5372) + (z * -0.4986);
642
+ g = (x * -0.9689) + (y * 1.8758) + (z * 0.0415);
643
+ b = (x * 0.0557) + (y * -0.2040) + (z * 1.0570);
644
+
645
+ // Assume sRGB
646
+ r = r > 0.0031308
647
+ ? ((1.055 * (r ** (1.0 / 2.4))) - 0.055)
648
+ : r * 12.92;
649
+
650
+ g = g > 0.0031308
651
+ ? ((1.055 * (g ** (1.0 / 2.4))) - 0.055)
652
+ : g * 12.92;
653
+
654
+ b = b > 0.0031308
655
+ ? ((1.055 * (b ** (1.0 / 2.4))) - 0.055)
656
+ : b * 12.92;
657
+
658
+ r = Math.min(Math.max(0, r), 1);
659
+ g = Math.min(Math.max(0, g), 1);
660
+ b = Math.min(Math.max(0, b), 1);
661
+
662
+ return [r * 255, g * 255, b * 255];
663
+ };
664
+
665
+ convert.xyz.lab = function (xyz) {
666
+ let x = xyz[0];
667
+ let y = xyz[1];
668
+ let z = xyz[2];
669
+
670
+ x /= 95.047;
671
+ y /= 100;
672
+ z /= 108.883;
673
+
674
+ x = x > 0.008856 ? (x ** (1 / 3)) : (7.787 * x) + (16 / 116);
675
+ y = y > 0.008856 ? (y ** (1 / 3)) : (7.787 * y) + (16 / 116);
676
+ z = z > 0.008856 ? (z ** (1 / 3)) : (7.787 * z) + (16 / 116);
677
+
678
+ const l = (116 * y) - 16;
679
+ const a = 500 * (x - y);
680
+ const b = 200 * (y - z);
681
+
682
+ return [l, a, b];
683
+ };
684
+
685
+ convert.lab.xyz = function (lab) {
686
+ const l = lab[0];
687
+ const a = lab[1];
688
+ const b = lab[2];
689
+ let x;
690
+ let y;
691
+ let z;
692
+
693
+ y = (l + 16) / 116;
694
+ x = a / 500 + y;
695
+ z = y - b / 200;
696
+
697
+ const y2 = y ** 3;
698
+ const x2 = x ** 3;
699
+ const z2 = z ** 3;
700
+ y = y2 > 0.008856 ? y2 : (y - 16 / 116) / 7.787;
701
+ x = x2 > 0.008856 ? x2 : (x - 16 / 116) / 7.787;
702
+ z = z2 > 0.008856 ? z2 : (z - 16 / 116) / 7.787;
703
+
704
+ x *= 95.047;
705
+ y *= 100;
706
+ z *= 108.883;
707
+
708
+ return [x, y, z];
709
+ };
710
+
711
+ convert.lab.lch = function (lab) {
712
+ const l = lab[0];
713
+ const a = lab[1];
714
+ const b = lab[2];
715
+ let h;
716
+
717
+ const hr = Math.atan2(b, a);
718
+ h = hr * 360 / 2 / Math.PI;
719
+
720
+ if (h < 0) {
721
+ h += 360;
722
+ }
723
+
724
+ const c = Math.sqrt(a * a + b * b);
725
+
726
+ return [l, c, h];
727
+ };
728
+
729
+ convert.lch.lab = function (lch) {
730
+ const l = lch[0];
731
+ const c = lch[1];
732
+ const h = lch[2];
733
+
734
+ const hr = h / 360 * 2 * Math.PI;
735
+ const a = c * Math.cos(hr);
736
+ const b = c * Math.sin(hr);
737
+
738
+ return [l, a, b];
739
+ };
740
+
741
+ convert.rgb.ansi16 = function (args, saturation = null) {
742
+ const [r, g, b] = args;
743
+ let value = saturation === null ? convert.rgb.hsv(args)[2] : saturation; // Hsv -> ansi16 optimization
744
+
745
+ value = Math.round(value / 50);
746
+
747
+ if (value === 0) {
748
+ return 30;
749
+ }
750
+
751
+ let ansi = 30
752
+ + ((Math.round(b / 255) << 2)
753
+ | (Math.round(g / 255) << 1)
754
+ | Math.round(r / 255));
755
+
756
+ if (value === 2) {
757
+ ansi += 60;
758
+ }
759
+
760
+ return ansi;
761
+ };
762
+
763
+ convert.hsv.ansi16 = function (args) {
764
+ // Optimization here; we already know the value and don't need to get
765
+ // it converted for us.
766
+ return convert.rgb.ansi16(convert.hsv.rgb(args), args[2]);
767
+ };
768
+
769
+ convert.rgb.ansi256 = function (args) {
770
+ const r = args[0];
771
+ const g = args[1];
772
+ const b = args[2];
773
+
774
+ // We use the extended greyscale palette here, with the exception of
775
+ // black and white. normal palette only has 4 greyscale shades.
776
+ if (r === g && g === b) {
777
+ if (r < 8) {
778
+ return 16;
779
+ }
780
+
781
+ if (r > 248) {
782
+ return 231;
783
+ }
784
+
785
+ return Math.round(((r - 8) / 247) * 24) + 232;
786
+ }
787
+
788
+ const ansi = 16
789
+ + (36 * Math.round(r / 255 * 5))
790
+ + (6 * Math.round(g / 255 * 5))
791
+ + Math.round(b / 255 * 5);
792
+
793
+ return ansi;
794
+ };
795
+
796
+ convert.ansi16.rgb = function (args) {
797
+ let color = args % 10;
798
+
799
+ // Handle greyscale
800
+ if (color === 0 || color === 7) {
801
+ if (args > 50) {
802
+ color += 3.5;
803
+ }
804
+
805
+ color = color / 10.5 * 255;
806
+
807
+ return [color, color, color];
808
+ }
809
+
810
+ const mult = (~~(args > 50) + 1) * 0.5;
811
+ const r = ((color & 1) * mult) * 255;
812
+ const g = (((color >> 1) & 1) * mult) * 255;
813
+ const b = (((color >> 2) & 1) * mult) * 255;
814
+
815
+ return [r, g, b];
816
+ };
817
+
818
+ convert.ansi256.rgb = function (args) {
819
+ // Handle greyscale
820
+ if (args >= 232) {
821
+ const c = (args - 232) * 10 + 8;
822
+ return [c, c, c];
823
+ }
824
+
825
+ args -= 16;
826
+
827
+ let rem;
828
+ const r = Math.floor(args / 36) / 5 * 255;
829
+ const g = Math.floor((rem = args % 36) / 6) / 5 * 255;
830
+ const b = (rem % 6) / 5 * 255;
831
+
832
+ return [r, g, b];
833
+ };
834
+
835
+ convert.rgb.hex = function (args) {
836
+ const integer = ((Math.round(args[0]) & 0xFF) << 16)
837
+ + ((Math.round(args[1]) & 0xFF) << 8)
838
+ + (Math.round(args[2]) & 0xFF);
839
+
840
+ const string = integer.toString(16).toUpperCase();
841
+ return '000000'.substring(string.length) + string;
842
+ };
843
+
844
+ convert.hex.rgb = function (args) {
845
+ const match = args.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);
846
+ if (!match) {
847
+ return [0, 0, 0];
848
+ }
849
+
850
+ let colorString = match[0];
851
+
852
+ if (match[0].length === 3) {
853
+ colorString = colorString.split('').map(char => {
854
+ return char + char;
855
+ }).join('');
856
+ }
857
+
858
+ const integer = parseInt(colorString, 16);
859
+ const r = (integer >> 16) & 0xFF;
860
+ const g = (integer >> 8) & 0xFF;
861
+ const b = integer & 0xFF;
862
+
863
+ return [r, g, b];
864
+ };
865
+
866
+ convert.rgb.hcg = function (rgb) {
867
+ const r = rgb[0] / 255;
868
+ const g = rgb[1] / 255;
869
+ const b = rgb[2] / 255;
870
+ const max = Math.max(Math.max(r, g), b);
871
+ const min = Math.min(Math.min(r, g), b);
872
+ const chroma = (max - min);
873
+ let grayscale;
874
+ let hue;
875
+
876
+ if (chroma < 1) {
877
+ grayscale = min / (1 - chroma);
878
+ } else {
879
+ grayscale = 0;
880
+ }
881
+
882
+ if (chroma <= 0) {
883
+ hue = 0;
884
+ } else
885
+ if (max === r) {
886
+ hue = ((g - b) / chroma) % 6;
887
+ } else
888
+ if (max === g) {
889
+ hue = 2 + (b - r) / chroma;
890
+ } else {
891
+ hue = 4 + (r - g) / chroma;
892
+ }
893
+
894
+ hue /= 6;
895
+ hue %= 1;
896
+
897
+ return [hue * 360, chroma * 100, grayscale * 100];
898
+ };
899
+
900
+ convert.hsl.hcg = function (hsl) {
901
+ const s = hsl[1] / 100;
902
+ const l = hsl[2] / 100;
903
+
904
+ const c = l < 0.5 ? (2.0 * s * l) : (2.0 * s * (1.0 - l));
905
+
906
+ let f = 0;
907
+ if (c < 1.0) {
908
+ f = (l - 0.5 * c) / (1.0 - c);
909
+ }
910
+
911
+ return [hsl[0], c * 100, f * 100];
912
+ };
913
+
914
+ convert.hsv.hcg = function (hsv) {
915
+ const s = hsv[1] / 100;
916
+ const v = hsv[2] / 100;
917
+
918
+ const c = s * v;
919
+ let f = 0;
920
+
921
+ if (c < 1.0) {
922
+ f = (v - c) / (1 - c);
923
+ }
924
+
925
+ return [hsv[0], c * 100, f * 100];
926
+ };
927
+
928
+ convert.hcg.rgb = function (hcg) {
929
+ const h = hcg[0] / 360;
930
+ const c = hcg[1] / 100;
931
+ const g = hcg[2] / 100;
932
+
933
+ if (c === 0.0) {
934
+ return [g * 255, g * 255, g * 255];
935
+ }
936
+
937
+ const pure = [0, 0, 0];
938
+ const hi = (h % 1) * 6;
939
+ const v = hi % 1;
940
+ const w = 1 - v;
941
+ let mg = 0;
942
+
943
+ /* eslint-disable max-statements-per-line */
944
+ switch (Math.floor(hi)) {
945
+ case 0:
946
+ pure[0] = 1; pure[1] = v; pure[2] = 0; break;
947
+ case 1:
948
+ pure[0] = w; pure[1] = 1; pure[2] = 0; break;
949
+ case 2:
950
+ pure[0] = 0; pure[1] = 1; pure[2] = v; break;
951
+ case 3:
952
+ pure[0] = 0; pure[1] = w; pure[2] = 1; break;
953
+ case 4:
954
+ pure[0] = v; pure[1] = 0; pure[2] = 1; break;
955
+ default:
956
+ pure[0] = 1; pure[1] = 0; pure[2] = w;
957
+ }
958
+ /* eslint-enable max-statements-per-line */
959
+
960
+ mg = (1.0 - c) * g;
961
+
962
+ return [
963
+ (c * pure[0] + mg) * 255,
964
+ (c * pure[1] + mg) * 255,
965
+ (c * pure[2] + mg) * 255
966
+ ];
967
+ };
968
+
969
+ convert.hcg.hsv = function (hcg) {
970
+ const c = hcg[1] / 100;
971
+ const g = hcg[2] / 100;
972
+
973
+ const v = c + g * (1.0 - c);
974
+ let f = 0;
975
+
976
+ if (v > 0.0) {
977
+ f = c / v;
978
+ }
979
+
980
+ return [hcg[0], f * 100, v * 100];
981
+ };
982
+
983
+ convert.hcg.hsl = function (hcg) {
984
+ const c = hcg[1] / 100;
985
+ const g = hcg[2] / 100;
986
+
987
+ const l = g * (1.0 - c) + 0.5 * c;
988
+ let s = 0;
989
+
990
+ if (l > 0.0 && l < 0.5) {
991
+ s = c / (2 * l);
992
+ } else
993
+ if (l >= 0.5 && l < 1.0) {
994
+ s = c / (2 * (1 - l));
995
+ }
996
+
997
+ return [hcg[0], s * 100, l * 100];
998
+ };
999
+
1000
+ convert.hcg.hwb = function (hcg) {
1001
+ const c = hcg[1] / 100;
1002
+ const g = hcg[2] / 100;
1003
+ const v = c + g * (1.0 - c);
1004
+ return [hcg[0], (v - c) * 100, (1 - v) * 100];
1005
+ };
1006
+
1007
+ convert.hwb.hcg = function (hwb) {
1008
+ const w = hwb[1] / 100;
1009
+ const b = hwb[2] / 100;
1010
+ const v = 1 - b;
1011
+ const c = v - w;
1012
+ let g = 0;
1013
+
1014
+ if (c < 1) {
1015
+ g = (v - c) / (1 - c);
1016
+ }
1017
+
1018
+ return [hwb[0], c * 100, g * 100];
1019
+ };
1020
+
1021
+ convert.apple.rgb = function (apple) {
1022
+ return [(apple[0] / 65535) * 255, (apple[1] / 65535) * 255, (apple[2] / 65535) * 255];
1023
+ };
1024
+
1025
+ convert.rgb.apple = function (rgb) {
1026
+ return [(rgb[0] / 255) * 65535, (rgb[1] / 255) * 65535, (rgb[2] / 255) * 65535];
1027
+ };
1028
+
1029
+ convert.gray.rgb = function (args) {
1030
+ return [args[0] / 100 * 255, args[0] / 100 * 255, args[0] / 100 * 255];
1031
+ };
1032
+
1033
+ convert.gray.hsl = function (args) {
1034
+ return [0, 0, args[0]];
1035
+ };
1036
+
1037
+ convert.gray.hsv = convert.gray.hsl;
1038
+
1039
+ convert.gray.hwb = function (gray) {
1040
+ return [0, 100, gray[0]];
1041
+ };
1042
+
1043
+ convert.gray.cmyk = function (gray) {
1044
+ return [0, 0, 0, gray[0]];
1045
+ };
1046
+
1047
+ convert.gray.lab = function (gray) {
1048
+ return [gray[0], 0, 0];
1049
+ };
1050
+
1051
+ convert.gray.hex = function (gray) {
1052
+ const val = Math.round(gray[0] / 100 * 255) & 0xFF;
1053
+ const integer = (val << 16) + (val << 8) + val;
1054
+
1055
+ const string = integer.toString(16).toUpperCase();
1056
+ return '000000'.substring(string.length) + string;
1057
+ };
1058
+
1059
+ convert.rgb.gray = function (rgb) {
1060
+ const val = (rgb[0] + rgb[1] + rgb[2]) / 3;
1061
+ return [val / 255 * 100];
1062
+ };
1063
+ return conversions;
1064
+ }
1065
+
1066
+ var route;
1067
+ var hasRequiredRoute;
1068
+
1069
+ function requireRoute () {
1070
+ if (hasRequiredRoute) return route;
1071
+ hasRequiredRoute = 1;
1072
+ const conversions = requireConversions();
1073
+
1074
+ /*
1075
+ This function routes a model to all other models.
1076
+
1077
+ all functions that are routed have a property `.conversion` attached
1078
+ to the returned synthetic function. This property is an array
1079
+ of strings, each with the steps in between the 'from' and 'to'
1080
+ color models (inclusive).
1081
+
1082
+ conversions that are not possible simply are not included.
1083
+ */
1084
+
1085
+ function buildGraph() {
1086
+ const graph = {};
1087
+ // https://jsperf.com/object-keys-vs-for-in-with-closure/3
1088
+ const models = Object.keys(conversions);
1089
+
1090
+ for (let len = models.length, i = 0; i < len; i++) {
1091
+ graph[models[i]] = {
1092
+ // http://jsperf.com/1-vs-infinity
1093
+ // micro-opt, but this is simple.
1094
+ distance: -1,
1095
+ parent: null
1096
+ };
1097
+ }
1098
+
1099
+ return graph;
1100
+ }
1101
+
1102
+ // https://en.wikipedia.org/wiki/Breadth-first_search
1103
+ function deriveBFS(fromModel) {
1104
+ const graph = buildGraph();
1105
+ const queue = [fromModel]; // Unshift -> queue -> pop
1106
+
1107
+ graph[fromModel].distance = 0;
1108
+
1109
+ while (queue.length) {
1110
+ const current = queue.pop();
1111
+ const adjacents = Object.keys(conversions[current]);
1112
+
1113
+ for (let len = adjacents.length, i = 0; i < len; i++) {
1114
+ const adjacent = adjacents[i];
1115
+ const node = graph[adjacent];
1116
+
1117
+ if (node.distance === -1) {
1118
+ node.distance = graph[current].distance + 1;
1119
+ node.parent = current;
1120
+ queue.unshift(adjacent);
1121
+ }
1122
+ }
1123
+ }
1124
+
1125
+ return graph;
1126
+ }
1127
+
1128
+ function link(from, to) {
1129
+ return function (args) {
1130
+ return to(from(args));
1131
+ };
1132
+ }
1133
+
1134
+ function wrapConversion(toModel, graph) {
1135
+ const path = [graph[toModel].parent, toModel];
1136
+ let fn = conversions[graph[toModel].parent][toModel];
1137
+
1138
+ let cur = graph[toModel].parent;
1139
+ while (graph[cur].parent) {
1140
+ path.unshift(graph[cur].parent);
1141
+ fn = link(conversions[graph[cur].parent][cur], fn);
1142
+ cur = graph[cur].parent;
1143
+ }
1144
+
1145
+ fn.conversion = path;
1146
+ return fn;
1147
+ }
1148
+
1149
+ route = function (fromModel) {
1150
+ const graph = deriveBFS(fromModel);
1151
+ const conversion = {};
1152
+
1153
+ const models = Object.keys(graph);
1154
+ for (let len = models.length, i = 0; i < len; i++) {
1155
+ const toModel = models[i];
1156
+ const node = graph[toModel];
1157
+
1158
+ if (node.parent === null) {
1159
+ // No possible conversion, or this node is the source model.
1160
+ continue;
1161
+ }
1162
+
1163
+ conversion[toModel] = wrapConversion(toModel, graph);
1164
+ }
1165
+
1166
+ return conversion;
1167
+ };
1168
+ return route;
1169
+ }
1170
+
1171
+ var colorConvert;
1172
+ var hasRequiredColorConvert;
1173
+
1174
+ function requireColorConvert () {
1175
+ if (hasRequiredColorConvert) return colorConvert;
1176
+ hasRequiredColorConvert = 1;
1177
+ const conversions = requireConversions();
1178
+ const route = requireRoute();
1179
+
1180
+ const convert = {};
1181
+
1182
+ const models = Object.keys(conversions);
1183
+
1184
+ function wrapRaw(fn) {
1185
+ const wrappedFn = function (...args) {
1186
+ const arg0 = args[0];
1187
+ if (arg0 === undefined || arg0 === null) {
1188
+ return arg0;
1189
+ }
1190
+
1191
+ if (arg0.length > 1) {
1192
+ args = arg0;
1193
+ }
1194
+
1195
+ return fn(args);
1196
+ };
1197
+
1198
+ // Preserve .conversion property if there is one
1199
+ if ('conversion' in fn) {
1200
+ wrappedFn.conversion = fn.conversion;
1201
+ }
1202
+
1203
+ return wrappedFn;
1204
+ }
1205
+
1206
+ function wrapRounded(fn) {
1207
+ const wrappedFn = function (...args) {
1208
+ const arg0 = args[0];
1209
+
1210
+ if (arg0 === undefined || arg0 === null) {
1211
+ return arg0;
1212
+ }
1213
+
1214
+ if (arg0.length > 1) {
1215
+ args = arg0;
1216
+ }
1217
+
1218
+ const result = fn(args);
1219
+
1220
+ // We're assuming the result is an array here.
1221
+ // see notice in conversions.js; don't use box types
1222
+ // in conversion functions.
1223
+ if (typeof result === 'object') {
1224
+ for (let len = result.length, i = 0; i < len; i++) {
1225
+ result[i] = Math.round(result[i]);
1226
+ }
1227
+ }
1228
+
1229
+ return result;
1230
+ };
1231
+
1232
+ // Preserve .conversion property if there is one
1233
+ if ('conversion' in fn) {
1234
+ wrappedFn.conversion = fn.conversion;
1235
+ }
1236
+
1237
+ return wrappedFn;
1238
+ }
1239
+
1240
+ models.forEach(fromModel => {
1241
+ convert[fromModel] = {};
1242
+
1243
+ Object.defineProperty(convert[fromModel], 'channels', {value: conversions[fromModel].channels});
1244
+ Object.defineProperty(convert[fromModel], 'labels', {value: conversions[fromModel].labels});
1245
+
1246
+ const routes = route(fromModel);
1247
+ const routeModels = Object.keys(routes);
1248
+
1249
+ routeModels.forEach(toModel => {
1250
+ const fn = routes[toModel];
1251
+
1252
+ convert[fromModel][toModel] = wrapRounded(fn);
1253
+ convert[fromModel][toModel].raw = wrapRaw(fn);
1254
+ });
1255
+ });
1256
+
1257
+ colorConvert = convert;
1258
+ return colorConvert;
1259
+ }
1260
+
1261
+ ansiStyles$1.exports;
1262
+
1263
+ (function (module) {
1264
+
1265
+ const wrapAnsi16 = (fn, offset) => (...args) => {
1266
+ const code = fn(...args);
1267
+ return `\u001B[${code + offset}m`;
1268
+ };
1269
+
1270
+ const wrapAnsi256 = (fn, offset) => (...args) => {
1271
+ const code = fn(...args);
1272
+ return `\u001B[${38 + offset};5;${code}m`;
1273
+ };
1274
+
1275
+ const wrapAnsi16m = (fn, offset) => (...args) => {
1276
+ const rgb = fn(...args);
1277
+ return `\u001B[${38 + offset};2;${rgb[0]};${rgb[1]};${rgb[2]}m`;
1278
+ };
1279
+
1280
+ const ansi2ansi = n => n;
1281
+ const rgb2rgb = (r, g, b) => [r, g, b];
1282
+
1283
+ const setLazyProperty = (object, property, get) => {
1284
+ Object.defineProperty(object, property, {
1285
+ get: () => {
1286
+ const value = get();
1287
+
1288
+ Object.defineProperty(object, property, {
1289
+ value,
1290
+ enumerable: true,
1291
+ configurable: true
1292
+ });
1293
+
1294
+ return value;
1295
+ },
1296
+ enumerable: true,
1297
+ configurable: true
1298
+ });
1299
+ };
1300
+
1301
+ /** @type {typeof import('color-convert')} */
1302
+ let colorConvert;
1303
+ const makeDynamicStyles = (wrap, targetSpace, identity, isBackground) => {
1304
+ if (colorConvert === undefined) {
1305
+ colorConvert = requireColorConvert();
1306
+ }
1307
+
1308
+ const offset = isBackground ? 10 : 0;
1309
+ const styles = {};
1310
+
1311
+ for (const [sourceSpace, suite] of Object.entries(colorConvert)) {
1312
+ const name = sourceSpace === 'ansi16' ? 'ansi' : sourceSpace;
1313
+ if (sourceSpace === targetSpace) {
1314
+ styles[name] = wrap(identity, offset);
1315
+ } else if (typeof suite === 'object') {
1316
+ styles[name] = wrap(suite[targetSpace], offset);
1317
+ }
1318
+ }
1319
+
1320
+ return styles;
1321
+ };
1322
+
1323
+ function assembleStyles() {
1324
+ const codes = new Map();
1325
+ const styles = {
1326
+ modifier: {
1327
+ reset: [0, 0],
1328
+ // 21 isn't widely supported and 22 does the same thing
1329
+ bold: [1, 22],
1330
+ dim: [2, 22],
1331
+ italic: [3, 23],
1332
+ underline: [4, 24],
1333
+ inverse: [7, 27],
1334
+ hidden: [8, 28],
1335
+ strikethrough: [9, 29]
1336
+ },
1337
+ color: {
1338
+ black: [30, 39],
1339
+ red: [31, 39],
1340
+ green: [32, 39],
1341
+ yellow: [33, 39],
1342
+ blue: [34, 39],
1343
+ magenta: [35, 39],
1344
+ cyan: [36, 39],
1345
+ white: [37, 39],
1346
+
1347
+ // Bright color
1348
+ blackBright: [90, 39],
1349
+ redBright: [91, 39],
1350
+ greenBright: [92, 39],
1351
+ yellowBright: [93, 39],
1352
+ blueBright: [94, 39],
1353
+ magentaBright: [95, 39],
1354
+ cyanBright: [96, 39],
1355
+ whiteBright: [97, 39]
1356
+ },
1357
+ bgColor: {
1358
+ bgBlack: [40, 49],
1359
+ bgRed: [41, 49],
1360
+ bgGreen: [42, 49],
1361
+ bgYellow: [43, 49],
1362
+ bgBlue: [44, 49],
1363
+ bgMagenta: [45, 49],
1364
+ bgCyan: [46, 49],
1365
+ bgWhite: [47, 49],
1366
+
1367
+ // Bright color
1368
+ bgBlackBright: [100, 49],
1369
+ bgRedBright: [101, 49],
1370
+ bgGreenBright: [102, 49],
1371
+ bgYellowBright: [103, 49],
1372
+ bgBlueBright: [104, 49],
1373
+ bgMagentaBright: [105, 49],
1374
+ bgCyanBright: [106, 49],
1375
+ bgWhiteBright: [107, 49]
1376
+ }
1377
+ };
1378
+
1379
+ // Alias bright black as gray (and grey)
1380
+ styles.color.gray = styles.color.blackBright;
1381
+ styles.bgColor.bgGray = styles.bgColor.bgBlackBright;
1382
+ styles.color.grey = styles.color.blackBright;
1383
+ styles.bgColor.bgGrey = styles.bgColor.bgBlackBright;
1384
+
1385
+ for (const [groupName, group] of Object.entries(styles)) {
1386
+ for (const [styleName, style] of Object.entries(group)) {
1387
+ styles[styleName] = {
1388
+ open: `\u001B[${style[0]}m`,
1389
+ close: `\u001B[${style[1]}m`
1390
+ };
1391
+
1392
+ group[styleName] = styles[styleName];
1393
+
1394
+ codes.set(style[0], style[1]);
1395
+ }
1396
+
1397
+ Object.defineProperty(styles, groupName, {
1398
+ value: group,
1399
+ enumerable: false
1400
+ });
1401
+ }
1402
+
1403
+ Object.defineProperty(styles, 'codes', {
1404
+ value: codes,
1405
+ enumerable: false
1406
+ });
1407
+
1408
+ styles.color.close = '\u001B[39m';
1409
+ styles.bgColor.close = '\u001B[49m';
1410
+
1411
+ setLazyProperty(styles.color, 'ansi', () => makeDynamicStyles(wrapAnsi16, 'ansi16', ansi2ansi, false));
1412
+ setLazyProperty(styles.color, 'ansi256', () => makeDynamicStyles(wrapAnsi256, 'ansi256', ansi2ansi, false));
1413
+ setLazyProperty(styles.color, 'ansi16m', () => makeDynamicStyles(wrapAnsi16m, 'rgb', rgb2rgb, false));
1414
+ setLazyProperty(styles.bgColor, 'ansi', () => makeDynamicStyles(wrapAnsi16, 'ansi16', ansi2ansi, true));
1415
+ setLazyProperty(styles.bgColor, 'ansi256', () => makeDynamicStyles(wrapAnsi256, 'ansi256', ansi2ansi, true));
1416
+ setLazyProperty(styles.bgColor, 'ansi16m', () => makeDynamicStyles(wrapAnsi16m, 'rgb', rgb2rgb, true));
1417
+
1418
+ return styles;
1419
+ }
1420
+
1421
+ // Make the export immutable
1422
+ Object.defineProperty(module, 'exports', {
1423
+ enumerable: true,
1424
+ get: assembleStyles
1425
+ });
1426
+ } (ansiStyles$1));
1427
+
1428
+ var ansiStylesExports = ansiStyles$1.exports;
1429
+
1430
+ var hasFlag$1 = (flag, argv = process.argv) => {
1431
+ const prefix = flag.startsWith('-') ? '' : (flag.length === 1 ? '-' : '--');
1432
+ const position = argv.indexOf(prefix + flag);
1433
+ const terminatorPosition = argv.indexOf('--');
1434
+ return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
1435
+ };
1436
+
1437
+ const os = require$$0;
1438
+ const tty = require$$1;
1439
+ const hasFlag = hasFlag$1;
1440
+
1441
+ const {env} = process;
1442
+
1443
+ let forceColor;
1444
+ if (hasFlag('no-color') ||
1445
+ hasFlag('no-colors') ||
1446
+ hasFlag('color=false') ||
1447
+ hasFlag('color=never')) {
1448
+ forceColor = 0;
1449
+ } else if (hasFlag('color') ||
1450
+ hasFlag('colors') ||
1451
+ hasFlag('color=true') ||
1452
+ hasFlag('color=always')) {
1453
+ forceColor = 1;
1454
+ }
1455
+
1456
+ if ('FORCE_COLOR' in env) {
1457
+ if (env.FORCE_COLOR === 'true') {
1458
+ forceColor = 1;
1459
+ } else if (env.FORCE_COLOR === 'false') {
1460
+ forceColor = 0;
1461
+ } else {
1462
+ forceColor = env.FORCE_COLOR.length === 0 ? 1 : Math.min(parseInt(env.FORCE_COLOR, 10), 3);
1463
+ }
1464
+ }
1465
+
1466
+ function translateLevel(level) {
1467
+ if (level === 0) {
1468
+ return false;
1469
+ }
1470
+
1471
+ return {
1472
+ level,
1473
+ hasBasic: true,
1474
+ has256: level >= 2,
1475
+ has16m: level >= 3
1476
+ };
1477
+ }
1478
+
1479
+ function supportsColor(haveStream, streamIsTTY) {
1480
+ if (forceColor === 0) {
1481
+ return 0;
1482
+ }
1483
+
1484
+ if (hasFlag('color=16m') ||
1485
+ hasFlag('color=full') ||
1486
+ hasFlag('color=truecolor')) {
1487
+ return 3;
1488
+ }
1489
+
1490
+ if (hasFlag('color=256')) {
1491
+ return 2;
1492
+ }
1493
+
1494
+ if (haveStream && !streamIsTTY && forceColor === undefined) {
1495
+ return 0;
1496
+ }
1497
+
1498
+ const min = forceColor || 0;
1499
+
1500
+ if (env.TERM === 'dumb') {
1501
+ return min;
1502
+ }
1503
+
1504
+ if (process.platform === 'win32') {
1505
+ // Windows 10 build 10586 is the first Windows release that supports 256 colors.
1506
+ // Windows 10 build 14931 is the first release that supports 16m/TrueColor.
1507
+ const osRelease = os.release().split('.');
1508
+ if (
1509
+ Number(osRelease[0]) >= 10 &&
1510
+ Number(osRelease[2]) >= 10586
1511
+ ) {
1512
+ return Number(osRelease[2]) >= 14931 ? 3 : 2;
1513
+ }
1514
+
1515
+ return 1;
1516
+ }
1517
+
1518
+ if ('CI' in env) {
1519
+ if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI', 'GITHUB_ACTIONS', 'BUILDKITE'].some(sign => sign in env) || env.CI_NAME === 'codeship') {
1520
+ return 1;
1521
+ }
1522
+
1523
+ return min;
1524
+ }
1525
+
1526
+ if ('TEAMCITY_VERSION' in env) {
1527
+ return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
1528
+ }
1529
+
1530
+ if (env.COLORTERM === 'truecolor') {
1531
+ return 3;
1532
+ }
1533
+
1534
+ if ('TERM_PROGRAM' in env) {
1535
+ const version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
1536
+
1537
+ switch (env.TERM_PROGRAM) {
1538
+ case 'iTerm.app':
1539
+ return version >= 3 ? 3 : 2;
1540
+ case 'Apple_Terminal':
1541
+ return 2;
1542
+ // No default
1543
+ }
1544
+ }
1545
+
1546
+ if (/-256(color)?$/i.test(env.TERM)) {
1547
+ return 2;
1548
+ }
1549
+
1550
+ if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
1551
+ return 1;
1552
+ }
1553
+
1554
+ if ('COLORTERM' in env) {
1555
+ return 1;
1556
+ }
1557
+
1558
+ return min;
1559
+ }
1560
+
1561
+ function getSupportLevel(stream) {
1562
+ const level = supportsColor(stream, stream && stream.isTTY);
1563
+ return translateLevel(level);
1564
+ }
1565
+
1566
+ var supportsColor_1 = {
1567
+ supportsColor: getSupportLevel,
1568
+ stdout: translateLevel(supportsColor(true, tty.isatty(1))),
1569
+ stderr: translateLevel(supportsColor(true, tty.isatty(2)))
1570
+ };
1571
+
1572
+ const stringReplaceAll$1 = (string, substring, replacer) => {
1573
+ let index = string.indexOf(substring);
1574
+ if (index === -1) {
1575
+ return string;
1576
+ }
1577
+
1578
+ const substringLength = substring.length;
1579
+ let endIndex = 0;
1580
+ let returnValue = '';
1581
+ do {
1582
+ returnValue += string.substr(endIndex, index - endIndex) + substring + replacer;
1583
+ endIndex = index + substringLength;
1584
+ index = string.indexOf(substring, endIndex);
1585
+ } while (index !== -1);
1586
+
1587
+ returnValue += string.substr(endIndex);
1588
+ return returnValue;
1589
+ };
1590
+
1591
+ const stringEncaseCRLFWithFirstIndex$1 = (string, prefix, postfix, index) => {
1592
+ let endIndex = 0;
1593
+ let returnValue = '';
1594
+ do {
1595
+ const gotCR = string[index - 1] === '\r';
1596
+ returnValue += string.substr(endIndex, (gotCR ? index - 1 : index) - endIndex) + prefix + (gotCR ? '\r\n' : '\n') + postfix;
1597
+ endIndex = index + 1;
1598
+ index = string.indexOf('\n', endIndex);
1599
+ } while (index !== -1);
1600
+
1601
+ returnValue += string.substr(endIndex);
1602
+ return returnValue;
1603
+ };
1604
+
1605
+ var util = {
1606
+ stringReplaceAll: stringReplaceAll$1,
1607
+ stringEncaseCRLFWithFirstIndex: stringEncaseCRLFWithFirstIndex$1
1608
+ };
1609
+
1610
+ var templates;
1611
+ var hasRequiredTemplates;
1612
+
1613
+ function requireTemplates () {
1614
+ if (hasRequiredTemplates) return templates;
1615
+ hasRequiredTemplates = 1;
1616
+ const TEMPLATE_REGEX = /(?:\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi;
1617
+ const STYLE_REGEX = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g;
1618
+ const STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
1619
+ const ESCAPE_REGEX = /\\(u(?:[a-f\d]{4}|{[a-f\d]{1,6}})|x[a-f\d]{2}|.)|([^\\])/gi;
1620
+
1621
+ const ESCAPES = new Map([
1622
+ ['n', '\n'],
1623
+ ['r', '\r'],
1624
+ ['t', '\t'],
1625
+ ['b', '\b'],
1626
+ ['f', '\f'],
1627
+ ['v', '\v'],
1628
+ ['0', '\0'],
1629
+ ['\\', '\\'],
1630
+ ['e', '\u001B'],
1631
+ ['a', '\u0007']
1632
+ ]);
1633
+
1634
+ function unescape(c) {
1635
+ const u = c[0] === 'u';
1636
+ const bracket = c[1] === '{';
1637
+
1638
+ if ((u && !bracket && c.length === 5) || (c[0] === 'x' && c.length === 3)) {
1639
+ return String.fromCharCode(parseInt(c.slice(1), 16));
1640
+ }
1641
+
1642
+ if (u && bracket) {
1643
+ return String.fromCodePoint(parseInt(c.slice(2, -1), 16));
1644
+ }
1645
+
1646
+ return ESCAPES.get(c) || c;
1647
+ }
1648
+
1649
+ function parseArguments(name, arguments_) {
1650
+ const results = [];
1651
+ const chunks = arguments_.trim().split(/\s*,\s*/g);
1652
+ let matches;
1653
+
1654
+ for (const chunk of chunks) {
1655
+ const number = Number(chunk);
1656
+ if (!Number.isNaN(number)) {
1657
+ results.push(number);
1658
+ } else if ((matches = chunk.match(STRING_REGEX))) {
1659
+ results.push(matches[2].replace(ESCAPE_REGEX, (m, escape, character) => escape ? unescape(escape) : character));
1660
+ } else {
1661
+ throw new Error(`Invalid Chalk template style argument: ${chunk} (in style '${name}')`);
1662
+ }
1663
+ }
1664
+
1665
+ return results;
1666
+ }
1667
+
1668
+ function parseStyle(style) {
1669
+ STYLE_REGEX.lastIndex = 0;
1670
+
1671
+ const results = [];
1672
+ let matches;
1673
+
1674
+ while ((matches = STYLE_REGEX.exec(style)) !== null) {
1675
+ const name = matches[1];
1676
+
1677
+ if (matches[2]) {
1678
+ const args = parseArguments(name, matches[2]);
1679
+ results.push([name].concat(args));
1680
+ } else {
1681
+ results.push([name]);
1682
+ }
1683
+ }
1684
+
1685
+ return results;
1686
+ }
1687
+
1688
+ function buildStyle(chalk, styles) {
1689
+ const enabled = {};
1690
+
1691
+ for (const layer of styles) {
1692
+ for (const style of layer.styles) {
1693
+ enabled[style[0]] = layer.inverse ? null : style.slice(1);
1694
+ }
1695
+ }
1696
+
1697
+ let current = chalk;
1698
+ for (const [styleName, styles] of Object.entries(enabled)) {
1699
+ if (!Array.isArray(styles)) {
1700
+ continue;
1701
+ }
1702
+
1703
+ if (!(styleName in current)) {
1704
+ throw new Error(`Unknown Chalk style: ${styleName}`);
1705
+ }
1706
+
1707
+ current = styles.length > 0 ? current[styleName](...styles) : current[styleName];
1708
+ }
1709
+
1710
+ return current;
1711
+ }
1712
+
1713
+ templates = (chalk, temporary) => {
1714
+ const styles = [];
1715
+ const chunks = [];
1716
+ let chunk = [];
1717
+
1718
+ // eslint-disable-next-line max-params
1719
+ temporary.replace(TEMPLATE_REGEX, (m, escapeCharacter, inverse, style, close, character) => {
1720
+ if (escapeCharacter) {
1721
+ chunk.push(unescape(escapeCharacter));
1722
+ } else if (style) {
1723
+ const string = chunk.join('');
1724
+ chunk = [];
1725
+ chunks.push(styles.length === 0 ? string : buildStyle(chalk, styles)(string));
1726
+ styles.push({inverse, styles: parseStyle(style)});
1727
+ } else if (close) {
1728
+ if (styles.length === 0) {
1729
+ throw new Error('Found extraneous } in Chalk template literal');
1730
+ }
1731
+
1732
+ chunks.push(buildStyle(chalk, styles)(chunk.join('')));
1733
+ chunk = [];
1734
+ styles.pop();
1735
+ } else {
1736
+ chunk.push(character);
1737
+ }
1738
+ });
1739
+
1740
+ chunks.push(chunk.join(''));
1741
+
1742
+ if (styles.length > 0) {
1743
+ const errMessage = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? '' : 's'} (\`}\`)`;
1744
+ throw new Error(errMessage);
1745
+ }
1746
+
1747
+ return chunks.join('');
1748
+ };
1749
+ return templates;
1750
+ }
1751
+
1752
+ const ansiStyles = ansiStylesExports;
1753
+ const {stdout: stdoutColor, stderr: stderrColor} = supportsColor_1;
1754
+ const {
1755
+ stringReplaceAll,
1756
+ stringEncaseCRLFWithFirstIndex
1757
+ } = util;
1758
+
1759
+ const {isArray} = Array;
1760
+
1761
+ // `supportsColor.level` → `ansiStyles.color[name]` mapping
1762
+ const levelMapping = [
1763
+ 'ansi',
1764
+ 'ansi',
1765
+ 'ansi256',
1766
+ 'ansi16m'
1767
+ ];
1768
+
1769
+ const styles = Object.create(null);
1770
+
1771
+ const applyOptions = (object, options = {}) => {
1772
+ if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
1773
+ throw new Error('The `level` option should be an integer from 0 to 3');
1774
+ }
1775
+
1776
+ // Detect level if not set manually
1777
+ const colorLevel = stdoutColor ? stdoutColor.level : 0;
1778
+ object.level = options.level === undefined ? colorLevel : options.level;
1779
+ };
1780
+
1781
+ class ChalkClass {
1782
+ constructor(options) {
1783
+ // eslint-disable-next-line no-constructor-return
1784
+ return chalkFactory(options);
1785
+ }
1786
+ }
1787
+
1788
+ const chalkFactory = options => {
1789
+ const chalk = {};
1790
+ applyOptions(chalk, options);
1791
+
1792
+ chalk.template = (...arguments_) => chalkTag(chalk.template, ...arguments_);
1793
+
1794
+ Object.setPrototypeOf(chalk, Chalk.prototype);
1795
+ Object.setPrototypeOf(chalk.template, chalk);
1796
+
1797
+ chalk.template.constructor = () => {
1798
+ throw new Error('`chalk.constructor()` is deprecated. Use `new chalk.Instance()` instead.');
1799
+ };
1800
+
1801
+ chalk.template.Instance = ChalkClass;
1802
+
1803
+ return chalk.template;
1804
+ };
1805
+
1806
+ function Chalk(options) {
1807
+ return chalkFactory(options);
1808
+ }
1809
+
1810
+ for (const [styleName, style] of Object.entries(ansiStyles)) {
1811
+ styles[styleName] = {
1812
+ get() {
1813
+ const builder = createBuilder(this, createStyler(style.open, style.close, this._styler), this._isEmpty);
1814
+ Object.defineProperty(this, styleName, {value: builder});
1815
+ return builder;
1816
+ }
1817
+ };
1818
+ }
1819
+
1820
+ styles.visible = {
1821
+ get() {
1822
+ const builder = createBuilder(this, this._styler, true);
1823
+ Object.defineProperty(this, 'visible', {value: builder});
1824
+ return builder;
1825
+ }
1826
+ };
1827
+
1828
+ const usedModels = ['rgb', 'hex', 'keyword', 'hsl', 'hsv', 'hwb', 'ansi', 'ansi256'];
1829
+
1830
+ for (const model of usedModels) {
1831
+ styles[model] = {
1832
+ get() {
1833
+ const {level} = this;
1834
+ return function (...arguments_) {
1835
+ const styler = createStyler(ansiStyles.color[levelMapping[level]][model](...arguments_), ansiStyles.color.close, this._styler);
1836
+ return createBuilder(this, styler, this._isEmpty);
1837
+ };
1838
+ }
1839
+ };
1840
+ }
1841
+
1842
+ for (const model of usedModels) {
1843
+ const bgModel = 'bg' + model[0].toUpperCase() + model.slice(1);
1844
+ styles[bgModel] = {
1845
+ get() {
1846
+ const {level} = this;
1847
+ return function (...arguments_) {
1848
+ const styler = createStyler(ansiStyles.bgColor[levelMapping[level]][model](...arguments_), ansiStyles.bgColor.close, this._styler);
1849
+ return createBuilder(this, styler, this._isEmpty);
1850
+ };
1851
+ }
1852
+ };
1853
+ }
1854
+
1855
+ const proto = Object.defineProperties(() => {}, {
1856
+ ...styles,
1857
+ level: {
1858
+ enumerable: true,
1859
+ get() {
1860
+ return this._generator.level;
1861
+ },
1862
+ set(level) {
1863
+ this._generator.level = level;
1864
+ }
1865
+ }
1866
+ });
1867
+
1868
+ const createStyler = (open, close, parent) => {
1869
+ let openAll;
1870
+ let closeAll;
1871
+ if (parent === undefined) {
1872
+ openAll = open;
1873
+ closeAll = close;
1874
+ } else {
1875
+ openAll = parent.openAll + open;
1876
+ closeAll = close + parent.closeAll;
1877
+ }
1878
+
1879
+ return {
1880
+ open,
1881
+ close,
1882
+ openAll,
1883
+ closeAll,
1884
+ parent
1885
+ };
1886
+ };
1887
+
1888
+ const createBuilder = (self, _styler, _isEmpty) => {
1889
+ const builder = (...arguments_) => {
1890
+ if (isArray(arguments_[0]) && isArray(arguments_[0].raw)) {
1891
+ // Called as a template literal, for example: chalk.red`2 + 3 = {bold ${2+3}}`
1892
+ return applyStyle(builder, chalkTag(builder, ...arguments_));
1893
+ }
1894
+
1895
+ // Single argument is hot path, implicit coercion is faster than anything
1896
+ // eslint-disable-next-line no-implicit-coercion
1897
+ return applyStyle(builder, (arguments_.length === 1) ? ('' + arguments_[0]) : arguments_.join(' '));
1898
+ };
1899
+
1900
+ // We alter the prototype because we must return a function, but there is
1901
+ // no way to create a function with a different prototype
1902
+ Object.setPrototypeOf(builder, proto);
1903
+
1904
+ builder._generator = self;
1905
+ builder._styler = _styler;
1906
+ builder._isEmpty = _isEmpty;
1907
+
1908
+ return builder;
1909
+ };
1910
+
1911
+ const applyStyle = (self, string) => {
1912
+ if (self.level <= 0 || !string) {
1913
+ return self._isEmpty ? '' : string;
1914
+ }
1915
+
1916
+ let styler = self._styler;
1917
+
1918
+ if (styler === undefined) {
1919
+ return string;
1920
+ }
1921
+
1922
+ const {openAll, closeAll} = styler;
1923
+ if (string.indexOf('\u001B') !== -1) {
1924
+ while (styler !== undefined) {
1925
+ // Replace any instances already present with a re-opening code
1926
+ // otherwise only the part of the string until said closing code
1927
+ // will be colored, and the rest will simply be 'plain'.
1928
+ string = stringReplaceAll(string, styler.close, styler.open);
1929
+
1930
+ styler = styler.parent;
1931
+ }
1932
+ }
1933
+
1934
+ // We can move both next actions out of loop, because remaining actions in loop won't have
1935
+ // any/visible effect on parts we add here. Close the styling before a linebreak and reopen
1936
+ // after next line to fix a bleed issue on macOS: https://github.com/chalk/chalk/pull/92
1937
+ const lfIndex = string.indexOf('\n');
1938
+ if (lfIndex !== -1) {
1939
+ string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
1940
+ }
1941
+
1942
+ return openAll + string + closeAll;
1943
+ };
1944
+
1945
+ let template;
1946
+ const chalkTag = (chalk, ...strings) => {
1947
+ const [firstString] = strings;
1948
+
1949
+ if (!isArray(firstString) || !isArray(firstString.raw)) {
1950
+ // If chalk() was called by itself or with a string,
1951
+ // return the string itself as a string.
1952
+ return strings.join(' ');
1953
+ }
1954
+
1955
+ const arguments_ = strings.slice(1);
1956
+ const parts = [firstString.raw[0]];
1957
+
1958
+ for (let i = 1; i < firstString.length; i++) {
1959
+ parts.push(
1960
+ String(arguments_[i - 1]).replace(/[{}\\]/g, '\\$&'),
1961
+ String(firstString.raw[i])
1962
+ );
1963
+ }
1964
+
1965
+ if (template === undefined) {
1966
+ template = requireTemplates();
1967
+ }
1968
+
1969
+ return template(chalk, parts.join(''));
1970
+ };
1971
+
1972
+ Object.defineProperties(Chalk.prototype, styles);
1973
+
1974
+ const chalk = Chalk(); // eslint-disable-line new-cap
1975
+ chalk.supportsColor = stdoutColor;
1976
+ chalk.stderr = Chalk({level: stderrColor ? stderrColor.level : 0}); // eslint-disable-line new-cap
1977
+ chalk.stderr.supportsColor = stderrColor;
1978
+
1979
+ var source = chalk;
1980
+
1981
+ var chalk$1 = /*@__PURE__*/getDefaultExportFromCjs(source);
1982
+
54
1983
  class Node {
55
1984
  /// value;
56
1985
  /// next;
@@ -217,9 +2146,9 @@ async function debugOutput(url, responseStatus, startTime) {
217
2146
  endTime = performance.now();
218
2147
  elapsedTime = endTime - startTime;
219
2148
  }
220
- console.log(`${chalk.red("[DEBUG]")}` + " |" + ` Request URL: ${chalk.yellow(url)}` + " |" + ` Response code: ${responseStatus !== 200 ? chalk.red(responseStatus) : chalk.green(responseStatus)}` + " |" + ` Response time: ${chalk.cyan(elapsedTime.toFixed(2) + "ms")}`);
2149
+ console.log(`${chalk$1.red("[DEBUG]")}` + " |" + ` Request URL: ${chalk$1.yellow(url)}` + " |" + ` Response code: ${responseStatus !== 200 ? chalk$1.red(responseStatus) : chalk$1.green(responseStatus)}` + " |" + ` Response time: ${chalk$1.cyan(elapsedTime.toFixed(2) + "ms")}`);
221
2150
  }
222
- async function* paginateEndpoint$1(url, apiKey, urlsParams, dataClassConstructor, debug, threadCount, enableRetry) {
2151
+ async function* paginateEndpoint$1(url, apiKey, urlsParams, dataClassConstructor, debug, threadCount, enableRetry, source) {
223
2152
  let hasNext = true;
224
2153
  let response;
225
2154
  let data;
@@ -236,13 +2165,13 @@ async function* paginateEndpoint$1(url, apiKey, urlsParams, dataClassConstructor
236
2165
  response = await LIMIT(() => fetch(urlsParams.get("page-number") ? `${url}?${urlsParams}` : `${url}?${urlsParams}&page-number=${page_number}`, {
237
2166
  headers: {
238
2167
  "Authorization": `Bearer ${apiKey}`,
239
- "X-Requested-With": userAgent
2168
+ "X-Requested-With": source ? source + " " + "(" + userAgent + ")" : userAgent
240
2169
  }
241
2170
  }));
242
2171
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
243
2172
  if ((enableRetry === true) && (!response || response.status === null || response.status === 429)) {
244
2173
  try {
245
- data = await LIMIT(() => backoff.backOff(response ? response.url : link));
2174
+ data = await LIMIT(() => backoff.backOff(response ? response.url : link, source));
246
2175
  }
247
2176
  catch (error) {
248
2177
  hasNext = false;
@@ -384,12 +2313,13 @@ class NftApprovalSpender {
384
2313
  *
385
2314
  */
386
2315
  class SecurityService {
387
- constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true) {
2316
+ constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true, source) {
388
2317
  this.apiKey = apiKey;
389
2318
  this.debug = debug;
390
2319
  this.threadCount = threadCount;
391
2320
  this.is_key_valid = is_key_valid;
392
2321
  this.enableRetry = enableRetry;
2322
+ this.source = source;
393
2323
  this.LIMIT = pLimit$1(this.threadCount);
394
2324
  }
395
2325
  /**
@@ -424,13 +2354,13 @@ class SecurityService {
424
2354
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/approvals/${walletAddress}/?${urlParams}`, {
425
2355
  headers: {
426
2356
  "Authorization": `Bearer ${this.apiKey}`,
427
- "X-Requested-With": userAgent
2357
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
428
2358
  }
429
2359
  }));
430
2360
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
431
2361
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
432
2362
  try {
433
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
2363
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
434
2364
  }
435
2365
  catch (error) {
436
2366
  success = true;
@@ -497,13 +2427,13 @@ class SecurityService {
497
2427
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/approvals/${walletAddress}/?${urlParams}`, {
498
2428
  headers: {
499
2429
  "Authorization": `Bearer ${this.apiKey}`,
500
- "X-Requested-With": userAgent
2430
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
501
2431
  }
502
2432
  }));
503
2433
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
504
2434
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
505
2435
  try {
506
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
2436
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
507
2437
  }
508
2438
  catch (error) {
509
2439
  success = true;
@@ -822,12 +2752,13 @@ class NativeBalanceItem {
822
2752
  *
823
2753
  */
824
2754
  class BalanceService {
825
- constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true) {
2755
+ constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true, source) {
826
2756
  this.apiKey = apiKey;
827
2757
  this.debug = debug;
828
2758
  this.threadCount = threadCount;
829
2759
  this.is_key_valid = is_key_valid;
830
2760
  this.enableRetry = enableRetry;
2761
+ this.source = source;
831
2762
  this.LIMIT = pLimit$1(this.threadCount);
832
2763
  }
833
2764
  /**
@@ -883,13 +2814,13 @@ class BalanceService {
883
2814
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/balances_v2/?${urlParams}`, {
884
2815
  headers: {
885
2816
  "Authorization": `Bearer ${this.apiKey}`,
886
- "X-Requested-With": userAgent
2817
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
887
2818
  }
888
2819
  }));
889
2820
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
890
2821
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
891
2822
  try {
892
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
2823
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
893
2824
  }
894
2825
  catch (error) {
895
2826
  success = true;
@@ -966,13 +2897,13 @@ class BalanceService {
966
2897
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/portfolio_v2/?${urlParams}`, {
967
2898
  headers: {
968
2899
  "Authorization": `Bearer ${this.apiKey}`,
969
- "X-Requested-With": userAgent
2900
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
970
2901
  }
971
2902
  }));
972
2903
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
973
2904
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
974
2905
  try {
975
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
2906
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
976
2907
  }
977
2908
  catch (error) {
978
2909
  success = true;
@@ -1050,7 +2981,7 @@ class BalanceService {
1050
2981
  if (queryParamOpts?.pageNumber !== undefined) {
1051
2982
  urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
1052
2983
  }
1053
- for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transfers_v2/`, this.apiKey, urlParams, BlockTransactionWithContractTransfers, this.debug, this.threadCount, this.enableRetry)) {
2984
+ for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transfers_v2/`, this.apiKey, urlParams, BlockTransactionWithContractTransfers, this.debug, this.threadCount, this.enableRetry, this.source)) {
1054
2985
  yield res;
1055
2986
  }
1056
2987
  success = true;
@@ -1118,13 +3049,13 @@ class BalanceService {
1118
3049
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transfers_v2/?${urlParams}`, {
1119
3050
  headers: {
1120
3051
  "Authorization": `Bearer ${this.apiKey}`,
1121
- "X-Requested-With": userAgent
3052
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1122
3053
  }
1123
3054
  }));
1124
3055
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1125
3056
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1126
3057
  try {
1127
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
3058
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1128
3059
  }
1129
3060
  catch (error) {
1130
3061
  success = true;
@@ -1194,7 +3125,7 @@ class BalanceService {
1194
3125
  if (queryParamOpts?.date !== undefined) {
1195
3126
  urlParams.append("date", queryParamOpts?.date.toString());
1196
3127
  }
1197
- for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/tokens/${tokenAddress}/token_holders_v2/`, this.apiKey, urlParams, TokenHolder, this.debug, this.threadCount, this.enableRetry)) {
3128
+ for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/tokens/${tokenAddress}/token_holders_v2/`, this.apiKey, urlParams, TokenHolder, this.debug, this.threadCount, this.enableRetry, this.source)) {
1198
3129
  yield res;
1199
3130
  }
1200
3131
  success = true;
@@ -1254,13 +3185,13 @@ class BalanceService {
1254
3185
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/tokens/${tokenAddress}/token_holders_v2/?${urlParams}`, {
1255
3186
  headers: {
1256
3187
  "Authorization": `Bearer ${this.apiKey}`,
1257
- "X-Requested-With": userAgent
3188
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1258
3189
  }
1259
3190
  }));
1260
3191
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1261
3192
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1262
3193
  try {
1263
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
3194
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1264
3195
  }
1265
3196
  catch (error) {
1266
3197
  success = true;
@@ -1357,13 +3288,13 @@ class BalanceService {
1357
3288
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/historical_balances/?${urlParams}`, {
1358
3289
  headers: {
1359
3290
  "Authorization": `Bearer ${this.apiKey}`,
1360
- "X-Requested-With": userAgent
3291
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1361
3292
  }
1362
3293
  }));
1363
3294
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1364
3295
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1365
3296
  try {
1366
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
3297
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1367
3298
  }
1368
3299
  catch (error) {
1369
3300
  success = true;
@@ -1438,13 +3369,13 @@ class BalanceService {
1438
3369
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/balances_native/?${urlParams}`, {
1439
3370
  headers: {
1440
3371
  "Authorization": `Bearer ${this.apiKey}`,
1441
- "X-Requested-With": userAgent
3372
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1442
3373
  }
1443
3374
  }));
1444
3375
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1445
3376
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1446
3377
  try {
1447
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
3378
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1448
3379
  }
1449
3380
  catch (error) {
1450
3381
  success = true;
@@ -1703,12 +3634,13 @@ class OtherFees {
1703
3634
  *
1704
3635
  */
1705
3636
  class BaseService {
1706
- constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true) {
3637
+ constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true, source) {
1707
3638
  this.apiKey = apiKey;
1708
3639
  this.debug = debug;
1709
3640
  this.threadCount = threadCount;
1710
3641
  this.is_key_valid = is_key_valid;
1711
3642
  this.enableRetry = enableRetry;
3643
+ this.source = source;
1712
3644
  this.LIMIT = pLimit$1(this.threadCount);
1713
3645
  }
1714
3646
  /**
@@ -1743,13 +3675,13 @@ class BaseService {
1743
3675
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/block_v2/${blockHeight}/?${urlParams}`, {
1744
3676
  headers: {
1745
3677
  "Authorization": `Bearer ${this.apiKey}`,
1746
- "X-Requested-With": userAgent
3678
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1747
3679
  }
1748
3680
  }));
1749
3681
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1750
3682
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1751
3683
  try {
1752
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
3684
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1753
3685
  }
1754
3686
  catch (error) {
1755
3687
  success = true;
@@ -1817,13 +3749,13 @@ class BaseService {
1817
3749
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/resolve_address/?${urlParams}`, {
1818
3750
  headers: {
1819
3751
  "Authorization": `Bearer ${this.apiKey}`,
1820
- "X-Requested-With": userAgent
3752
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1821
3753
  }
1822
3754
  }));
1823
3755
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1824
3756
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1825
3757
  try {
1826
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
3758
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1827
3759
  }
1828
3760
  catch (error) {
1829
3761
  success = true;
@@ -1886,7 +3818,7 @@ class BaseService {
1886
3818
  if (queryParamOpts?.pageNumber !== undefined) {
1887
3819
  urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
1888
3820
  }
1889
- for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/block_v2/${startDate}/${endDate}/`, this.apiKey, urlParams, Block, this.debug, this.threadCount, this.enableRetry)) {
3821
+ for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/block_v2/${startDate}/${endDate}/`, this.apiKey, urlParams, Block, this.debug, this.threadCount, this.enableRetry, this.source)) {
1890
3822
  yield res;
1891
3823
  }
1892
3824
  success = true;
@@ -1939,13 +3871,13 @@ class BaseService {
1939
3871
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/block_v2/${startDate}/${endDate}/?${urlParams}`, {
1940
3872
  headers: {
1941
3873
  "Authorization": `Bearer ${this.apiKey}`,
1942
- "X-Requested-With": userAgent
3874
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1943
3875
  }
1944
3876
  }));
1945
3877
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1946
3878
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1947
3879
  try {
1948
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
3880
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1949
3881
  }
1950
3882
  catch (error) {
1951
3883
  success = true;
@@ -2037,13 +3969,13 @@ class BaseService {
2037
3969
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/events/?${urlParams}`, {
2038
3970
  headers: {
2039
3971
  "Authorization": `Bearer ${this.apiKey}`,
2040
- "X-Requested-With": userAgent
3972
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
2041
3973
  }
2042
3974
  }));
2043
3975
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
2044
3976
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
2045
3977
  try {
2046
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
3978
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
2047
3979
  }
2048
3980
  catch (error) {
2049
3981
  success = true;
@@ -2113,7 +4045,7 @@ class BaseService {
2113
4045
  if (queryParamOpts?.pageNumber !== undefined) {
2114
4046
  urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
2115
4047
  }
2116
- for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/events/address/${contractAddress}/`, this.apiKey, urlParams, LogEvent$2, this.debug, this.threadCount, this.enableRetry)) {
4048
+ for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/events/address/${contractAddress}/`, this.apiKey, urlParams, LogEvent$2, this.debug, this.threadCount, this.enableRetry, this.source)) {
2117
4049
  yield res;
2118
4050
  }
2119
4051
  success = true;
@@ -2173,13 +4105,13 @@ class BaseService {
2173
4105
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/events/address/${contractAddress}/?${urlParams}`, {
2174
4106
  headers: {
2175
4107
  "Authorization": `Bearer ${this.apiKey}`,
2176
- "X-Requested-With": userAgent
4108
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
2177
4109
  }
2178
4110
  }));
2179
4111
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
2180
4112
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
2181
4113
  try {
2182
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
4114
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
2183
4115
  }
2184
4116
  catch (error) {
2185
4117
  success = true;
@@ -2253,7 +4185,7 @@ class BaseService {
2253
4185
  if (queryParamOpts?.pageNumber !== undefined) {
2254
4186
  urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
2255
4187
  }
2256
- for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/events/topics/${topicHash}/`, this.apiKey, urlParams, LogEvent$2, this.debug, this.threadCount, this.enableRetry)) {
4188
+ for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/events/topics/${topicHash}/`, this.apiKey, urlParams, LogEvent$2, this.debug, this.threadCount, this.enableRetry, this.source)) {
2257
4189
  yield res;
2258
4190
  }
2259
4191
  success = true;
@@ -2317,13 +4249,13 @@ class BaseService {
2317
4249
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/events/topics/${topicHash}/?${urlParams}`, {
2318
4250
  headers: {
2319
4251
  "Authorization": `Bearer ${this.apiKey}`,
2320
- "X-Requested-With": userAgent
4252
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
2321
4253
  }
2322
4254
  }));
2323
4255
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
2324
4256
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
2325
4257
  try {
2326
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
4258
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
2327
4259
  }
2328
4260
  catch (error) {
2329
4261
  success = true;
@@ -2389,13 +4321,13 @@ class BaseService {
2389
4321
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/chains/?${urlParams}`, {
2390
4322
  headers: {
2391
4323
  "Authorization": `Bearer ${this.apiKey}`,
2392
- "X-Requested-With": userAgent
4324
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
2393
4325
  }
2394
4326
  }));
2395
4327
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
2396
4328
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
2397
4329
  try {
2398
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
4330
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
2399
4331
  }
2400
4332
  catch (error) {
2401
4333
  success = true;
@@ -2461,13 +4393,13 @@ class BaseService {
2461
4393
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/chains/status/?${urlParams}`, {
2462
4394
  headers: {
2463
4395
  "Authorization": `Bearer ${this.apiKey}`,
2464
- "X-Requested-With": userAgent
4396
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
2465
4397
  }
2466
4398
  }));
2467
4399
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
2468
4400
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
2469
4401
  try {
2470
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
4402
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
2471
4403
  }
2472
4404
  catch (error) {
2473
4405
  success = true;
@@ -2539,13 +4471,13 @@ class BaseService {
2539
4471
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/address/${walletAddress}/activity/?${urlParams}`, {
2540
4472
  headers: {
2541
4473
  "Authorization": `Bearer ${this.apiKey}`,
2542
- "X-Requested-With": userAgent
4474
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
2543
4475
  }
2544
4476
  }));
2545
4477
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
2546
4478
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
2547
4479
  try {
2548
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
4480
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
2549
4481
  }
2550
4482
  catch (error) {
2551
4483
  success = true;
@@ -2616,13 +4548,13 @@ class BaseService {
2616
4548
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/event/${eventType}/gas_prices/?${urlParams}`, {
2617
4549
  headers: {
2618
4550
  "Authorization": `Bearer ${this.apiKey}`,
2619
- "X-Requested-With": userAgent
4551
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
2620
4552
  }
2621
4553
  }));
2622
4554
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
2623
4555
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
2624
4556
  try {
2625
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
4557
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
2626
4558
  }
2627
4559
  catch (error) {
2628
4560
  success = true;
@@ -2982,12 +4914,13 @@ class MarketFloorPriceItem {
2982
4914
  *
2983
4915
  */
2984
4916
  class NftService {
2985
- constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true) {
4917
+ constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true, source) {
2986
4918
  this.apiKey = apiKey;
2987
4919
  this.debug = debug;
2988
4920
  this.threadCount = threadCount;
2989
4921
  this.is_key_valid = is_key_valid;
2990
4922
  this.enableRetry = enableRetry;
4923
+ this.source = source;
2991
4924
  this.LIMIT = pLimit$1(this.threadCount);
2992
4925
  }
2993
4926
  /**
@@ -3019,7 +4952,7 @@ class NftService {
3019
4952
  if (queryParamOpts?.noSpam !== undefined) {
3020
4953
  urlParams.append("no-spam", queryParamOpts?.noSpam.toString());
3021
4954
  }
3022
- for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/nft/collections/`, this.apiKey, urlParams, ChainCollectionItem, this.debug, this.threadCount, this.enableRetry)) {
4955
+ for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/nft/collections/`, this.apiKey, urlParams, ChainCollectionItem, this.debug, this.threadCount, this.enableRetry, this.source)) {
3023
4956
  yield res;
3024
4957
  }
3025
4958
  success = true;
@@ -3074,13 +5007,13 @@ class NftService {
3074
5007
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/collections/?${urlParams}`, {
3075
5008
  headers: {
3076
5009
  "Authorization": `Bearer ${this.apiKey}`,
3077
- "X-Requested-With": userAgent
5010
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
3078
5011
  }
3079
5012
  }));
3080
5013
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
3081
5014
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
3082
5015
  try {
3083
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
5016
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
3084
5017
  }
3085
5018
  catch (error) {
3086
5019
  success = true;
@@ -3161,13 +5094,13 @@ class NftService {
3161
5094
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/balances_nft/?${urlParams}`, {
3162
5095
  headers: {
3163
5096
  "Authorization": `Bearer ${this.apiKey}`,
3164
- "X-Requested-With": userAgent
5097
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
3165
5098
  }
3166
5099
  }));
3167
5100
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
3168
5101
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
3169
5102
  try {
3170
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
5103
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
3171
5104
  }
3172
5105
  catch (error) {
3173
5106
  success = true;
@@ -3245,7 +5178,7 @@ class NftService {
3245
5178
  if (queryParamOpts?.withUncached !== undefined) {
3246
5179
  urlParams.append("with-uncached", queryParamOpts?.withUncached.toString());
3247
5180
  }
3248
- for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/nft/${contractAddress}/metadata/`, this.apiKey, urlParams, NftTokenContract, this.debug, this.threadCount, this.enableRetry)) {
5181
+ for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/nft/${contractAddress}/metadata/`, this.apiKey, urlParams, NftTokenContract, this.debug, this.threadCount, this.enableRetry, this.source)) {
3249
5182
  yield res;
3250
5183
  }
3251
5184
  success = true;
@@ -3313,13 +5246,13 @@ class NftService {
3313
5246
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${contractAddress}/metadata/?${urlParams}`, {
3314
5247
  headers: {
3315
5248
  "Authorization": `Bearer ${this.apiKey}`,
3316
- "X-Requested-With": userAgent
5249
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
3317
5250
  }
3318
5251
  }));
3319
5252
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
3320
5253
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
3321
5254
  try {
3322
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
5255
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
3323
5256
  }
3324
5257
  catch (error) {
3325
5258
  success = true;
@@ -3397,13 +5330,13 @@ class NftService {
3397
5330
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${contractAddress}/metadata/${tokenId}/?${urlParams}`, {
3398
5331
  headers: {
3399
5332
  "Authorization": `Bearer ${this.apiKey}`,
3400
- "X-Requested-With": userAgent
5333
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
3401
5334
  }
3402
5335
  }));
3403
5336
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
3404
5337
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
3405
5338
  try {
3406
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
5339
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
3407
5340
  }
3408
5341
  catch (error) {
3409
5342
  success = true;
@@ -3477,13 +5410,13 @@ class NftService {
3477
5410
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/tokens/${contractAddress}/nft_transactions/${tokenId}/?${urlParams}`, {
3478
5411
  headers: {
3479
5412
  "Authorization": `Bearer ${this.apiKey}`,
3480
- "X-Requested-With": userAgent
5413
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
3481
5414
  }
3482
5415
  }));
3483
5416
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
3484
5417
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
3485
5418
  try {
3486
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
5419
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
3487
5420
  }
3488
5421
  catch (error) {
3489
5422
  success = true;
@@ -3551,13 +5484,13 @@ class NftService {
3551
5484
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits/?${urlParams}`, {
3552
5485
  headers: {
3553
5486
  "Authorization": `Bearer ${this.apiKey}`,
3554
- "X-Requested-With": userAgent
5487
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
3555
5488
  }
3556
5489
  }));
3557
5490
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
3558
5491
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
3559
5492
  try {
3560
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
5493
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
3561
5494
  }
3562
5495
  catch (error) {
3563
5496
  success = true;
@@ -3626,13 +5559,13 @@ class NftService {
3626
5559
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits/${trait}/attributes/?${urlParams}`, {
3627
5560
  headers: {
3628
5561
  "Authorization": `Bearer ${this.apiKey}`,
3629
- "X-Requested-With": userAgent
5562
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
3630
5563
  }
3631
5564
  }));
3632
5565
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
3633
5566
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
3634
5567
  try {
3635
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
5568
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
3636
5569
  }
3637
5570
  catch (error) {
3638
5571
  success = true;
@@ -3700,13 +5633,13 @@ class NftService {
3700
5633
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits_summary/?${urlParams}`, {
3701
5634
  headers: {
3702
5635
  "Authorization": `Bearer ${this.apiKey}`,
3703
- "X-Requested-With": userAgent
5636
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
3704
5637
  }
3705
5638
  }));
3706
5639
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
3707
5640
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
3708
5641
  try {
3709
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
5642
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
3710
5643
  }
3711
5644
  catch (error) {
3712
5645
  success = true;
@@ -3775,13 +5708,13 @@ class NftService {
3775
5708
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/collection/${collectionContract}/?${urlParams}`, {
3776
5709
  headers: {
3777
5710
  "Authorization": `Bearer ${this.apiKey}`,
3778
- "X-Requested-With": userAgent
5711
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
3779
5712
  }
3780
5713
  }));
3781
5714
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
3782
5715
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
3783
5716
  try {
3784
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
5717
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
3785
5718
  }
3786
5719
  catch (error) {
3787
5720
  success = true;
@@ -3851,13 +5784,13 @@ class NftService {
3851
5784
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/collection/${collectionContract}/token/${tokenId}/?${urlParams}`, {
3852
5785
  headers: {
3853
5786
  "Authorization": `Bearer ${this.apiKey}`,
3854
- "X-Requested-With": userAgent
5787
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
3855
5788
  }
3856
5789
  }));
3857
5790
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
3858
5791
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
3859
5792
  try {
3860
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
5793
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
3861
5794
  }
3862
5795
  catch (error) {
3863
5796
  success = true;
@@ -3934,13 +5867,13 @@ class NftService {
3934
5867
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft_market/${contractAddress}/sale_count/?${urlParams}`, {
3935
5868
  headers: {
3936
5869
  "Authorization": `Bearer ${this.apiKey}`,
3937
- "X-Requested-With": userAgent
5870
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
3938
5871
  }
3939
5872
  }));
3940
5873
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
3941
5874
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
3942
5875
  try {
3943
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
5876
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
3944
5877
  }
3945
5878
  catch (error) {
3946
5879
  success = true;
@@ -4017,13 +5950,13 @@ class NftService {
4017
5950
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft_market/${contractAddress}/volume/?${urlParams}`, {
4018
5951
  headers: {
4019
5952
  "Authorization": `Bearer ${this.apiKey}`,
4020
- "X-Requested-With": userAgent
5953
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
4021
5954
  }
4022
5955
  }));
4023
5956
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
4024
5957
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
4025
5958
  try {
4026
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
5959
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
4027
5960
  }
4028
5961
  catch (error) {
4029
5962
  success = true;
@@ -4100,13 +6033,13 @@ class NftService {
4100
6033
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft_market/${contractAddress}/floor_price/?${urlParams}`, {
4101
6034
  headers: {
4102
6035
  "Authorization": `Bearer ${this.apiKey}`,
4103
- "X-Requested-With": userAgent
6036
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
4104
6037
  }
4105
6038
  }));
4106
6039
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
4107
6040
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
4108
6041
  try {
4109
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
6042
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
4110
6043
  }
4111
6044
  catch (error) {
4112
6045
  success = true;
@@ -4177,12 +6110,13 @@ let ContractMetadata$2 = class ContractMetadata {
4177
6110
  }
4178
6111
  };
4179
6112
  class PricingService {
4180
- constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true) {
6113
+ constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true, source) {
4181
6114
  this.apiKey = apiKey;
4182
6115
  this.debug = debug;
4183
6116
  this.threadCount = threadCount;
4184
6117
  this.is_key_valid = is_key_valid;
4185
6118
  this.enableRetry = enableRetry;
6119
+ this.source = source;
4186
6120
  this.LIMIT = pLimit$1(this.threadCount);
4187
6121
  }
4188
6122
  /**
@@ -4231,13 +6165,13 @@ class PricingService {
4231
6165
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/pricing/historical_by_addresses_v2/${chainName}/${quoteCurrency}/${contractAddress}/?${urlParams}`, {
4232
6166
  headers: {
4233
6167
  "Authorization": `Bearer ${this.apiKey}`,
4234
- "X-Requested-With": userAgent
6168
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
4235
6169
  }
4236
6170
  }));
4237
6171
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
4238
6172
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
4239
6173
  try {
4240
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
6174
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
4241
6175
  }
4242
6176
  catch (error) {
4243
6177
  success = true;
@@ -4483,28 +6417,184 @@ class DecodedItem {
4483
6417
  this.params = data.params && data.params !== null ? data.params.map((itemData) => new Param(itemData)) : null;
4484
6418
  }
4485
6419
  }
4486
- class Param {
6420
+ class Param {
6421
+ constructor(data) {
6422
+ this.name = data.name;
6423
+ this.type = data.type;
6424
+ this.indexed = data.indexed;
6425
+ this.decoded = data.decoded;
6426
+ this.value = data.value;
6427
+ }
6428
+ }
6429
+ class RecentTransactionsResponse {
6430
+ constructor(data, _debug, _apiKey, _threadCount, _urlParams, _enableRetry, _source) {
6431
+ this._debug = _debug;
6432
+ this._apiKey = _apiKey;
6433
+ this._threadCount = _threadCount;
6434
+ this._urlParams = _urlParams;
6435
+ this._enableRetry = _enableRetry;
6436
+ this._source = _source;
6437
+ this.address = data.address;
6438
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
6439
+ this.quote_currency = data.quote_currency;
6440
+ this.chain_id = data.chain_id;
6441
+ this.chain_name = data.chain_name;
6442
+ this.current_page = data.current_page;
6443
+ this.links = data.links && data.links !== null ? new PaginationLinks(data.links) : null;
6444
+ this.items = data.items && data.items !== null ? data.items.map((itemData) => new Transaction(itemData)) : null;
6445
+ }
6446
+ async prev() {
6447
+ let success = false;
6448
+ let data;
6449
+ let response;
6450
+ const backoff = new ExponentialBackoff(this._apiKey, this._debug);
6451
+ const LIMIT = pLimit$1(this._threadCount);
6452
+ while (!success) {
6453
+ try {
6454
+ let startTime;
6455
+ if (this._debug) {
6456
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
6457
+ }
6458
+ if (this.links.prev === null) {
6459
+ success = true;
6460
+ return {
6461
+ data: null,
6462
+ error: true,
6463
+ error_code: 400,
6464
+ error_message: "Invalid URL: URL link cannot be null"
6465
+ };
6466
+ }
6467
+ const url = `${this.links.prev}?${this._urlParams}`;
6468
+ response = await LIMIT(() => fetch(`${this.links.prev}?${this._urlParams}`, {
6469
+ headers: {
6470
+ "Authorization": `Bearer ${this._apiKey}`,
6471
+ "X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
6472
+ }
6473
+ }));
6474
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
6475
+ if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
6476
+ try {
6477
+ data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
6478
+ }
6479
+ catch (error) {
6480
+ success = true;
6481
+ return {
6482
+ data: null,
6483
+ error: true,
6484
+ error_code: response.status ?? 429,
6485
+ error_message: error.message
6486
+ };
6487
+ }
6488
+ }
6489
+ else {
6490
+ data = await response.json();
6491
+ }
6492
+ const dataClass = new RecentTransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
6493
+ checkAndModifyResponse(dataClass);
6494
+ success = true;
6495
+ return {
6496
+ data: dataClass,
6497
+ error: data.error,
6498
+ error_code: data ? data.error_code : response.status,
6499
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
6500
+ };
6501
+ }
6502
+ catch (error) {
6503
+ success = true;
6504
+ return {
6505
+ data: null,
6506
+ error: true,
6507
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
6508
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
6509
+ };
6510
+ }
6511
+ }
6512
+ }
6513
+ async next() {
6514
+ let success = false;
6515
+ let data;
6516
+ let response;
6517
+ const backoff = new ExponentialBackoff(this._apiKey, this._debug);
6518
+ const LIMIT = pLimit$1(this._threadCount);
6519
+ while (!success) {
6520
+ try {
6521
+ let startTime;
6522
+ if (this._debug) {
6523
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
6524
+ }
6525
+ if (this.links.next === null) {
6526
+ success = true;
6527
+ return {
6528
+ data: null,
6529
+ error: true,
6530
+ error_code: 400,
6531
+ error_message: "Invalid URL: URL link cannot be null"
6532
+ };
6533
+ }
6534
+ const url = `${this.links.next}?${this._urlParams}`;
6535
+ response = await LIMIT(() => fetch(`${this.links.next}?${this._urlParams}`, {
6536
+ headers: {
6537
+ "Authorization": `Bearer ${this._apiKey}`,
6538
+ "X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
6539
+ }
6540
+ }));
6541
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
6542
+ if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
6543
+ try {
6544
+ data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
6545
+ }
6546
+ catch (error) {
6547
+ success = true;
6548
+ return {
6549
+ data: null,
6550
+ error: true,
6551
+ error_code: response.status ?? 429,
6552
+ error_message: error.message
6553
+ };
6554
+ }
6555
+ }
6556
+ else {
6557
+ data = await response.json();
6558
+ }
6559
+ const dataClass = new RecentTransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
6560
+ checkAndModifyResponse(dataClass);
6561
+ success = true;
6562
+ return {
6563
+ data: dataClass,
6564
+ error: data.error,
6565
+ error_code: data ? data.error_code : response.status,
6566
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
6567
+ };
6568
+ }
6569
+ catch (error) {
6570
+ success = true;
6571
+ return {
6572
+ data: null,
6573
+ error: true,
6574
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
6575
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
6576
+ };
6577
+ }
6578
+ }
6579
+ }
6580
+ }
6581
+ class PaginationLinks {
4487
6582
  constructor(data) {
4488
- this.name = data.name;
4489
- this.type = data.type;
4490
- this.indexed = data.indexed;
4491
- this.decoded = data.decoded;
4492
- this.value = data.value;
6583
+ this.prev = data.prev;
6584
+ this.next = data.next;
4493
6585
  }
4494
6586
  }
4495
- class RecentTransactionsResponse {
4496
- constructor(data, _debug, _apiKey, _threadCount, _urlParams, _enableRetry) {
6587
+ class TransactionsBlockPageResponse {
6588
+ constructor(data, _debug, _apiKey, _threadCount, _urlParams, _enableRetry, _source) {
4497
6589
  this._debug = _debug;
4498
6590
  this._apiKey = _apiKey;
4499
6591
  this._threadCount = _threadCount;
4500
6592
  this._urlParams = _urlParams;
4501
6593
  this._enableRetry = _enableRetry;
4502
- this.address = data.address;
6594
+ this._source = _source;
4503
6595
  this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
4504
- this.quote_currency = data.quote_currency;
4505
6596
  this.chain_id = data.chain_id;
4506
6597
  this.chain_name = data.chain_name;
4507
- this.current_page = data.current_page;
4508
6598
  this.links = data.links && data.links !== null ? new PaginationLinks(data.links) : null;
4509
6599
  this.items = data.items && data.items !== null ? data.items.map((itemData) => new Transaction(itemData)) : null;
4510
6600
  }
@@ -4533,13 +6623,13 @@ class RecentTransactionsResponse {
4533
6623
  response = await LIMIT(() => fetch(`${this.links.prev}?${this._urlParams}`, {
4534
6624
  headers: {
4535
6625
  "Authorization": `Bearer ${this._apiKey}`,
4536
- "X-Requested-With": userAgent
6626
+ "X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
4537
6627
  }
4538
6628
  }));
4539
6629
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
4540
6630
  if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
4541
6631
  try {
4542
- data = await LIMIT(() => backoff.backOff(response ? response.url : url));
6632
+ data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
4543
6633
  }
4544
6634
  catch (error) {
4545
6635
  success = true;
@@ -4554,7 +6644,7 @@ class RecentTransactionsResponse {
4554
6644
  else {
4555
6645
  data = await response.json();
4556
6646
  }
4557
- const dataClass = new RecentTransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry);
6647
+ const dataClass = new TransactionsBlockPageResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
4558
6648
  checkAndModifyResponse(dataClass);
4559
6649
  success = true;
4560
6650
  return {
@@ -4600,13 +6690,13 @@ class RecentTransactionsResponse {
4600
6690
  response = await LIMIT(() => fetch(`${this.links.next}?${this._urlParams}`, {
4601
6691
  headers: {
4602
6692
  "Authorization": `Bearer ${this._apiKey}`,
4603
- "X-Requested-With": userAgent
6693
+ "X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
4604
6694
  }
4605
6695
  }));
4606
6696
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
4607
6697
  if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
4608
6698
  try {
4609
- data = await LIMIT(() => backoff.backOff(response ? response.url : url));
6699
+ data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
4610
6700
  }
4611
6701
  catch (error) {
4612
6702
  success = true;
@@ -4621,7 +6711,7 @@ class RecentTransactionsResponse {
4621
6711
  else {
4622
6712
  data = await response.json();
4623
6713
  }
4624
- const dataClass = new RecentTransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry);
6714
+ const dataClass = new TransactionsBlockPageResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
4625
6715
  checkAndModifyResponse(dataClass);
4626
6716
  success = true;
4627
6717
  return {
@@ -4643,12 +6733,6 @@ class RecentTransactionsResponse {
4643
6733
  }
4644
6734
  }
4645
6735
  }
4646
- class PaginationLinks {
4647
- constructor(data) {
4648
- this.prev = data.prev;
4649
- this.next = data.next;
4650
- }
4651
- }
4652
6736
  class TransactionsBlockResponse {
4653
6737
  constructor(data) {
4654
6738
  this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
@@ -4681,12 +6765,13 @@ class TransactionSummary {
4681
6765
  }
4682
6766
  }
4683
6767
  class TransactionsResponse {
4684
- constructor(data, _debug, _apiKey, _threadCount, _urlParams, _enableRetry) {
6768
+ constructor(data, _debug, _apiKey, _threadCount, _urlParams, _enableRetry, _source) {
4685
6769
  this._debug = _debug;
4686
6770
  this._apiKey = _apiKey;
4687
6771
  this._threadCount = _threadCount;
4688
6772
  this._urlParams = _urlParams;
4689
6773
  this._enableRetry = _enableRetry;
6774
+ this._source = _source;
4690
6775
  this.address = data.address;
4691
6776
  this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
4692
6777
  this.quote_currency = data.quote_currency;
@@ -4721,13 +6806,13 @@ class TransactionsResponse {
4721
6806
  response = await LIMIT(() => fetch(`${this.links.prev}?${this._urlParams}`, {
4722
6807
  headers: {
4723
6808
  "Authorization": `Bearer ${this._apiKey}`,
4724
- "X-Requested-With": userAgent
6809
+ "X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
4725
6810
  }
4726
6811
  }));
4727
6812
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
4728
6813
  if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
4729
6814
  try {
4730
- data = await LIMIT(() => backoff.backOff(response ? response.url : url));
6815
+ data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
4731
6816
  }
4732
6817
  catch (error) {
4733
6818
  success = true;
@@ -4742,7 +6827,7 @@ class TransactionsResponse {
4742
6827
  else {
4743
6828
  data = await response.json();
4744
6829
  }
4745
- const dataClass = new TransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry);
6830
+ const dataClass = new TransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
4746
6831
  checkAndModifyResponse(dataClass);
4747
6832
  success = true;
4748
6833
  return {
@@ -4788,13 +6873,13 @@ class TransactionsResponse {
4788
6873
  response = await LIMIT(() => fetch(`${this.links.next}?${this._urlParams}`, {
4789
6874
  headers: {
4790
6875
  "Authorization": `Bearer ${this._apiKey}`,
4791
- "X-Requested-With": userAgent
6876
+ "X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
4792
6877
  }
4793
6878
  }));
4794
6879
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
4795
6880
  if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
4796
6881
  try {
4797
- data = await LIMIT(() => backoff.backOff(response ? response.url : url));
6882
+ data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
4798
6883
  }
4799
6884
  catch (error) {
4800
6885
  success = true;
@@ -4809,7 +6894,7 @@ class TransactionsResponse {
4809
6894
  else {
4810
6895
  data = await response.json();
4811
6896
  }
4812
- const dataClass = new TransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry);
6897
+ const dataClass = new TransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
4813
6898
  checkAndModifyResponse(dataClass);
4814
6899
  success = true;
4815
6900
  return {
@@ -4832,12 +6917,13 @@ class TransactionsResponse {
4832
6917
  }
4833
6918
  }
4834
6919
  class TransactionsTimeBucketResponse {
4835
- constructor(data, _debug, _apiKey, _threadCount, _urlParams, _enableRetry) {
6920
+ constructor(data, _debug, _apiKey, _threadCount, _urlParams, _enableRetry, _source) {
4836
6921
  this._debug = _debug;
4837
6922
  this._apiKey = _apiKey;
4838
6923
  this._threadCount = _threadCount;
4839
6924
  this._urlParams = _urlParams;
4840
6925
  this._enableRetry = _enableRetry;
6926
+ this._source = _source;
4841
6927
  this.address = data.address;
4842
6928
  this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
4843
6929
  this.quote_currency = data.quote_currency;
@@ -4873,13 +6959,13 @@ class TransactionsTimeBucketResponse {
4873
6959
  response = await LIMIT(() => fetch(`${this.links.prev}?${this._urlParams}`, {
4874
6960
  headers: {
4875
6961
  "Authorization": `Bearer ${this._apiKey}`,
4876
- "X-Requested-With": userAgent
6962
+ "X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
4877
6963
  }
4878
6964
  }));
4879
6965
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
4880
6966
  if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
4881
6967
  try {
4882
- data = await LIMIT(() => backoff.backOff(response ? response.url : url));
6968
+ data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
4883
6969
  }
4884
6970
  catch (error) {
4885
6971
  success = true;
@@ -4894,7 +6980,7 @@ class TransactionsTimeBucketResponse {
4894
6980
  else {
4895
6981
  data = await response.json();
4896
6982
  }
4897
- const dataClass = new TransactionsTimeBucketResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry);
6983
+ const dataClass = new TransactionsTimeBucketResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
4898
6984
  checkAndModifyResponse(dataClass);
4899
6985
  success = true;
4900
6986
  return {
@@ -4940,13 +7026,13 @@ class TransactionsTimeBucketResponse {
4940
7026
  response = await LIMIT(() => fetch(`${this.links.next}?${this._urlParams}`, {
4941
7027
  headers: {
4942
7028
  "Authorization": `Bearer ${this._apiKey}`,
4943
- "X-Requested-With": userAgent
7029
+ "X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
4944
7030
  }
4945
7031
  }));
4946
7032
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
4947
7033
  if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
4948
7034
  try {
4949
- data = await LIMIT(() => backoff.backOff(response ? response.url : url));
7035
+ data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
4950
7036
  }
4951
7037
  catch (error) {
4952
7038
  success = true;
@@ -4961,7 +7047,7 @@ class TransactionsTimeBucketResponse {
4961
7047
  else {
4962
7048
  data = await response.json();
4963
7049
  }
4964
- const dataClass = new TransactionsTimeBucketResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry);
7050
+ const dataClass = new TransactionsTimeBucketResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
4965
7051
  checkAndModifyResponse(dataClass);
4966
7052
  success = true;
4967
7053
  return {
@@ -4987,7 +7073,7 @@ class TransactionsTimeBucketResponse {
4987
7073
  * Transactions APIs
4988
7074
  *
4989
7075
  */
4990
- async function* paginateEndpoint(url, apiKey, urlsParams, debug, threadCount, enableRetry) {
7076
+ async function* paginateEndpoint(url, apiKey, urlsParams, debug, threadCount, enableRetry, source) {
4991
7077
  let hasNext = true;
4992
7078
  let response;
4993
7079
  let data;
@@ -5002,13 +7088,13 @@ async function* paginateEndpoint(url, apiKey, urlsParams, debug, threadCount, en
5002
7088
  response = await LIMIT(() => fetch(`${url}?${urlsParams}`, {
5003
7089
  headers: {
5004
7090
  "Authorization": `Bearer ${apiKey}`,
5005
- "X-Requested-With": userAgent
7091
+ "X-Requested-With": source ? source + " " + "(" + userAgent + ")" : userAgent
5006
7092
  }
5007
7093
  }));
5008
7094
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
5009
7095
  if ((enableRetry === true) && (!response || response.status === null || response.status === 429)) {
5010
7096
  try {
5011
- data = await LIMIT(() => backoff.backOff(response ? response.url : `${url}?${urlsParams}`));
7097
+ data = await LIMIT(() => backoff.backOff(response ? response.url : `${url}?${urlsParams}`, this.source));
5012
7098
  }
5013
7099
  catch (error) {
5014
7100
  hasNext = false;
@@ -5044,12 +7130,13 @@ async function* paginateEndpoint(url, apiKey, urlsParams, debug, threadCount, en
5044
7130
  }
5045
7131
  }
5046
7132
  class TransactionService {
5047
- constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true) {
7133
+ constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true, source) {
5048
7134
  this.apiKey = apiKey;
5049
7135
  this.debug = debug;
5050
7136
  this.threadCount = threadCount;
5051
7137
  this.is_key_valid = is_key_valid;
5052
7138
  this.enableRetry = enableRetry;
7139
+ this.source = source;
5053
7140
  this.LIMIT = pLimit$1(this.threadCount);
5054
7141
  }
5055
7142
  /**
@@ -5109,13 +7196,13 @@ class TransactionService {
5109
7196
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/transaction_v2/${txHash}/?${urlParams}`, {
5110
7197
  headers: {
5111
7198
  "Authorization": `Bearer ${this.apiKey}`,
5112
- "X-Requested-With": userAgent
7199
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
5113
7200
  }
5114
7201
  }));
5115
7202
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
5116
7203
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
5117
7204
  try {
5118
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
7205
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
5119
7206
  }
5120
7207
  catch (error) {
5121
7208
  success = true;
@@ -5185,7 +7272,7 @@ class TransactionService {
5185
7272
  if (queryParamOpts?.withSafe !== undefined) {
5186
7273
  urlParams.append("with-safe", queryParamOpts?.withSafe.toString());
5187
7274
  }
5188
- for await (tx of paginateEndpoint(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/`, this.apiKey, urlParams, this.debug, this.threadCount, this.enableRetry)) {
7275
+ for await (tx of paginateEndpoint(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/`, this.apiKey, urlParams, this.debug, this.threadCount, this.enableRetry, this.source)) {
5189
7276
  yield tx;
5190
7277
  }
5191
7278
  success = true;
@@ -5245,13 +7332,13 @@ class TransactionService {
5245
7332
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/?${urlParams}`, {
5246
7333
  headers: {
5247
7334
  "Authorization": `Bearer ${this.apiKey}`,
5248
- "X-Requested-With": userAgent
7335
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
5249
7336
  }
5250
7337
  }));
5251
7338
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
5252
7339
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
5253
7340
  try {
5254
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
7341
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
5255
7342
  }
5256
7343
  catch (error) {
5257
7344
  success = true;
@@ -5266,7 +7353,7 @@ class TransactionService {
5266
7353
  else {
5267
7354
  data = await response.json();
5268
7355
  }
5269
- const dataClass = new RecentTransactionsResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams, this.enableRetry);
7356
+ const dataClass = new RecentTransactionsResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams, this.enableRetry, this.source);
5270
7357
  checkAndModifyResponse(dataClass);
5271
7358
  success = true;
5272
7359
  return {
@@ -5332,13 +7419,13 @@ class TransactionService {
5332
7419
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/block/${blockHeight}/transactions_v3/?${urlParams}`, {
5333
7420
  headers: {
5334
7421
  "Authorization": `Bearer ${this.apiKey}`,
5335
- "X-Requested-With": userAgent
7422
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
5336
7423
  }
5337
7424
  }));
5338
7425
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
5339
7426
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
5340
7427
  try {
5341
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
7428
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
5342
7429
  }
5343
7430
  catch (error) {
5344
7431
  success = true;
@@ -5406,13 +7493,13 @@ class TransactionService {
5406
7493
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_summary/?${urlParams}`, {
5407
7494
  headers: {
5408
7495
  "Authorization": `Bearer ${this.apiKey}`,
5409
- "X-Requested-With": userAgent
7496
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
5410
7497
  }
5411
7498
  }));
5412
7499
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
5413
7500
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
5414
7501
  try {
5415
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
7502
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
5416
7503
  }
5417
7504
  catch (error) {
5418
7505
  success = true;
@@ -5496,13 +7583,13 @@ class TransactionService {
5496
7583
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/page/${page}/?${urlParams}`, {
5497
7584
  headers: {
5498
7585
  "Authorization": `Bearer ${this.apiKey}`,
5499
- "X-Requested-With": userAgent
7586
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
5500
7587
  }
5501
7588
  }));
5502
7589
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
5503
7590
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
5504
7591
  try {
5505
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
7592
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
5506
7593
  }
5507
7594
  catch (error) {
5508
7595
  success = true;
@@ -5517,7 +7604,7 @@ class TransactionService {
5517
7604
  else {
5518
7605
  data = await response.json();
5519
7606
  }
5520
- const dataClass = new TransactionsResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams, this.enableRetry);
7607
+ const dataClass = new TransactionsResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams, this.enableRetry, this.source);
5521
7608
  checkAndModifyResponse(dataClass);
5522
7609
  success = true;
5523
7610
  return {
@@ -5582,13 +7669,188 @@ class TransactionService {
5582
7669
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/bulk/transactions/${walletAddress}/${timeBucket}/?${urlParams}`, {
5583
7670
  headers: {
5584
7671
  "Authorization": `Bearer ${this.apiKey}`,
5585
- "X-Requested-With": userAgent
7672
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
7673
+ }
7674
+ }));
7675
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
7676
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
7677
+ try {
7678
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
7679
+ }
7680
+ catch (error) {
7681
+ success = true;
7682
+ return {
7683
+ data: null,
7684
+ error: true,
7685
+ error_code: response.status ?? 429,
7686
+ error_message: error.message
7687
+ };
7688
+ }
7689
+ }
7690
+ else {
7691
+ data = await response.json();
7692
+ }
7693
+ const dataClass = new TransactionsTimeBucketResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams, this.enableRetry, this.source);
7694
+ checkAndModifyResponse(dataClass);
7695
+ success = true;
7696
+ return {
7697
+ data: dataClass,
7698
+ error: data.error,
7699
+ error_code: data ? data.error_code : response.status,
7700
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
7701
+ };
7702
+ }
7703
+ catch (error) {
7704
+ success = true;
7705
+ return {
7706
+ data: null,
7707
+ error: true,
7708
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
7709
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
7710
+ };
7711
+ }
7712
+ }
7713
+ }
7714
+ /**
7715
+ *
7716
+ * Commonly used to fetch all transactions including their decoded log events in a block and further flag interesting wallets or transactions.
7717
+ *
7718
+ * @param {string} chainName - The chain name eg: `eth-mainnet`.
7719
+ * @param {string} blockHash - The requested block hash.
7720
+ * @param {number} page - The requested 0-indexed page number.
7721
+ * @param {GetTransactionsForBlockHashByPageQueryParamOpts} queryParamOpts
7722
+ * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
7723
+ * - `noLogs`: Omit log events.
7724
+ * - `withSafe`: Include safe details.
7725
+ *
7726
+ */
7727
+ async getTransactionsForBlockHashByPage(chainName, blockHash, page, queryParamOpts) {
7728
+ let success = false;
7729
+ let data;
7730
+ let response;
7731
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
7732
+ while (!success) {
7733
+ try {
7734
+ const urlParams = new URLSearchParams();
7735
+ if (!this.is_key_valid) {
7736
+ return {
7737
+ data: null,
7738
+ error: true,
7739
+ error_code: 401,
7740
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
7741
+ };
7742
+ }
7743
+ if (queryParamOpts?.quoteCurrency !== undefined) {
7744
+ urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
7745
+ }
7746
+ if (queryParamOpts?.noLogs !== undefined) {
7747
+ urlParams.append("no-logs", queryParamOpts?.noLogs.toString());
7748
+ }
7749
+ if (queryParamOpts?.withSafe !== undefined) {
7750
+ urlParams.append("with-safe", queryParamOpts?.withSafe.toString());
7751
+ }
7752
+ const url = `https://api.covalenthq.com/v1/${chainName}/block_hash/${blockHash}/transactions_v3/page/${page}/?${urlParams}`;
7753
+ let startTime;
7754
+ if (this.debug) {
7755
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
7756
+ }
7757
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/block_hash/${blockHash}/transactions_v3/page/${page}/?${urlParams}`, {
7758
+ headers: {
7759
+ "Authorization": `Bearer ${this.apiKey}`,
7760
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
7761
+ }
7762
+ }));
7763
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
7764
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
7765
+ try {
7766
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
7767
+ }
7768
+ catch (error) {
7769
+ success = true;
7770
+ return {
7771
+ data: null,
7772
+ error: true,
7773
+ error_code: response.status ?? 429,
7774
+ error_message: error.message
7775
+ };
7776
+ }
7777
+ }
7778
+ else {
7779
+ data = await response.json();
7780
+ }
7781
+ const dataClass = new TransactionsBlockPageResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams, this.enableRetry, this.source);
7782
+ checkAndModifyResponse(dataClass);
7783
+ success = true;
7784
+ return {
7785
+ data: dataClass,
7786
+ error: data.error,
7787
+ error_code: data ? data.error_code : response.status,
7788
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
7789
+ };
7790
+ }
7791
+ catch (error) {
7792
+ success = true;
7793
+ return {
7794
+ data: null,
7795
+ error: true,
7796
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
7797
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
7798
+ };
7799
+ }
7800
+ }
7801
+ }
7802
+ /**
7803
+ *
7804
+ * Commonly used to fetch all transactions including their decoded log events in a block and further flag interesting wallets or transactions.
7805
+ *
7806
+ * @param {string} chainName - The chain name eg: `eth-mainnet`.
7807
+ * @param {string} blockHash - The requested block hash.
7808
+ * @param {GetTransactionsForBlockHashQueryParamOpts} queryParamOpts
7809
+ * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
7810
+ * - `noLogs`: Omit log events.
7811
+ * - `withSafe`: Include safe details.
7812
+ *
7813
+ */
7814
+ async getTransactionsForBlockHash(chainName, blockHash, queryParamOpts) {
7815
+ let success = false;
7816
+ let data;
7817
+ let response;
7818
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
7819
+ while (!success) {
7820
+ try {
7821
+ const urlParams = new URLSearchParams();
7822
+ if (!this.is_key_valid) {
7823
+ return {
7824
+ data: null,
7825
+ error: true,
7826
+ error_code: 401,
7827
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
7828
+ };
7829
+ }
7830
+ if (queryParamOpts?.quoteCurrency !== undefined) {
7831
+ urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
7832
+ }
7833
+ if (queryParamOpts?.noLogs !== undefined) {
7834
+ urlParams.append("no-logs", queryParamOpts?.noLogs.toString());
7835
+ }
7836
+ if (queryParamOpts?.withSafe !== undefined) {
7837
+ urlParams.append("with-safe", queryParamOpts?.withSafe.toString());
7838
+ }
7839
+ const url = `https://api.covalenthq.com/v1/${chainName}/block_hash/${blockHash}/transactions_v3/?${urlParams}`;
7840
+ let startTime;
7841
+ if (this.debug) {
7842
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
7843
+ }
7844
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/block_hash/${blockHash}/transactions_v3/?${urlParams}`, {
7845
+ headers: {
7846
+ "Authorization": `Bearer ${this.apiKey}`,
7847
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
5586
7848
  }
5587
7849
  }));
5588
7850
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
5589
7851
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
5590
7852
  try {
5591
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
7853
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
5592
7854
  }
5593
7855
  catch (error) {
5594
7856
  success = true;
@@ -5603,7 +7865,7 @@ class TransactionService {
5603
7865
  else {
5604
7866
  data = await response.json();
5605
7867
  }
5606
- const dataClass = new TransactionsTimeBucketResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams, this.enableRetry);
7868
+ const dataClass = new TransactionsBlockResponse(data.data);
5607
7869
  checkAndModifyResponse(dataClass);
5608
7870
  success = true;
5609
7871
  return {
@@ -5868,23 +8130,55 @@ class UniswapLikeTokenWithSupply {
5868
8130
  this.contract_ticker_symbol = data.contract_ticker_symbol;
5869
8131
  this.contract_address = data.contract_address;
5870
8132
  this.logo_url = data.logo_url;
5871
- this.balance = data.balance && data.balance !== null ? BigInt(data.balance) : null;
5872
- this.quote = data.quote;
5873
- this.pretty_quote = data.pretty_quote;
8133
+ this.balance = data.balance && data.balance !== null ? BigInt(data.balance) : null;
8134
+ this.quote = data.quote;
8135
+ this.pretty_quote = data.pretty_quote;
8136
+ this.quote_rate = data.quote_rate;
8137
+ this.total_supply = data.total_supply && data.total_supply !== null ? BigInt(data.total_supply) : null;
8138
+ }
8139
+ }
8140
+ class NetworkExchangeTokensResponse {
8141
+ constructor(data) {
8142
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
8143
+ this.chain_id = data.chain_id;
8144
+ this.chain_name = data.chain_name;
8145
+ this.items = data.items && data.items !== null ? data.items.map((itemData) => new TokenV2Volume(itemData)) : null;
8146
+ this.pagination = data.pagination && data.pagination !== null ? new Pagination(data.pagination) : null;
8147
+ }
8148
+ }
8149
+ class TokenV2Volume {
8150
+ constructor(data) {
8151
+ this.chain_name = data.chain_name;
8152
+ this.chain_id = data.chain_id;
8153
+ this.dex_name = data.dex_name;
8154
+ this.contract_address = data.contract_address;
8155
+ this.contract_name = data.contract_name;
8156
+ this.total_liquidity = data.total_liquidity;
8157
+ this.total_volume_24h = data.total_volume_24h;
8158
+ this.logo_url = data.logo_url;
8159
+ this.contract_ticker_symbol = data.contract_ticker_symbol;
8160
+ this.contract_decimals = data.contract_decimals;
8161
+ this.swap_count_24h = data.swap_count_24h;
5874
8162
  this.quote_rate = data.quote_rate;
5875
- this.total_supply = data.total_supply && data.total_supply !== null ? BigInt(data.total_supply) : null;
8163
+ this.quote_rate_24h = data.quote_rate_24h;
8164
+ this.pretty_quote_rate = data.pretty_quote_rate;
8165
+ this.pretty_quote_rate_24h = data.pretty_quote_rate_24h;
8166
+ this.pretty_total_liquidity_quote = data.pretty_total_liquidity_quote;
8167
+ this.pretty_total_volume_24h_quote = data.pretty_total_volume_24h_quote;
8168
+ this.total_liquidity_quote = data.total_liquidity_quote;
8169
+ this.total_volume_24h_quote = data.total_volume_24h_quote;
5876
8170
  }
5877
8171
  }
5878
- class NetworkExchangeTokensResponse {
8172
+ class NetworkExchangeTokenViewResponse {
5879
8173
  constructor(data) {
5880
8174
  this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
5881
8175
  this.chain_id = data.chain_id;
5882
8176
  this.chain_name = data.chain_name;
5883
- this.items = data.items && data.items !== null ? data.items.map((itemData) => new TokenV2Volume(itemData)) : null;
8177
+ this.items = data.items && data.items !== null ? data.items.map((itemData) => new TokenV2VolumeWithChartData(itemData)) : null;
5884
8178
  this.pagination = data.pagination && data.pagination !== null ? new Pagination(data.pagination) : null;
5885
8179
  }
5886
8180
  }
5887
- class TokenV2Volume {
8181
+ class TokenV2VolumeWithChartData {
5888
8182
  constructor(data) {
5889
8183
  this.chain_name = data.chain_name;
5890
8184
  this.chain_id = data.chain_id;
@@ -5905,6 +8199,43 @@ class TokenV2Volume {
5905
8199
  this.pretty_total_volume_24h_quote = data.pretty_total_volume_24h_quote;
5906
8200
  this.total_liquidity_quote = data.total_liquidity_quote;
5907
8201
  this.total_volume_24h_quote = data.total_volume_24h_quote;
8202
+ this.transactions_24h = data.transactions_24h;
8203
+ this.volume_timeseries_7d = data.volume_timeseries_7d && data.volume_timeseries_7d !== null ? data.volume_timeseries_7d.map((itemData) => new VolumeTokenTimeseries(itemData)) : null;
8204
+ this.volume_timeseries_30d = data.volume_timeseries_30d && data.volume_timeseries_30d !== null ? data.volume_timeseries_30d.map((itemData) => new VolumeTokenTimeseries(itemData)) : null;
8205
+ this.liquidity_timeseries_7d = data.liquidity_timeseries_7d && data.liquidity_timeseries_7d !== null ? data.liquidity_timeseries_7d.map((itemData) => new LiquidityTokenTimeseries(itemData)) : null;
8206
+ this.liquidity_timeseries_30d = data.liquidity_timeseries_30d && data.liquidity_timeseries_30d !== null ? data.liquidity_timeseries_30d.map((itemData) => new LiquidityTokenTimeseries(itemData)) : null;
8207
+ this.price_timeseries_7d = data.price_timeseries_7d && data.price_timeseries_7d !== null ? data.price_timeseries_7d.map((itemData) => new PriceTokenTimeseries(itemData)) : null;
8208
+ this.price_timeseries_30d = data.price_timeseries_30d && data.price_timeseries_30d !== null ? data.price_timeseries_30d.map((itemData) => new PriceTokenTimeseries(itemData)) : null;
8209
+ }
8210
+ }
8211
+ class VolumeTokenTimeseries {
8212
+ constructor(data) {
8213
+ this.dex_name = data.dex_name;
8214
+ this.chain_id = data.chain_id;
8215
+ this.dt = data.dt;
8216
+ this.total_volume = data.total_volume;
8217
+ this.volume_quote = data.volume_quote;
8218
+ this.pretty_volume_quote = data.pretty_volume_quote;
8219
+ }
8220
+ }
8221
+ class LiquidityTokenTimeseries {
8222
+ constructor(data) {
8223
+ this.dex_name = data.dex_name;
8224
+ this.chain_id = data.chain_id;
8225
+ this.dt = data.dt;
8226
+ this.total_liquidity = data.total_liquidity;
8227
+ this.liquidity_quote = data.liquidity_quote;
8228
+ this.pretty_liquidity_quote = data.pretty_liquidity_quote;
8229
+ }
8230
+ }
8231
+ class PriceTokenTimeseries {
8232
+ constructor(data) {
8233
+ this.dex_name = data.dex_name;
8234
+ this.chain_id = data.chain_id;
8235
+ this.dt = data.dt;
8236
+ this.quote_currency = data.quote_currency;
8237
+ this.quote_rate = data.quote_rate;
8238
+ this.pretty_quote_rate = data.pretty_quote_rate;
5908
8239
  }
5909
8240
  }
5910
8241
  class SupportedDexesResponse {
@@ -6005,6 +8336,15 @@ class TransactionsForExchangeResponse {
6005
8336
  this.pagination = data.pagination && data.pagination !== null ? new Pagination(data.pagination) : null;
6006
8337
  }
6007
8338
  }
8339
+ class NetworkTransactionsResponse {
8340
+ constructor(data) {
8341
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
8342
+ this.chain_id = data.chain_id;
8343
+ this.chain_name = data.chain_name;
8344
+ this.items = data.items && data.items !== null ? data.items.map((itemData) => new ExchangeTransaction(itemData)) : null;
8345
+ this.pagination = data.pagination && data.pagination !== null ? new Pagination(data.pagination) : null;
8346
+ }
8347
+ }
6008
8348
  class EcosystemChartDataResponse {
6009
8349
  constructor(data) {
6010
8350
  this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
@@ -6074,12 +8414,13 @@ class HealthData {
6074
8414
  *
6075
8415
  */
6076
8416
  class XykService {
6077
- constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true) {
8417
+ constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true, source) {
6078
8418
  this.apiKey = apiKey;
6079
8419
  this.debug = debug;
6080
8420
  this.threadCount = threadCount;
6081
8421
  this.is_key_valid = is_key_valid;
6082
8422
  this.enableRetry = enableRetry;
8423
+ this.source = source;
6083
8424
  this.LIMIT = pLimit$1(this.threadCount);
6084
8425
  }
6085
8426
  /**
@@ -6088,9 +8429,12 @@ class XykService {
6088
8429
  *
6089
8430
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
6090
8431
  * @param {string} dexName - The DEX name eg: `uniswap_v2`.
8432
+ * @param {GetPoolsQueryParamOpts} queryParamOpts
8433
+ * - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
8434
+ * - `pageNumber`: 0-indexed page number to begin pagination.
6091
8435
  *
6092
8436
  */
6093
- async getPools(chainName, dexName) {
8437
+ async getPools(chainName, dexName, queryParamOpts) {
6094
8438
  let success = false;
6095
8439
  let data;
6096
8440
  let response;
@@ -6098,6 +8442,12 @@ class XykService {
6098
8442
  while (!success) {
6099
8443
  try {
6100
8444
  const urlParams = new URLSearchParams();
8445
+ if (queryParamOpts?.pageSize !== undefined) {
8446
+ urlParams.append("page-size", queryParamOpts?.pageSize.toString());
8447
+ }
8448
+ if (queryParamOpts?.pageNumber !== undefined) {
8449
+ urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
8450
+ }
6101
8451
  const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/?${urlParams}`;
6102
8452
  if (!this.is_key_valid) {
6103
8453
  return {
@@ -6114,13 +8464,13 @@ class XykService {
6114
8464
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/?${urlParams}`, {
6115
8465
  headers: {
6116
8466
  "Authorization": `Bearer ${this.apiKey}`,
6117
- "X-Requested-With": userAgent
8467
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
6118
8468
  }
6119
8469
  }));
6120
8470
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
6121
8471
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
6122
8472
  try {
6123
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
8473
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
6124
8474
  }
6125
8475
  catch (error) {
6126
8476
  success = true;
@@ -6188,13 +8538,13 @@ class XykService {
6188
8538
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/address/${poolAddress}/dex_name/?${urlParams}`, {
6189
8539
  headers: {
6190
8540
  "Authorization": `Bearer ${this.apiKey}`,
6191
- "X-Requested-With": userAgent
8541
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
6192
8542
  }
6193
8543
  }));
6194
8544
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
6195
8545
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
6196
8546
  try {
6197
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
8547
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
6198
8548
  }
6199
8549
  catch (error) {
6200
8550
  success = true;
@@ -6263,13 +8613,13 @@ class XykService {
6263
8613
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/address/${poolAddress}/?${urlParams}`, {
6264
8614
  headers: {
6265
8615
  "Authorization": `Bearer ${this.apiKey}`,
6266
- "X-Requested-With": userAgent
8616
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
6267
8617
  }
6268
8618
  }));
6269
8619
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
6270
8620
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
6271
8621
  try {
6272
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
8622
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
6273
8623
  }
6274
8624
  catch (error) {
6275
8625
  success = true;
@@ -6314,6 +8664,8 @@ class XykService {
6314
8664
  * @param {number} page - The requested 0-indexed page number.
6315
8665
  * @param {GetPoolsForTokenAddressQueryParamOpts} queryParamOpts
6316
8666
  * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
8667
+ * - `dexName`: The DEX name eg: `uniswap_v2`.
8668
+ * - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
6317
8669
  *
6318
8670
  */
6319
8671
  async getPoolsForTokenAddress(chainName, tokenAddress, page, queryParamOpts) {
@@ -6338,6 +8690,9 @@ class XykService {
6338
8690
  if (queryParamOpts?.dexName !== undefined) {
6339
8691
  urlParams.append("dex-name", queryParamOpts?.dexName.toString());
6340
8692
  }
8693
+ if (queryParamOpts?.pageSize !== undefined) {
8694
+ urlParams.append("page-size", queryParamOpts?.pageSize.toString());
8695
+ }
6341
8696
  const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/tokens/address/${tokenAddress}/pools/page/${page}/?${urlParams}`;
6342
8697
  let startTime;
6343
8698
  if (this.debug) {
@@ -6346,13 +8701,13 @@ class XykService {
6346
8701
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/tokens/address/${tokenAddress}/pools/page/${page}/?${urlParams}`, {
6347
8702
  headers: {
6348
8703
  "Authorization": `Bearer ${this.apiKey}`,
6349
- "X-Requested-With": userAgent
8704
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
6350
8705
  }
6351
8706
  }));
6352
8707
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
6353
8708
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
6354
8709
  try {
6355
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
8710
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
6356
8711
  }
6357
8712
  catch (error) {
6358
8713
  success = true;
@@ -6421,13 +8776,13 @@ class XykService {
6421
8776
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/address/${accountAddress}/balances/?${urlParams}`, {
6422
8777
  headers: {
6423
8778
  "Authorization": `Bearer ${this.apiKey}`,
6424
- "X-Requested-With": userAgent
8779
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
6425
8780
  }
6426
8781
  }));
6427
8782
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
6428
8783
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
6429
8784
  try {
6430
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
8785
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
6431
8786
  }
6432
8787
  catch (error) {
6433
8788
  success = true;
@@ -6473,6 +8828,8 @@ class XykService {
6473
8828
  * @param {GetPoolsForWalletAddressQueryParamOpts} queryParamOpts
6474
8829
  * - `tokenAddress`: The token contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
6475
8830
  * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
8831
+ * - `dexName`: The DEX name eg: `uniswap_v2`.
8832
+ * - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
6476
8833
  *
6477
8834
  */
6478
8835
  async getPoolsForWalletAddress(chainName, walletAddress, page, queryParamOpts) {
@@ -6500,6 +8857,9 @@ class XykService {
6500
8857
  if (queryParamOpts?.dexName !== undefined) {
6501
8858
  urlParams.append("dex-name", queryParamOpts?.dexName.toString());
6502
8859
  }
8860
+ if (queryParamOpts?.pageSize !== undefined) {
8861
+ urlParams.append("page-size", queryParamOpts?.pageSize.toString());
8862
+ }
6503
8863
  const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/address/${walletAddress}/pools/page/${page}/?${urlParams}`;
6504
8864
  let startTime;
6505
8865
  if (this.debug) {
@@ -6508,13 +8868,13 @@ class XykService {
6508
8868
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/address/${walletAddress}/pools/page/${page}/?${urlParams}`, {
6509
8869
  headers: {
6510
8870
  "Authorization": `Bearer ${this.apiKey}`,
6511
- "X-Requested-With": userAgent
8871
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
6512
8872
  }
6513
8873
  }));
6514
8874
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
6515
8875
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
6516
8876
  try {
6517
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
8877
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
6518
8878
  }
6519
8879
  catch (error) {
6520
8880
  success = true;
@@ -6556,9 +8916,12 @@ class XykService {
6556
8916
  *
6557
8917
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
6558
8918
  * @param {string} dexName - The DEX name eg: `uniswap_v2`.
8919
+ * @param {GetNetworkExchangeTokensQueryParamOpts} queryParamOpts
8920
+ * - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
8921
+ * - `pageNumber`: 0-indexed page number to begin pagination.
6559
8922
  *
6560
8923
  */
6561
- async getNetworkExchangeTokens(chainName, dexName) {
8924
+ async getNetworkExchangeTokens(chainName, dexName, queryParamOpts) {
6562
8925
  let success = false;
6563
8926
  let data;
6564
8927
  let response;
@@ -6566,6 +8929,12 @@ class XykService {
6566
8929
  while (!success) {
6567
8930
  try {
6568
8931
  const urlParams = new URLSearchParams();
8932
+ if (queryParamOpts?.pageSize !== undefined) {
8933
+ urlParams.append("page-size", queryParamOpts?.pageSize.toString());
8934
+ }
8935
+ if (queryParamOpts?.pageNumber !== undefined) {
8936
+ urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
8937
+ }
6569
8938
  if (!this.is_key_valid) {
6570
8939
  return {
6571
8940
  data: null,
@@ -6582,13 +8951,13 @@ class XykService {
6582
8951
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/?${urlParams}`, {
6583
8952
  headers: {
6584
8953
  "Authorization": `Bearer ${this.apiKey}`,
6585
- "X-Requested-With": userAgent
8954
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
6586
8955
  }
6587
8956
  }));
6588
8957
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
6589
8958
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
6590
8959
  try {
6591
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
8960
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
6592
8961
  }
6593
8962
  catch (error) {
6594
8963
  success = true;
@@ -6624,6 +8993,86 @@ class XykService {
6624
8993
  }
6625
8994
  }
6626
8995
  }
8996
+ /**
8997
+ *
8998
+ * Commonly used to get a detailed view for a single liquidity pool token. Includes time series data.
8999
+ *
9000
+ * @param {string} chainName - The chain name eg: `eth-mainnet`.
9001
+ * @param {string} dexName - The DEX name eg: `uniswap_v2`.
9002
+ * @param {string} tokenAddress - The token contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
9003
+ * @param {GetLpTokenViewQueryParamOpts} queryParamOpts
9004
+ * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
9005
+ *
9006
+ */
9007
+ async getLpTokenView(chainName, dexName, tokenAddress, queryParamOpts) {
9008
+ let success = false;
9009
+ let data;
9010
+ let response;
9011
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
9012
+ while (!success) {
9013
+ try {
9014
+ const urlParams = new URLSearchParams();
9015
+ if (!this.is_key_valid) {
9016
+ return {
9017
+ data: null,
9018
+ error: true,
9019
+ error_code: 401,
9020
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
9021
+ };
9022
+ }
9023
+ if (queryParamOpts?.quoteCurrency !== undefined) {
9024
+ urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
9025
+ }
9026
+ const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/address/${tokenAddress}/view/?${urlParams}`;
9027
+ let startTime;
9028
+ if (this.debug) {
9029
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
9030
+ }
9031
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/address/${tokenAddress}/view/?${urlParams}`, {
9032
+ headers: {
9033
+ "Authorization": `Bearer ${this.apiKey}`,
9034
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
9035
+ }
9036
+ }));
9037
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
9038
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
9039
+ try {
9040
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
9041
+ }
9042
+ catch (error) {
9043
+ success = true;
9044
+ return {
9045
+ data: null,
9046
+ error: true,
9047
+ error_code: response.status ?? 429,
9048
+ error_message: error.message
9049
+ };
9050
+ }
9051
+ }
9052
+ else {
9053
+ data = await response.json();
9054
+ }
9055
+ const dataClass = new NetworkExchangeTokenViewResponse(data.data);
9056
+ checkAndModifyResponse(dataClass);
9057
+ success = true;
9058
+ return {
9059
+ data: dataClass,
9060
+ error: data.error,
9061
+ error_code: data ? data.error_code : response.status,
9062
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
9063
+ };
9064
+ }
9065
+ catch (error) {
9066
+ success = true;
9067
+ return {
9068
+ data: null,
9069
+ error: true,
9070
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
9071
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
9072
+ };
9073
+ }
9074
+ }
9075
+ }
6627
9076
  /**
6628
9077
  *
6629
9078
  * Commonly used to get all the supported DEXs available for the xy=k endpoints, along with the swap fees and factory addresses.
@@ -6654,13 +9103,13 @@ class XykService {
6654
9103
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/xy=k/supported_dexes/?${urlParams}`, {
6655
9104
  headers: {
6656
9105
  "Authorization": `Bearer ${this.apiKey}`,
6657
- "X-Requested-With": userAgent
9106
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
6658
9107
  }
6659
9108
  }));
6660
9109
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
6661
9110
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
6662
9111
  try {
6663
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
9112
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
6664
9113
  }
6665
9114
  catch (error) {
6666
9115
  success = true;
@@ -6703,9 +9152,12 @@ class XykService {
6703
9152
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
6704
9153
  * @param {string} dexName - The DEX name eg: `uniswap_v2`.
6705
9154
  * @param {string} tokenAddress - The token contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
9155
+ * @param {GetSingleNetworkExchangeTokenQueryParamOpts} queryParamOpts
9156
+ * - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
9157
+ * - `pageNumber`: 0-indexed page number to begin pagination.
6706
9158
  *
6707
9159
  */
6708
- async getSingleNetworkExchangeToken(chainName, dexName, tokenAddress) {
9160
+ async getSingleNetworkExchangeToken(chainName, dexName, tokenAddress, queryParamOpts) {
6709
9161
  let success = false;
6710
9162
  let data;
6711
9163
  let response;
@@ -6713,6 +9165,12 @@ class XykService {
6713
9165
  while (!success) {
6714
9166
  try {
6715
9167
  const urlParams = new URLSearchParams();
9168
+ if (queryParamOpts?.pageSize !== undefined) {
9169
+ urlParams.append("page-size", queryParamOpts?.pageSize.toString());
9170
+ }
9171
+ if (queryParamOpts?.pageNumber !== undefined) {
9172
+ urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
9173
+ }
6716
9174
  if (!this.is_key_valid) {
6717
9175
  return {
6718
9176
  data: null,
@@ -6729,13 +9187,13 @@ class XykService {
6729
9187
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/address/${tokenAddress}/?${urlParams}`, {
6730
9188
  headers: {
6731
9189
  "Authorization": `Bearer ${this.apiKey}`,
6732
- "X-Requested-With": userAgent
9190
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
6733
9191
  }
6734
9192
  }));
6735
9193
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
6736
9194
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
6737
9195
  try {
6738
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
9196
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
6739
9197
  }
6740
9198
  catch (error) {
6741
9199
  success = true;
@@ -6804,13 +9262,13 @@ class XykService {
6804
9262
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/address/${accountAddress}/transactions/?${urlParams}`, {
6805
9263
  headers: {
6806
9264
  "Authorization": `Bearer ${this.apiKey}`,
6807
- "X-Requested-With": userAgent
9265
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
6808
9266
  }
6809
9267
  }));
6810
9268
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
6811
9269
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
6812
9270
  try {
6813
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
9271
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
6814
9272
  }
6815
9273
  catch (error) {
6816
9274
  success = true;
@@ -6853,9 +9311,12 @@ class XykService {
6853
9311
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
6854
9312
  * @param {string} dexName - The DEX name eg: `uniswap_v2`.
6855
9313
  * @param {string} tokenAddress - The token contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
9314
+ * @param {GetTransactionsForTokenAddressQueryParamOpts} queryParamOpts
9315
+ * - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
9316
+ * - `pageNumber`: 0-indexed page number to begin pagination.
6856
9317
  *
6857
9318
  */
6858
- async getTransactionsForTokenAddress(chainName, dexName, tokenAddress) {
9319
+ async getTransactionsForTokenAddress(chainName, dexName, tokenAddress, queryParamOpts) {
6859
9320
  let success = false;
6860
9321
  let data;
6861
9322
  let response;
@@ -6871,6 +9332,12 @@ class XykService {
6871
9332
  error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
6872
9333
  };
6873
9334
  }
9335
+ if (queryParamOpts?.pageSize !== undefined) {
9336
+ urlParams.append("page-size", queryParamOpts?.pageSize.toString());
9337
+ }
9338
+ if (queryParamOpts?.pageNumber !== undefined) {
9339
+ urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
9340
+ }
6874
9341
  const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/address/${tokenAddress}/transactions/?${urlParams}`;
6875
9342
  let startTime;
6876
9343
  if (this.debug) {
@@ -6879,13 +9346,13 @@ class XykService {
6879
9346
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/address/${tokenAddress}/transactions/?${urlParams}`, {
6880
9347
  headers: {
6881
9348
  "Authorization": `Bearer ${this.apiKey}`,
6882
- "X-Requested-With": userAgent
9349
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
6883
9350
  }
6884
9351
  }));
6885
9352
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
6886
9353
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
6887
9354
  try {
6888
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
9355
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
6889
9356
  }
6890
9357
  catch (error) {
6891
9358
  success = true;
@@ -6928,9 +9395,12 @@ class XykService {
6928
9395
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
6929
9396
  * @param {string} dexName - The DEX name eg: `uniswap_v2`.
6930
9397
  * @param {string} poolAddress - The pool contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
9398
+ * @param {GetTransactionsForExchangeQueryParamOpts} queryParamOpts
9399
+ * - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
9400
+ * - `pageNumber`: 0-indexed page number to begin pagination.
6931
9401
  *
6932
9402
  */
6933
- async getTransactionsForExchange(chainName, dexName, poolAddress) {
9403
+ async getTransactionsForExchange(chainName, dexName, poolAddress, queryParamOpts) {
6934
9404
  let success = false;
6935
9405
  let data;
6936
9406
  let response;
@@ -6946,6 +9416,12 @@ class XykService {
6946
9416
  error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
6947
9417
  };
6948
9418
  }
9419
+ if (queryParamOpts?.pageSize !== undefined) {
9420
+ urlParams.append("page-size", queryParamOpts?.pageSize.toString());
9421
+ }
9422
+ if (queryParamOpts?.pageNumber !== undefined) {
9423
+ urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
9424
+ }
6949
9425
  const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/address/${poolAddress}/transactions/?${urlParams}`;
6950
9426
  let startTime;
6951
9427
  if (this.debug) {
@@ -6954,13 +9430,13 @@ class XykService {
6954
9430
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/address/${poolAddress}/transactions/?${urlParams}`, {
6955
9431
  headers: {
6956
9432
  "Authorization": `Bearer ${this.apiKey}`,
6957
- "X-Requested-With": userAgent
9433
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
6958
9434
  }
6959
9435
  }));
6960
9436
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
6961
9437
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
6962
9438
  try {
6963
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
9439
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
6964
9440
  }
6965
9441
  catch (error) {
6966
9442
  success = true;
@@ -6996,6 +9472,93 @@ class XykService {
6996
9472
  }
6997
9473
  }
6998
9474
  }
9475
+ /**
9476
+ *
9477
+ * Commonly used to get all the the transactions for a given DEX. Useful for building DEX activity views.
9478
+ *
9479
+ * @param {string} chainName - The chain name eg: `eth-mainnet`.
9480
+ * @param {string} dexName - The DEX name eg: `uniswap_v2`.
9481
+ * @param {GetTransactionsForDexQueryParamOpts} queryParamOpts
9482
+ * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
9483
+ * - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
9484
+ * - `pageNumber`: 0-indexed page number to begin pagination.
9485
+ *
9486
+ */
9487
+ async getTransactionsForDex(chainName, dexName, queryParamOpts) {
9488
+ let success = false;
9489
+ let data;
9490
+ let response;
9491
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
9492
+ while (!success) {
9493
+ try {
9494
+ const urlParams = new URLSearchParams();
9495
+ if (!this.is_key_valid) {
9496
+ return {
9497
+ data: null,
9498
+ error: true,
9499
+ error_code: 401,
9500
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
9501
+ };
9502
+ }
9503
+ if (queryParamOpts?.quoteCurrency !== undefined) {
9504
+ urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
9505
+ }
9506
+ if (queryParamOpts?.pageSize !== undefined) {
9507
+ urlParams.append("page-size", queryParamOpts?.pageSize.toString());
9508
+ }
9509
+ if (queryParamOpts?.pageNumber !== undefined) {
9510
+ urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
9511
+ }
9512
+ const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/transactions/?${urlParams}`;
9513
+ let startTime;
9514
+ if (this.debug) {
9515
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
9516
+ }
9517
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/transactions/?${urlParams}`, {
9518
+ headers: {
9519
+ "Authorization": `Bearer ${this.apiKey}`,
9520
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
9521
+ }
9522
+ }));
9523
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
9524
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
9525
+ try {
9526
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
9527
+ }
9528
+ catch (error) {
9529
+ success = true;
9530
+ return {
9531
+ data: null,
9532
+ error: true,
9533
+ error_code: response.status ?? 429,
9534
+ error_message: error.message
9535
+ };
9536
+ }
9537
+ }
9538
+ else {
9539
+ data = await response.json();
9540
+ }
9541
+ const dataClass = new NetworkTransactionsResponse(data.data);
9542
+ checkAndModifyResponse(dataClass);
9543
+ success = true;
9544
+ return {
9545
+ data: dataClass,
9546
+ error: data.error,
9547
+ error_code: data ? data.error_code : response.status,
9548
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
9549
+ };
9550
+ }
9551
+ catch (error) {
9552
+ success = true;
9553
+ return {
9554
+ data: null,
9555
+ error: true,
9556
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
9557
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
9558
+ };
9559
+ }
9560
+ }
9561
+ }
6999
9562
  /**
7000
9563
  *
7001
9564
  * Commonly used to get a 7d and 30d time-series chart of DEX activity. Includes volume and swap count.
@@ -7028,13 +9591,13 @@ class XykService {
7028
9591
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/ecosystem/?${urlParams}`, {
7029
9592
  headers: {
7030
9593
  "Authorization": `Bearer ${this.apiKey}`,
7031
- "X-Requested-With": userAgent
9594
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
7032
9595
  }
7033
9596
  }));
7034
9597
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
7035
9598
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
7036
9599
  try {
7037
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
9600
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
7038
9601
  }
7039
9602
  catch (error) {
7040
9603
  success = true;
@@ -7102,13 +9665,13 @@ class XykService {
7102
9665
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/health/?${urlParams}`, {
7103
9666
  headers: {
7104
9667
  "Authorization": `Bearer ${this.apiKey}`,
7105
- "X-Requested-With": userAgent
9668
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
7106
9669
  }
7107
9670
  }));
7108
9671
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
7109
9672
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
7110
9673
  try {
7111
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
9674
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
7112
9675
  }
7113
9676
  catch (error) {
7114
9677
  success = true;
@@ -7146,22 +9709,22 @@ class XykService {
7146
9709
  }
7147
9710
  }
7148
9711
 
7149
- const userAgent = "com.covalenthq.sdk.typescript/0.7.6";
9712
+ const userAgent = "com.covalenthq.sdk.typescript/0.8.1";
7150
9713
  /**
7151
9714
  * CovalentClient Class
7152
9715
  */
7153
9716
  class CovalentClient {
7154
- constructor(apiKey, settings) {
9717
+ constructor(apiKey, settings, source) {
7155
9718
  const { debug = false, threadCount = 3, enableRetry = true } = settings || {};
7156
9719
  const validator = new ApiKeyValidator(apiKey);
7157
9720
  this._is_key_valid = validator.isValidApiKey();
7158
- this.SecurityService = new SecurityService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
7159
- this.BalanceService = new BalanceService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
7160
- this.BaseService = new BaseService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
7161
- this.NftService = new NftService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
7162
- this.PricingService = new PricingService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
7163
- this.TransactionService = new TransactionService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
7164
- this.XykService = new XykService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
9721
+ this.SecurityService = new SecurityService(apiKey, debug, threadCount, this._is_key_valid, enableRetry, source);
9722
+ this.BalanceService = new BalanceService(apiKey, debug, threadCount, this._is_key_valid, enableRetry, source);
9723
+ this.BaseService = new BaseService(apiKey, debug, threadCount, this._is_key_valid, enableRetry, source);
9724
+ this.NftService = new NftService(apiKey, debug, threadCount, this._is_key_valid, enableRetry, source);
9725
+ this.PricingService = new PricingService(apiKey, debug, threadCount, this._is_key_valid, enableRetry, source);
9726
+ this.TransactionService = new TransactionService(apiKey, debug, threadCount, this._is_key_valid, enableRetry, source);
9727
+ this.XykService = new XykService(apiKey, debug, threadCount, this._is_key_valid, enableRetry, source);
7165
9728
  }
7166
9729
  }
7167
9730
  /**
@@ -7171,17 +9734,17 @@ class CovalentClient {
7171
9734
  * CovalentClient Class
7172
9735
  */
7173
9736
  class Client {
7174
- constructor(apiKey, settings) {
9737
+ constructor(apiKey, settings, source) {
7175
9738
  const { debug = false, threadCount = 3, enableRetry = true } = settings || {};
7176
9739
  const validator = new ApiKeyValidator(apiKey);
7177
9740
  this._is_key_valid = validator.isValidApiKey();
7178
- this.SecurityService = new SecurityService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
7179
- this.BalanceService = new BalanceService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
7180
- this.BaseService = new BaseService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
7181
- this.NftService = new NftService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
7182
- this.PricingService = new PricingService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
7183
- this.TransactionService = new TransactionService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
7184
- this.XykService = new XykService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
9741
+ this.SecurityService = new SecurityService(apiKey, debug, threadCount, this._is_key_valid, enableRetry, source);
9742
+ this.BalanceService = new BalanceService(apiKey, debug, threadCount, this._is_key_valid, enableRetry, source);
9743
+ this.BaseService = new BaseService(apiKey, debug, threadCount, this._is_key_valid, enableRetry, source);
9744
+ this.NftService = new NftService(apiKey, debug, threadCount, this._is_key_valid, enableRetry, source);
9745
+ this.PricingService = new PricingService(apiKey, debug, threadCount, this._is_key_valid, enableRetry, source);
9746
+ this.TransactionService = new TransactionService(apiKey, debug, threadCount, this._is_key_valid, enableRetry, source);
9747
+ this.XykService = new XykService(apiKey, debug, threadCount, this._is_key_valid, enableRetry, source);
7185
9748
  }
7186
9749
  }
7187
9750