@short.io/client-node 1.0.3 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/index.ts CHANGED
@@ -1,774 +1,3 @@
1
- import { ErrorResBody, StatusResBody, SuccessResBody } from "./types/common.js";
2
- import { Domain, DomainCreateOptions } from "./types/domain.js";
3
- import {
4
- DeleteLinkRes,
5
- GetLinkQRCodeOptions,
6
- Link,
7
- LinkBulkCreateOptions,
8
- LinkCountry,
9
- LinkCountryCreateOptions,
10
- LinkCreateOptions,
11
- LinkListOptions,
12
- LinkOpenGraphData,
13
- LinkRegion,
14
- LinkRegionCreateOptions,
15
- LinkRegionDeleteOptions,
16
- LinksAndCount,
17
- LinkUpdateOptions,
18
- LinkWithUser,
19
- UpdateLinkErrorRes,
20
- } from "./types/link.js";
21
- import {
22
- Column,
23
- DomainStatistics,
24
- FilterOptions,
25
- GetLastClicksOptions,
26
- GetStatisticsOptions,
27
- IncludeExcludeOptions,
28
- LastClicksRes,
29
- LinkClicks,
30
- LinkIds,
31
- LinkStatistics,
32
- PathClicks,
33
- PathDate,
34
- StartEndDate,
35
- TopByColumnOptions,
36
- TopByIntervalOptions,
37
- TopByIntervalRes,
38
- TopColumnRes,
39
- } from "./types/statistics.js";
40
-
41
- export class Shortio {
42
- private readonly baseApiUrl = "https://api.short.io";
43
- private readonly baseStatisticsUrl = "https://api-v2.short.cm/statistics";
44
-
45
- constructor(private readonly apiKey: string) {}
46
-
47
- public readonly link = {
48
- /**
49
- * Fetch links for a given domain id.
50
- * By default it returns 150 links, this behavior can be changed by passing limit option.
51
- * API reference: https://developers.short.io/reference/apilinksget
52
- * @param domainId Domain id
53
- * @param options Options for the request
54
- * @returns Links, total link count and the next page token for pagination
55
- */
56
- list: async (domainId: Domain["id"], options?: LinkListOptions): Promise<LinksAndCount | ErrorResBody> => {
57
- let queryString = `domain_id=${domainId}`;
58
- if (options) {
59
- for (const param in options) {
60
- queryString += `&${param}=${options[param as keyof LinkListOptions]}`;
61
- }
62
- }
63
- const linksRes = await fetch(`${this.baseApiUrl}/api/links?${queryString}`, {
64
- method: "GET",
65
- headers: {
66
- "Content-Type": "application/json",
67
- Authorization: this.apiKey,
68
- },
69
- });
70
- const linksData = await linksRes.json();
71
- return linksData;
72
- },
73
-
74
- /**
75
- * Fetch link info by path.
76
- * API reference: https://developers.short.io/reference/linksexpandbydomainandpathget
77
- * @param hostname Domain hostname
78
- * @param path Path of the link
79
- * @returns Link details
80
- */
81
- getByPath: async (hostname: Domain["hostname"], path: Link["path"]): Promise<Link | ErrorResBody> => {
82
- const queryString = `domain=${hostname}&path=${path}`;
83
- const linkInfoRes = await fetch(`${this.baseApiUrl}/links/expand?${queryString}`, {
84
- method: "GET",
85
- headers: {
86
- "Content-Type": "application/json",
87
- Authorization: this.apiKey,
88
- },
89
- });
90
- const linkInfo = await linkInfoRes.json();
91
- return linkInfo;
92
- },
93
-
94
- /**
95
- * Fetch link info by original URL.
96
- * API reference: https://developers.short.io/reference/linksbyoriginalurlbydomainandoriginalurlget
97
- * @param hostname Domain hostname
98
- * @param originalURL Original URL of the link
99
- * @returns Link details
100
- */
101
- getByOriginalURL: async (
102
- hostname: Domain["hostname"],
103
- originalURL: Link["originalURL"],
104
- ): Promise<Link | ErrorResBody> => {
105
- const queryString = `domain=${hostname}&originalURL=${originalURL}`;
106
- const linkInfoRes = await fetch(`${this.baseApiUrl}/links/by-original-url?${queryString}`, {
107
- method: "GET",
108
- headers: {
109
- "Content-Type": "application/json",
110
- Authorization: this.apiKey,
111
- },
112
- });
113
- const linkInfo = await linkInfoRes.json();
114
- return linkInfo;
115
- },
116
-
117
- /**
118
- * Shorten a URL and create a new short link. If parameter "path" in the options is omitted, it
119
- generates path by algorithm, chosen in domain settings.
120
- * API reference: https://developers.short.io/reference/linkspost
121
- * @param hostname Domain hostname
122
- * @param originalURL Original URL of the link
123
- * @param options Options for the request
124
- */
125
- create: async (
126
- hostname: Domain["hostname"],
127
- originalURL: Link["originalURL"],
128
- options?: LinkCreateOptions,
129
- ): Promise<Link | ErrorResBody> => {
130
- const linkRes = await fetch(`${this.baseApiUrl}/links`, {
131
- method: "POST",
132
- headers: {
133
- "Content-Type": "application/json",
134
- Authorization: this.apiKey,
135
- },
136
- body: JSON.stringify({
137
- domain: hostname,
138
- originalURL,
139
- ...options,
140
- }),
141
- });
142
- const link = await linkRes.json();
143
- return link;
144
- },
145
-
146
- /**
147
- * Shorten a URL with public key and create a new short link. If parameter "path" in the options is omitted, it generates path by algorithm, chosen in domain settings.
148
- * API reference: https://developers.short.io/reference/linkspostpublic
149
- * @param hostname Domain hostname
150
- * @param originalURL Original URL of the link
151
- * @param publicAPIKey Public API key
152
- * @param options Options for the request
153
- * @returns Shortened link
154
- */
155
- createPublic: async (
156
- hostname: Domain["hostname"],
157
- originalURL: Link["originalURL"],
158
- publicAPIKey: string,
159
- options?: LinkCreateOptions,
160
- ): Promise<Link | (SuccessResBody & ErrorResBody)> => {
161
- const linkRes = await fetch(`${this.baseApiUrl}/links/public`, {
162
- method: "POST",
163
- headers: {
164
- "Content-Type": "application/json",
165
- Authorization: publicAPIKey,
166
- },
167
- body: JSON.stringify({
168
- domain: hostname,
169
- originalURL,
170
- ...options,
171
- }),
172
- });
173
- const link = await linkRes.json();
174
- return link;
175
- },
176
-
177
- /**
178
- * Shorten links in bulk. Method accepts up to 1000 links in one API call.
179
- * API reference: https://developers.short.io/reference/linksbulkpost
180
- * @param hostname Domain hostname
181
- * @param links Links to be shortened
182
- * @param allowDuplicates Allow duplicate links
183
- * @returns Shortened links
184
- */
185
- bulkCreate: async (
186
- hostname: Domain["hostname"],
187
- links: LinkBulkCreateOptions[],
188
- allowDuplicates = false,
189
- ): Promise<(Link & SuccessResBody)[] | (SuccessResBody & ErrorResBody & StatusResBody)> => {
190
- const linkRes = await fetch(`${this.baseApiUrl}/links/bulk`, {
191
- method: "POST",
192
- headers: {
193
- "Content-Type": "application/json",
194
- Authorization: this.apiKey,
195
- },
196
- body: JSON.stringify({
197
- domain: hostname,
198
- links,
199
- allowDuplicates,
200
- }),
201
- });
202
- const link = await linkRes.json();
203
- return link;
204
- },
205
-
206
- /**
207
- * Archive link by its id string.
208
- * API reference: https://developers.short.io/reference/archivelink
209
- * @param linkIdString Link id string
210
- */
211
- archive: async (linkIdString: Link["idString"]): Promise<SuccessResBody | ErrorResBody> => {
212
- const res = await fetch(`${this.baseApiUrl}/links/archive`, {
213
- method: "POST",
214
- headers: {
215
- "Content-Type": "application/json",
216
- Authorization: this.apiKey,
217
- },
218
- body: JSON.stringify({
219
- link_id: linkIdString,
220
- }),
221
- });
222
- const linkArchiveRes = await res.json();
223
- return linkArchiveRes;
224
- },
225
-
226
- /**
227
- * Update existing link.
228
- * API reference: https://developers.short.io/reference/linksbylinkidpost
229
- * @param linkIdString Link id string
230
- * @param options Options for the request
231
- * @returns Updated link with a user details
232
- */
233
- update: async (
234
- linkIdString: Link["idString"],
235
- options: LinkUpdateOptions,
236
- ): Promise<LinkWithUser | UpdateLinkErrorRes> => {
237
- const res = await fetch(`${this.baseApiUrl}/links/${linkIdString}`, {
238
- method: "POST",
239
- headers: {
240
- "Content-Type": "application/json",
241
- Authorization: this.apiKey,
242
- },
243
- body: JSON.stringify(options),
244
- });
245
- const linkUpdateRes = await res.json();
246
- return linkUpdateRes;
247
- },
248
-
249
- /**
250
- * Delete link by its id string.
251
- * API reference: https://developers.short.io/reference/linksbylinkiddelete
252
- * @param linkIdString Link id string
253
- * @returns Deleted link id string
254
- */
255
- delete: async (linkIdString: Link["idString"]): Promise<DeleteLinkRes | ErrorResBody> => {
256
- const res = await fetch(`${this.baseApiUrl}/links/${linkIdString}`, {
257
- method: "DELETE",
258
- headers: {
259
- "Content-Type": "application/json",
260
- Authorization: this.apiKey,
261
- },
262
- });
263
- const linkDeleteRes = await res.json();
264
- return linkDeleteRes;
265
- },
266
-
267
- /**
268
- * Generate QR code for a link.
269
- * API reference: https://developers.short.io/reference/qrcodebylinkidpost
270
- * @param linkIdString Link id string
271
- * @param options Options for the request
272
- * @returns QR code image
273
- */
274
- generateQRCode: async (
275
- linkIdString: Link["idString"],
276
- options?: GetLinkQRCodeOptions,
277
- ): Promise<ErrorResBody | Buffer> => {
278
- const res = await fetch(`${this.baseApiUrl}/links/qr/${linkIdString}`, {
279
- method: "POST",
280
- headers: {
281
- "Content-Type": "application/json",
282
- Authorization: this.apiKey,
283
- },
284
- body: JSON.stringify(options),
285
- });
286
- const buffer = Buffer.from(await res.arrayBuffer());
287
- return buffer;
288
- },
289
-
290
- /**
291
- * Get Open Graph data for a link.
292
- * API reference: https://developers.short.io/reference/opengraphbydomainidandlinkidget
293
- * @param domainId Domain id
294
- * @param linkIdString Link id string
295
- * @returns Open Graph data
296
- */
297
- getOpenGraph: async (
298
- domainId: Domain["id"],
299
- linkIdString: Link["idString"],
300
- ): Promise<LinkOpenGraphData | ErrorResBody> => {
301
- const res = await fetch(`${this.baseApiUrl}/links/opengraph/${domainId}/${linkIdString}`, {
302
- method: "GET",
303
- headers: {
304
- "Content-Type": "application/json",
305
- Authorization: this.apiKey,
306
- },
307
- });
308
- const openGraphData = await res.json();
309
- return openGraphData;
310
- },
311
-
312
- /**
313
- * Update Open Graph data for a link.
314
- * API reference: https://developers.short.io/reference/opengraphbydomainidandlinkidpost
315
- * @param domainId Domain id
316
- * @param linkIdString Link id string
317
- * @param newOpenGraphData updated Open Graph data
318
- * @returns Updated Open Graph data
319
- */
320
- updateOpenGraph: async (
321
- domainId: Domain["id"],
322
- linkIdString: Link["idString"],
323
- newOpenGraphData: LinkOpenGraphData,
324
- ): Promise<LinkOpenGraphData | ErrorResBody> => {
325
- const res = await fetch(`${this.baseApiUrl}/links/opengraph/${domainId}/${linkIdString}`, {
326
- method: "PUT",
327
- headers: {
328
- "Content-Type": "application/json",
329
- Authorization: this.apiKey,
330
- },
331
- body: JSON.stringify(newOpenGraphData),
332
- });
333
- const openGraphData = await res.json();
334
- return openGraphData;
335
- },
336
- };
337
-
338
- public readonly domain = {
339
- /**
340
- * Fetch all user domains.
341
- * API reference: https://developers.short.io/reference/apidomainsget
342
- * @returns List of domains
343
- */
344
- list: async (): Promise<Domain[] | ErrorResBody> => {
345
- const domainsRes = await fetch(`${this.baseApiUrl}/api/domains`, {
346
- method: "GET",
347
- headers: {
348
- "Content-Type": "application/json",
349
- Authorization: this.apiKey,
350
- },
351
- });
352
- const domains = await domainsRes.json();
353
- return domains;
354
- },
355
-
356
- /**
357
- * Create a new domain and add it to your short.io account.
358
- * API reference: https://developers.short.io/reference/domainspost
359
- */
360
- create: async (hostname: Domain["hostname"], options?: DomainCreateOptions): Promise<Domain | ErrorResBody> => {
361
- const domainsRes = await fetch(`${this.baseApiUrl}/domains`, {
362
- method: "POST",
363
- headers: {
364
- "Content-Type": "application/json",
365
- Authorization: this.apiKey,
366
- },
367
- body: JSON.stringify({
368
- hostname,
369
- ...options,
370
- }),
371
- });
372
- const domain = await domainsRes.json();
373
- return domain;
374
- },
375
- };
376
-
377
- public readonly linkCountry = {
378
- /**
379
- * Returns list of country rules for a given link
380
- * API reference: https://developers.short.io/reference/linkcountrybylinkidget
381
- * @param linkIdString Link id string
382
- * @returns List of link country rules
383
- */
384
- list: async (linkIdString: Link["idString"]): Promise<LinkCountry[] | ErrorResBody> => {
385
- const res = await fetch(`${this.baseApiUrl}/link_country/${linkIdString}`, {
386
- method: "GET",
387
- headers: {
388
- "Content-Type": "application/json",
389
- Authorization: this.apiKey,
390
- },
391
- });
392
- const linkCountries = await res.json();
393
- return linkCountries;
394
- },
395
-
396
- /**
397
- * Create country rule for a given link
398
- * API reference: https://developers.short.io/reference/linkcountrybylinkidpost
399
- * @param linkIdString Link id string
400
- * @param options Options for the request
401
- * @returns Created link country rule
402
- */
403
- create: async (
404
- linkIdString: Link["idString"],
405
- options: LinkCountryCreateOptions,
406
- ): Promise<LinkCountry | ErrorResBody> => {
407
- const res = await fetch(`${this.baseApiUrl}/link_country/${linkIdString}`, {
408
- method: "POST",
409
- headers: {
410
- "Content-Type": "application/json",
411
- Authorization: this.apiKey,
412
- },
413
- body: JSON.stringify(options),
414
- });
415
- const linkCountry = await res.json();
416
- return linkCountry;
417
- },
418
-
419
- /**
420
- * Delete country rule for a given link
421
- * API reference: https://developers.short.io/reference/linkcountrybylinkidandcountrydelete
422
- * @param linkIdString Link id string
423
- * @param country Country code
424
- * @returns Empty response body
425
- */
426
- delete: async (
427
- linkIdString: Link["idString"],
428
- country: LinkCountry["country"],
429
- ): Promise<SuccessResBody | ErrorResBody> => {
430
- const res = await fetch(`${this.baseApiUrl}/link_country/${linkIdString}/${country}`, {
431
- method: "DELETE",
432
- headers: {
433
- "Content-Type": "application/json",
434
- Authorization: this.apiKey,
435
- },
436
- });
437
- const linkCountryDeleteRes = await res.json();
438
- return linkCountryDeleteRes;
439
- },
440
- };
441
-
442
- public readonly linkRegion = {
443
- /**
444
- * Returns list of region rules for a given link
445
- * API reference: https://developers.short.io/reference/linkregionbylinkidget
446
- * @param linkIdString Link id string
447
- * @returns List of link region rules
448
- */
449
- list: async (linkIdString: Link["idString"]): Promise<LinkRegion[] | ErrorResBody> => {
450
- const res = await fetch(`${this.baseApiUrl}/link_region/${linkIdString}`, {
451
- method: "GET",
452
- headers: {
453
- "Content-Type": "application/json",
454
- Authorization: this.apiKey,
455
- },
456
- });
457
- const linkRegions = await res.json();
458
- return linkRegions;
459
- },
460
-
461
- /**
462
- * Create region rule for a given link
463
- * API reference: https://developers.short.io/reference/linkregionbylinkidpost
464
- * @param linkIdString Link id string
465
- * @param options Options for the request
466
- * @returns Created link region rule
467
- */
468
- create: async (
469
- linkIdString: Link["idString"],
470
- options: LinkRegionCreateOptions,
471
- ): Promise<LinkRegion | ErrorResBody> => {
472
- const res = await fetch(`${this.baseApiUrl}/link_region/${linkIdString}`, {
473
- method: "POST",
474
- headers: {
475
- "Content-Type": "application/json",
476
- Authorization: this.apiKey,
477
- },
478
- body: JSON.stringify(options),
479
- });
480
- const linkRegion = await res.json();
481
- return linkRegion;
482
- },
483
-
484
- /**
485
- * Delete region rule for a given link
486
- * API reference: https://developers.short.io/reference/linkregionregionbylinkidandcountrydelete
487
- * @param linkIdString Link id string
488
- * @param options Options for the request
489
- * @returns Empty response body
490
- */
491
- delete: async (
492
- linkIdString: Link["idString"],
493
- options: LinkRegionDeleteOptions,
494
- ): Promise<SuccessResBody | ErrorResBody> => {
495
- const res = await fetch(
496
- `${this.baseApiUrl}/link_region/${linkIdString}/${options.country}/${options.region}`,
497
- {
498
- method: "DELETE",
499
- headers: {
500
- "Content-Type": "application/json",
501
- Authorization: this.apiKey,
502
- },
503
- },
504
- );
505
- const linkRegionDeleteRes = await res.json();
506
- return linkRegionDeleteRes;
507
- },
508
- };
509
-
510
- public readonly statistics = {
511
- /**
512
- * Return link statistics
513
- * API reference: https://developers.short.io/reference/getlinklinkid
514
- * @param linkIdString Link id string
515
- * @param options Options for the request
516
- * @returns Link statistics
517
- */
518
- getByLink: async (
519
- linkIdString: Link["idString"],
520
- options?: GetStatisticsOptions,
521
- ): Promise<LinkStatistics | ErrorResBody> => {
522
- let queryString = "";
523
- if (options) {
524
- for (const param in options) {
525
- queryString += `&${param}=${options[param as keyof GetStatisticsOptions]}`;
526
- }
527
- }
528
- const res = await fetch(
529
- `${this.baseStatisticsUrl}/link/${linkIdString}${queryString ? "?" + queryString : ""}`,
530
- {
531
- method: "GET",
532
- headers: {
533
- "Content-Type": "application/json",
534
- Authorization: this.apiKey,
535
- },
536
- },
537
- );
538
- const statistics = await res.json();
539
- return statistics;
540
- },
541
-
542
- /**
543
- * Return link statistics. The same as getByLink(), but uses POST method and sends all parameters in the body including filter parameters (include and exclude)
544
- * API reference: https://developers.short.io/reference/postlinklinkid
545
- * @param linkIdString Link id string
546
- * @param options Options for the request
547
- * @returns Link statistics
548
- */
549
- getByLinkPost: async (
550
- linkIdString: Link["idString"],
551
- options?: GetStatisticsOptions & {
552
- include?: FilterOptions;
553
- exclude?: FilterOptions;
554
- },
555
- ): Promise<LinkStatistics | ErrorResBody> => {
556
- const res = await fetch(`${this.baseStatisticsUrl}/link/${linkIdString}`, {
557
- method: "POST",
558
- headers: {
559
- "Content-Type": "application/json",
560
- Authorization: this.apiKey,
561
- },
562
- body: JSON.stringify(options),
563
- });
564
- const statistics = await res.json();
565
- return statistics;
566
- },
567
-
568
- /**
569
- * Return domain statistics
570
- * API reference: https://developers.short.io/reference/getdomaindomainid
571
- * @param domainId Domain id
572
- * @param options Options for the request
573
- * @returns Domain statistics
574
- */
575
- getByDomain: async (
576
- domainId: Domain["id"],
577
- options?: GetStatisticsOptions,
578
- ): Promise<DomainStatistics | ErrorResBody> => {
579
- let queryString = "";
580
- if (options) {
581
- for (const param in options) {
582
- queryString += `&${param}=${options[param as keyof GetStatisticsOptions]}`;
583
- }
584
- }
585
- const res = await fetch(
586
- `${this.baseStatisticsUrl}/domain/${domainId}${queryString ? "?" + queryString : ""}`,
587
- {
588
- method: "GET",
589
- headers: {
590
- "Content-Type": "application/json",
591
- Authorization: this.apiKey,
592
- },
593
- },
594
- );
595
- const statistics = await res.json();
596
- return statistics;
597
- },
598
-
599
- /**
600
- * Return domain statistics. The same as getByDomain(), but uses POST method and sends all parameters in the body including filter parameters (include and exclude)
601
- * API reference: https://developers.short.io/reference/postdomaindomainid
602
- * @param domainId Domain id
603
- * @param options Options for the request
604
- * @returns Domain statistics
605
- */
606
- getByDomainPost: async (
607
- domainId: Domain["id"],
608
- options?: GetStatisticsOptions & IncludeExcludeOptions,
609
- ): Promise<DomainStatistics | ErrorResBody> => {
610
- const res = await fetch(`${this.baseStatisticsUrl}/domain/${domainId}`, {
611
- method: "POST",
612
- headers: {
613
- "Content-Type": "application/json",
614
- Authorization: this.apiKey,
615
- },
616
- body: JSON.stringify(options),
617
- });
618
- const statistics = await res.json();
619
- return statistics;
620
- },
621
-
622
- /**
623
- * Gets link clicks for link ids
624
- * API reference: https://developers.short.io/reference/getdomaindomainidlink_clicks
625
- * @param domainId Domain id
626
- * @param options Options for the request. Ids is a string with comma separated link id strings
627
- * @returns Link clicks for requested links
628
- */
629
- getLinkClicks: async (
630
- domainId: Domain["id"],
631
- options: StartEndDate & LinkIds,
632
- ): Promise<LinkClicks | ErrorResBody> => {
633
- let queryString = "";
634
- for (const param in options) {
635
- queryString += `&${param}=${options[param as keyof (StartEndDate & LinkIds)]}`;
636
- }
637
- const res = await fetch(
638
- `${this.baseStatisticsUrl}/domain/${domainId}/link_clicks${queryString ? "?" + queryString : ""}`,
639
- {
640
- method: "GET",
641
- headers: {
642
- "Content-Type": "application/json",
643
- Authorization: this.apiKey,
644
- },
645
- },
646
- );
647
- const statistics = await res.json();
648
- return statistics;
649
- },
650
-
651
- /**
652
- * Gets link clicks for link paths and dates in the body
653
- * API reference: https://developers.short.io/reference/postdomaindomainidlink_clicks
654
- * @param domainId Domain id
655
- * @param options Options for the request
656
- * @returns Link clicks for requested links
657
- */
658
- getLinkClicksByPathDates: async (
659
- domainId: Domain["id"],
660
- pathsDates: PathDate[],
661
- options?: StartEndDate,
662
- ): Promise<PathClicks | ErrorResBody> => {
663
- let queryString = "";
664
- if (options) {
665
- for (const param in options) {
666
- queryString += `&${param}=${options[param as keyof StartEndDate]}`;
667
- }
668
- }
669
- const res = await fetch(
670
- `${this.baseStatisticsUrl}/domain/${domainId}/link_clicks${queryString ? "?" + queryString : ""}`,
671
- {
672
- method: "POST",
673
- headers: {
674
- "Content-Type": "application/json",
675
- Authorization: this.apiKey,
676
- },
677
- body: JSON.stringify({ pathsDates }),
678
- },
679
- );
680
- const statistics = await res.json();
681
- return statistics;
682
- },
683
-
684
- /**
685
- * Get top values of specified column, ordered by clicks desc
686
- * API reference: https://developers.short.io/reference/postdomaindomainidtop
687
- * @param domainId Domain id
688
- * @param column Column to get top values for
689
- * @param options Options for the request
690
- * @returns Top values of specified column for the domain
691
- */
692
- getTopByColumn: async (
693
- domainId: Domain["id"],
694
- column: Column,
695
- options?: TopByColumnOptions,
696
- ): Promise<TopColumnRes[]> => {
697
- const res = await fetch(`${this.baseStatisticsUrl}/domain/${domainId}/top`, {
698
- method: "POST",
699
- headers: {
700
- "Content-Type": "application/json",
701
- Authorization: this.apiKey,
702
- },
703
- body: JSON.stringify({ column, ...options }),
704
- });
705
- const statistics = await res.json();
706
- return statistics;
707
- },
708
-
709
- /**
710
- * Get values by interval and counts for specified column
711
- * @param domainId Domain id
712
- * @param column Column to get top values for
713
- * @param options Options for the request
714
- * @returns Values by interval and counts for specified column
715
- */
716
- getTopByInterval: async (
717
- domainId: Domain["id"],
718
- column: Column,
719
- options?: TopByIntervalOptions,
720
- ): Promise<TopByIntervalRes[] | ErrorResBody> => {
721
- const res = await fetch(`${this.baseStatisticsUrl}/domain/${domainId}/top_by_interval`, {
722
- method: "POST",
723
- headers: {
724
- "Content-Type": "application/json",
725
- Authorization: this.apiKey,
726
- },
727
- body: JSON.stringify({ column, ...options }),
728
- });
729
- const statistics = await res.json();
730
- return statistics;
731
- },
732
-
733
- /**
734
- * Get list of latest raw clicks
735
- * API reference: https://developers.short.io/reference/postdomaindomainidlast_clicks
736
- * @param domainId Domain id
737
- * @param options Options for the request
738
- * @returns List of latest raw clicks
739
- */
740
- getLastClicks: async (
741
- domainId: Domain["id"],
742
- options?: GetLastClicksOptions,
743
- ): Promise<LastClicksRes | ErrorResBody> => {
744
- const res = await fetch(`${this.baseStatisticsUrl}/domain/${domainId}/last_clicks`, {
745
- method: "POST",
746
- headers: {
747
- "Content-Type": "application/json",
748
- Authorization: this.apiKey,
749
- },
750
- body: JSON.stringify(options),
751
- });
752
- const statistics = await res.json();
753
- return statistics;
754
- },
755
-
756
- /**
757
- * Clear statistics of specified domain
758
- * API reference: https://developers.short.io/reference/deletedomaindomainidstatistics
759
- * @param domainId Domain id
760
- * @returns Empty response body
761
- */
762
- clear: async (domainId: Domain["id"]): Promise<SuccessResBody | ErrorResBody> => {
763
- const res = await fetch(`${this.baseStatisticsUrl}/domain/${domainId}/statistics`, {
764
- method: "DELETE",
765
- headers: {
766
- "Content-Type": "application/json",
767
- Authorization: this.apiKey,
768
- },
769
- });
770
- const deleteRes = await res.json();
771
- return deleteRes;
772
- },
773
- };
774
- }
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+ export * from "./types.gen";
3
+ export * from "./sdk.gen";