@short.io/client-node 1.1.0 → 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/README.md +29 -39
- package/package.json +21 -11
- package/src/index.ts +3 -830
- package/src/sdk.gen.ts +688 -0
- package/src/types.gen.ts +4560 -0
- package/tsconfig.json +4 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/.eslintignore +0 -1
- package/.eslintrc.cjs +0 -3
- package/dist/index.d.ts +0 -54
- package/dist/index.js +0 -438
- package/dist/index.js.map +0 -1
- package/dist/types/common.d.ts +0 -9
- package/dist/types/common.js +0 -2
- package/dist/types/common.js.map +0 -1
- package/dist/types/domain.d.ts +0 -43
- package/dist/types/domain.js +0 -2
- package/dist/types/domain.js.map +0 -1
- package/dist/types/index.d.ts +0 -4
- package/dist/types/index.js +0 -5
- package/dist/types/index.js.map +0 -1
- package/dist/types/link.d.ts +0 -131
- package/dist/types/link.js +0 -2
- package/dist/types/link.js.map +0 -1
- package/dist/types/statistics.d.ts +0 -199
- package/dist/types/statistics.js +0 -2
- package/dist/types/statistics.js.map +0 -1
- package/dist/types.d.ts +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/src/types/common.ts +0 -11
- package/src/types/domain.ts +0 -44
- package/src/types/index.ts +0 -4
- package/src/types/link.ts +0 -159
- package/src/types/statistics.ts +0 -242
package/src/index.ts
CHANGED
|
@@ -1,830 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
LinkUpdateOptions,
|
|
17
|
-
LinkWithUser,
|
|
18
|
-
LinksAndCount,
|
|
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 Created link or error response
|
|
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()) as Link | (SuccessResBody & ErrorResBody);
|
|
174
|
-
return link;
|
|
175
|
-
},
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Encode original URL, then shorten it with public key and create a new short link.
|
|
179
|
-
* If parameter "path" in the options is omitted, it generates path by algorithm, chosen in domain settings.
|
|
180
|
-
* To decrypt and navigate the long original URL add the returned key in base64 format to the short link as a hash.
|
|
181
|
-
*
|
|
182
|
-
* **Note that secure links feature usage is available only for Team and Enterprise plans.**
|
|
183
|
-
*
|
|
184
|
-
* API reference: https://developers.short.io/reference/linkspostsecure
|
|
185
|
-
* @param hostname Domain hostname
|
|
186
|
-
* @param originalURL Original URL of the link
|
|
187
|
-
* @param publicAPIKey Public API key
|
|
188
|
-
* @param options Options for the request
|
|
189
|
-
* @returns Created link with the keyBase64 or error response
|
|
190
|
-
*/
|
|
191
|
-
createSecure: async (
|
|
192
|
-
hostname: Domain["hostname"],
|
|
193
|
-
originalURL: Link["originalURL"],
|
|
194
|
-
publicAPIKey: string,
|
|
195
|
-
options?: LinkCreateOptions,
|
|
196
|
-
): Promise<Link | ErrorResBody> => {
|
|
197
|
-
const cryptoKey = await crypto.subtle.generateKey(
|
|
198
|
-
{
|
|
199
|
-
name: "AES-GCM",
|
|
200
|
-
length: 128,
|
|
201
|
-
},
|
|
202
|
-
true,
|
|
203
|
-
["encrypt", "decrypt"],
|
|
204
|
-
);
|
|
205
|
-
const iv = crypto.getRandomValues(new Uint8Array(12));
|
|
206
|
-
const urlData = new TextEncoder().encode(originalURL);
|
|
207
|
-
const encryptedUrl = await crypto.subtle.encrypt(
|
|
208
|
-
{
|
|
209
|
-
name: "AES-GCM",
|
|
210
|
-
iv,
|
|
211
|
-
},
|
|
212
|
-
cryptoKey,
|
|
213
|
-
urlData,
|
|
214
|
-
);
|
|
215
|
-
const encryptedUrlBase64 = Buffer.from(encryptedUrl).toString("base64");
|
|
216
|
-
const encryptedIvBase64 = Buffer.from(iv).toString("base64");
|
|
217
|
-
const encryptedData = `shortsecure://${encryptedUrlBase64}?${encryptedIvBase64}`;
|
|
218
|
-
const link = (await this.link.createPublic(hostname, encryptedData, publicAPIKey, options)) as
|
|
219
|
-
| Link
|
|
220
|
-
| (SuccessResBody & ErrorResBody);
|
|
221
|
-
if ("error" in link) {
|
|
222
|
-
return {
|
|
223
|
-
error: link.error,
|
|
224
|
-
} as ErrorResBody;
|
|
225
|
-
}
|
|
226
|
-
const exportedKey = await crypto.subtle.exportKey("raw", cryptoKey);
|
|
227
|
-
const keyBase64 = Buffer.from(new Uint8Array(exportedKey)).toString("base64");
|
|
228
|
-
link.shortURL += `#${keyBase64}`;
|
|
229
|
-
link.secureShortURL += `#${keyBase64}`;
|
|
230
|
-
return link;
|
|
231
|
-
},
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* Shorten links in bulk. Method accepts up to 1000 links in one API call.
|
|
235
|
-
* API reference: https://developers.short.io/reference/linksbulkpost
|
|
236
|
-
* @param hostname Domain hostname
|
|
237
|
-
* @param links Links to be shortened
|
|
238
|
-
* @param allowDuplicates Allow duplicate links
|
|
239
|
-
* @returns Shortened links
|
|
240
|
-
*/
|
|
241
|
-
bulkCreate: async (
|
|
242
|
-
hostname: Domain["hostname"],
|
|
243
|
-
links: LinkBulkCreateOptions[],
|
|
244
|
-
allowDuplicates = false,
|
|
245
|
-
): Promise<(Link & SuccessResBody)[] | (SuccessResBody & ErrorResBody & StatusResBody)> => {
|
|
246
|
-
const linkRes = await fetch(`${this.baseApiUrl}/links/bulk`, {
|
|
247
|
-
method: "POST",
|
|
248
|
-
headers: {
|
|
249
|
-
"Content-Type": "application/json",
|
|
250
|
-
Authorization: this.apiKey,
|
|
251
|
-
},
|
|
252
|
-
body: JSON.stringify({
|
|
253
|
-
domain: hostname,
|
|
254
|
-
links,
|
|
255
|
-
allowDuplicates,
|
|
256
|
-
}),
|
|
257
|
-
});
|
|
258
|
-
const link = await linkRes.json();
|
|
259
|
-
return link;
|
|
260
|
-
},
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* Archive link by its id string.
|
|
264
|
-
* API reference: https://developers.short.io/reference/archivelink
|
|
265
|
-
* @param linkIdString Link id string
|
|
266
|
-
*/
|
|
267
|
-
archive: async (linkIdString: Link["idString"]): Promise<SuccessResBody | ErrorResBody> => {
|
|
268
|
-
const res = await fetch(`${this.baseApiUrl}/links/archive`, {
|
|
269
|
-
method: "POST",
|
|
270
|
-
headers: {
|
|
271
|
-
"Content-Type": "application/json",
|
|
272
|
-
Authorization: this.apiKey,
|
|
273
|
-
},
|
|
274
|
-
body: JSON.stringify({
|
|
275
|
-
link_id: linkIdString,
|
|
276
|
-
}),
|
|
277
|
-
});
|
|
278
|
-
const linkArchiveRes = await res.json();
|
|
279
|
-
return linkArchiveRes;
|
|
280
|
-
},
|
|
281
|
-
|
|
282
|
-
/**
|
|
283
|
-
* Update existing link.
|
|
284
|
-
* API reference: https://developers.short.io/reference/linksbylinkidpost
|
|
285
|
-
* @param linkIdString Link id string
|
|
286
|
-
* @param options Options for the request
|
|
287
|
-
* @returns Updated link with a user details
|
|
288
|
-
*/
|
|
289
|
-
update: async (
|
|
290
|
-
linkIdString: Link["idString"],
|
|
291
|
-
options: LinkUpdateOptions,
|
|
292
|
-
): Promise<LinkWithUser | UpdateLinkErrorRes> => {
|
|
293
|
-
const res = await fetch(`${this.baseApiUrl}/links/${linkIdString}`, {
|
|
294
|
-
method: "POST",
|
|
295
|
-
headers: {
|
|
296
|
-
"Content-Type": "application/json",
|
|
297
|
-
Authorization: this.apiKey,
|
|
298
|
-
},
|
|
299
|
-
body: JSON.stringify(options),
|
|
300
|
-
});
|
|
301
|
-
const linkUpdateRes = await res.json();
|
|
302
|
-
return linkUpdateRes;
|
|
303
|
-
},
|
|
304
|
-
|
|
305
|
-
/**
|
|
306
|
-
* Delete link by its id string.
|
|
307
|
-
* API reference: https://developers.short.io/reference/linksbylinkiddelete
|
|
308
|
-
* @param linkIdString Link id string
|
|
309
|
-
* @returns Deleted link id string
|
|
310
|
-
*/
|
|
311
|
-
delete: async (linkIdString: Link["idString"]): Promise<DeleteLinkRes | ErrorResBody> => {
|
|
312
|
-
const res = await fetch(`${this.baseApiUrl}/links/${linkIdString}`, {
|
|
313
|
-
method: "DELETE",
|
|
314
|
-
headers: {
|
|
315
|
-
"Content-Type": "application/json",
|
|
316
|
-
Authorization: this.apiKey,
|
|
317
|
-
},
|
|
318
|
-
});
|
|
319
|
-
const linkDeleteRes = await res.json();
|
|
320
|
-
return linkDeleteRes;
|
|
321
|
-
},
|
|
322
|
-
|
|
323
|
-
/**
|
|
324
|
-
* Generate QR code for a link.
|
|
325
|
-
* API reference: https://developers.short.io/reference/qrcodebylinkidpost
|
|
326
|
-
* @param linkIdString Link id string
|
|
327
|
-
* @param options Options for the request
|
|
328
|
-
* @returns QR code image
|
|
329
|
-
*/
|
|
330
|
-
generateQRCode: async (
|
|
331
|
-
linkIdString: Link["idString"],
|
|
332
|
-
options?: GetLinkQRCodeOptions,
|
|
333
|
-
): Promise<ErrorResBody | Buffer> => {
|
|
334
|
-
const res = await fetch(`${this.baseApiUrl}/links/qr/${linkIdString}`, {
|
|
335
|
-
method: "POST",
|
|
336
|
-
headers: {
|
|
337
|
-
"Content-Type": "application/json",
|
|
338
|
-
Authorization: this.apiKey,
|
|
339
|
-
},
|
|
340
|
-
body: JSON.stringify(options),
|
|
341
|
-
});
|
|
342
|
-
const buffer = Buffer.from(await res.arrayBuffer());
|
|
343
|
-
return buffer;
|
|
344
|
-
},
|
|
345
|
-
|
|
346
|
-
/**
|
|
347
|
-
* Get Open Graph data for a link.
|
|
348
|
-
* API reference: https://developers.short.io/reference/opengraphbydomainidandlinkidget
|
|
349
|
-
* @param domainId Domain id
|
|
350
|
-
* @param linkIdString Link id string
|
|
351
|
-
* @returns Open Graph data
|
|
352
|
-
*/
|
|
353
|
-
getOpenGraph: async (
|
|
354
|
-
domainId: Domain["id"],
|
|
355
|
-
linkIdString: Link["idString"],
|
|
356
|
-
): Promise<LinkOpenGraphData | ErrorResBody> => {
|
|
357
|
-
const res = await fetch(`${this.baseApiUrl}/links/opengraph/${domainId}/${linkIdString}`, {
|
|
358
|
-
method: "GET",
|
|
359
|
-
headers: {
|
|
360
|
-
"Content-Type": "application/json",
|
|
361
|
-
Authorization: this.apiKey,
|
|
362
|
-
},
|
|
363
|
-
});
|
|
364
|
-
const openGraphData = await res.json();
|
|
365
|
-
return openGraphData;
|
|
366
|
-
},
|
|
367
|
-
|
|
368
|
-
/**
|
|
369
|
-
* Update Open Graph data for a link.
|
|
370
|
-
* API reference: https://developers.short.io/reference/opengraphbydomainidandlinkidpost
|
|
371
|
-
* @param domainId Domain id
|
|
372
|
-
* @param linkIdString Link id string
|
|
373
|
-
* @param newOpenGraphData updated Open Graph data
|
|
374
|
-
* @returns Updated Open Graph data
|
|
375
|
-
*/
|
|
376
|
-
updateOpenGraph: async (
|
|
377
|
-
domainId: Domain["id"],
|
|
378
|
-
linkIdString: Link["idString"],
|
|
379
|
-
newOpenGraphData: LinkOpenGraphData,
|
|
380
|
-
): Promise<LinkOpenGraphData | ErrorResBody> => {
|
|
381
|
-
const res = await fetch(`${this.baseApiUrl}/links/opengraph/${domainId}/${linkIdString}`, {
|
|
382
|
-
method: "PUT",
|
|
383
|
-
headers: {
|
|
384
|
-
"Content-Type": "application/json",
|
|
385
|
-
Authorization: this.apiKey,
|
|
386
|
-
},
|
|
387
|
-
body: JSON.stringify(newOpenGraphData),
|
|
388
|
-
});
|
|
389
|
-
const openGraphData = await res.json();
|
|
390
|
-
return openGraphData;
|
|
391
|
-
},
|
|
392
|
-
};
|
|
393
|
-
|
|
394
|
-
public readonly domain = {
|
|
395
|
-
/**
|
|
396
|
-
* Fetch all user domains.
|
|
397
|
-
* API reference: https://developers.short.io/reference/apidomainsget
|
|
398
|
-
* @returns List of domains
|
|
399
|
-
*/
|
|
400
|
-
list: async (): Promise<Domain[] | ErrorResBody> => {
|
|
401
|
-
const domainsRes = await fetch(`${this.baseApiUrl}/api/domains`, {
|
|
402
|
-
method: "GET",
|
|
403
|
-
headers: {
|
|
404
|
-
"Content-Type": "application/json",
|
|
405
|
-
Authorization: this.apiKey,
|
|
406
|
-
},
|
|
407
|
-
});
|
|
408
|
-
const domains = await domainsRes.json();
|
|
409
|
-
return domains;
|
|
410
|
-
},
|
|
411
|
-
|
|
412
|
-
/**
|
|
413
|
-
* Create a new domain and add it to your short.io account.
|
|
414
|
-
* API reference: https://developers.short.io/reference/domainspost
|
|
415
|
-
*/
|
|
416
|
-
create: async (hostname: Domain["hostname"], options?: DomainCreateOptions): Promise<Domain | ErrorResBody> => {
|
|
417
|
-
const domainsRes = await fetch(`${this.baseApiUrl}/domains`, {
|
|
418
|
-
method: "POST",
|
|
419
|
-
headers: {
|
|
420
|
-
"Content-Type": "application/json",
|
|
421
|
-
Authorization: this.apiKey,
|
|
422
|
-
},
|
|
423
|
-
body: JSON.stringify({
|
|
424
|
-
hostname,
|
|
425
|
-
...options,
|
|
426
|
-
}),
|
|
427
|
-
});
|
|
428
|
-
const domain = await domainsRes.json();
|
|
429
|
-
return domain;
|
|
430
|
-
},
|
|
431
|
-
};
|
|
432
|
-
|
|
433
|
-
public readonly linkCountry = {
|
|
434
|
-
/**
|
|
435
|
-
* Returns list of country rules for a given link
|
|
436
|
-
* API reference: https://developers.short.io/reference/linkcountrybylinkidget
|
|
437
|
-
* @param linkIdString Link id string
|
|
438
|
-
* @returns List of link country rules
|
|
439
|
-
*/
|
|
440
|
-
list: async (linkIdString: Link["idString"]): Promise<LinkCountry[] | ErrorResBody> => {
|
|
441
|
-
const res = await fetch(`${this.baseApiUrl}/link_country/${linkIdString}`, {
|
|
442
|
-
method: "GET",
|
|
443
|
-
headers: {
|
|
444
|
-
"Content-Type": "application/json",
|
|
445
|
-
Authorization: this.apiKey,
|
|
446
|
-
},
|
|
447
|
-
});
|
|
448
|
-
const linkCountries = await res.json();
|
|
449
|
-
return linkCountries;
|
|
450
|
-
},
|
|
451
|
-
|
|
452
|
-
/**
|
|
453
|
-
* Create country rule for a given link
|
|
454
|
-
* API reference: https://developers.short.io/reference/linkcountrybylinkidpost
|
|
455
|
-
* @param linkIdString Link id string
|
|
456
|
-
* @param options Options for the request
|
|
457
|
-
* @returns Created link country rule
|
|
458
|
-
*/
|
|
459
|
-
create: async (
|
|
460
|
-
linkIdString: Link["idString"],
|
|
461
|
-
options: LinkCountryCreateOptions,
|
|
462
|
-
): Promise<LinkCountry | ErrorResBody> => {
|
|
463
|
-
const res = await fetch(`${this.baseApiUrl}/link_country/${linkIdString}`, {
|
|
464
|
-
method: "POST",
|
|
465
|
-
headers: {
|
|
466
|
-
"Content-Type": "application/json",
|
|
467
|
-
Authorization: this.apiKey,
|
|
468
|
-
},
|
|
469
|
-
body: JSON.stringify(options),
|
|
470
|
-
});
|
|
471
|
-
const linkCountry = await res.json();
|
|
472
|
-
return linkCountry;
|
|
473
|
-
},
|
|
474
|
-
|
|
475
|
-
/**
|
|
476
|
-
* Delete country rule for a given link
|
|
477
|
-
* API reference: https://developers.short.io/reference/linkcountrybylinkidandcountrydelete
|
|
478
|
-
* @param linkIdString Link id string
|
|
479
|
-
* @param country Country code
|
|
480
|
-
* @returns Empty response body
|
|
481
|
-
*/
|
|
482
|
-
delete: async (
|
|
483
|
-
linkIdString: Link["idString"],
|
|
484
|
-
country: LinkCountry["country"],
|
|
485
|
-
): Promise<SuccessResBody | ErrorResBody> => {
|
|
486
|
-
const res = await fetch(`${this.baseApiUrl}/link_country/${linkIdString}/${country}`, {
|
|
487
|
-
method: "DELETE",
|
|
488
|
-
headers: {
|
|
489
|
-
"Content-Type": "application/json",
|
|
490
|
-
Authorization: this.apiKey,
|
|
491
|
-
},
|
|
492
|
-
});
|
|
493
|
-
const linkCountryDeleteRes = await res.json();
|
|
494
|
-
return linkCountryDeleteRes;
|
|
495
|
-
},
|
|
496
|
-
};
|
|
497
|
-
|
|
498
|
-
public readonly linkRegion = {
|
|
499
|
-
/**
|
|
500
|
-
* Returns list of region rules for a given link
|
|
501
|
-
* API reference: https://developers.short.io/reference/linkregionbylinkidget
|
|
502
|
-
* @param linkIdString Link id string
|
|
503
|
-
* @returns List of link region rules
|
|
504
|
-
*/
|
|
505
|
-
list: async (linkIdString: Link["idString"]): Promise<LinkRegion[] | ErrorResBody> => {
|
|
506
|
-
const res = await fetch(`${this.baseApiUrl}/link_region/${linkIdString}`, {
|
|
507
|
-
method: "GET",
|
|
508
|
-
headers: {
|
|
509
|
-
"Content-Type": "application/json",
|
|
510
|
-
Authorization: this.apiKey,
|
|
511
|
-
},
|
|
512
|
-
});
|
|
513
|
-
const linkRegions = await res.json();
|
|
514
|
-
return linkRegions;
|
|
515
|
-
},
|
|
516
|
-
|
|
517
|
-
/**
|
|
518
|
-
* Create region rule for a given link
|
|
519
|
-
* API reference: https://developers.short.io/reference/linkregionbylinkidpost
|
|
520
|
-
* @param linkIdString Link id string
|
|
521
|
-
* @param options Options for the request
|
|
522
|
-
* @returns Created link region rule
|
|
523
|
-
*/
|
|
524
|
-
create: async (
|
|
525
|
-
linkIdString: Link["idString"],
|
|
526
|
-
options: LinkRegionCreateOptions,
|
|
527
|
-
): Promise<LinkRegion | ErrorResBody> => {
|
|
528
|
-
const res = await fetch(`${this.baseApiUrl}/link_region/${linkIdString}`, {
|
|
529
|
-
method: "POST",
|
|
530
|
-
headers: {
|
|
531
|
-
"Content-Type": "application/json",
|
|
532
|
-
Authorization: this.apiKey,
|
|
533
|
-
},
|
|
534
|
-
body: JSON.stringify(options),
|
|
535
|
-
});
|
|
536
|
-
const linkRegion = await res.json();
|
|
537
|
-
return linkRegion;
|
|
538
|
-
},
|
|
539
|
-
|
|
540
|
-
/**
|
|
541
|
-
* Delete region rule for a given link
|
|
542
|
-
* API reference: https://developers.short.io/reference/linkregionregionbylinkidandcountrydelete
|
|
543
|
-
* @param linkIdString Link id string
|
|
544
|
-
* @param options Options for the request
|
|
545
|
-
* @returns Empty response body
|
|
546
|
-
*/
|
|
547
|
-
delete: async (
|
|
548
|
-
linkIdString: Link["idString"],
|
|
549
|
-
options: LinkRegionDeleteOptions,
|
|
550
|
-
): Promise<SuccessResBody | ErrorResBody> => {
|
|
551
|
-
const res = await fetch(
|
|
552
|
-
`${this.baseApiUrl}/link_region/${linkIdString}/${options.country}/${options.region}`,
|
|
553
|
-
{
|
|
554
|
-
method: "DELETE",
|
|
555
|
-
headers: {
|
|
556
|
-
"Content-Type": "application/json",
|
|
557
|
-
Authorization: this.apiKey,
|
|
558
|
-
},
|
|
559
|
-
},
|
|
560
|
-
);
|
|
561
|
-
const linkRegionDeleteRes = await res.json();
|
|
562
|
-
return linkRegionDeleteRes;
|
|
563
|
-
},
|
|
564
|
-
};
|
|
565
|
-
|
|
566
|
-
public readonly statistics = {
|
|
567
|
-
/**
|
|
568
|
-
* Return link statistics
|
|
569
|
-
* API reference: https://developers.short.io/reference/getlinklinkid
|
|
570
|
-
* @param linkIdString Link id string
|
|
571
|
-
* @param options Options for the request
|
|
572
|
-
* @returns Link statistics
|
|
573
|
-
*/
|
|
574
|
-
getByLink: async (
|
|
575
|
-
linkIdString: Link["idString"],
|
|
576
|
-
options?: GetStatisticsOptions,
|
|
577
|
-
): Promise<LinkStatistics | ErrorResBody> => {
|
|
578
|
-
let queryString = "";
|
|
579
|
-
if (options) {
|
|
580
|
-
for (const param in options) {
|
|
581
|
-
queryString += `&${param}=${options[param as keyof GetStatisticsOptions]}`;
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
const res = await fetch(
|
|
585
|
-
`${this.baseStatisticsUrl}/link/${linkIdString}${queryString ? "?" + queryString : ""}`,
|
|
586
|
-
{
|
|
587
|
-
method: "GET",
|
|
588
|
-
headers: {
|
|
589
|
-
"Content-Type": "application/json",
|
|
590
|
-
Authorization: this.apiKey,
|
|
591
|
-
},
|
|
592
|
-
},
|
|
593
|
-
);
|
|
594
|
-
const statistics = await res.json();
|
|
595
|
-
return statistics;
|
|
596
|
-
},
|
|
597
|
-
|
|
598
|
-
/**
|
|
599
|
-
* Return link statistics. The same as getByLink(), but uses POST method and sends all parameters in the body including filter parameters (include and exclude)
|
|
600
|
-
* API reference: https://developers.short.io/reference/postlinklinkid
|
|
601
|
-
* @param linkIdString Link id string
|
|
602
|
-
* @param options Options for the request
|
|
603
|
-
* @returns Link statistics
|
|
604
|
-
*/
|
|
605
|
-
getByLinkPost: async (
|
|
606
|
-
linkIdString: Link["idString"],
|
|
607
|
-
options?: GetStatisticsOptions & {
|
|
608
|
-
include?: FilterOptions;
|
|
609
|
-
exclude?: FilterOptions;
|
|
610
|
-
},
|
|
611
|
-
): Promise<LinkStatistics | ErrorResBody> => {
|
|
612
|
-
const res = await fetch(`${this.baseStatisticsUrl}/link/${linkIdString}`, {
|
|
613
|
-
method: "POST",
|
|
614
|
-
headers: {
|
|
615
|
-
"Content-Type": "application/json",
|
|
616
|
-
Authorization: this.apiKey,
|
|
617
|
-
},
|
|
618
|
-
body: JSON.stringify(options),
|
|
619
|
-
});
|
|
620
|
-
const statistics = await res.json();
|
|
621
|
-
return statistics;
|
|
622
|
-
},
|
|
623
|
-
|
|
624
|
-
/**
|
|
625
|
-
* Return domain statistics
|
|
626
|
-
* API reference: https://developers.short.io/reference/getdomaindomainid
|
|
627
|
-
* @param domainId Domain id
|
|
628
|
-
* @param options Options for the request
|
|
629
|
-
* @returns Domain statistics
|
|
630
|
-
*/
|
|
631
|
-
getByDomain: async (
|
|
632
|
-
domainId: Domain["id"],
|
|
633
|
-
options?: GetStatisticsOptions,
|
|
634
|
-
): Promise<DomainStatistics | ErrorResBody> => {
|
|
635
|
-
let queryString = "";
|
|
636
|
-
if (options) {
|
|
637
|
-
for (const param in options) {
|
|
638
|
-
queryString += `&${param}=${options[param as keyof GetStatisticsOptions]}`;
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
const res = await fetch(
|
|
642
|
-
`${this.baseStatisticsUrl}/domain/${domainId}${queryString ? "?" + queryString : ""}`,
|
|
643
|
-
{
|
|
644
|
-
method: "GET",
|
|
645
|
-
headers: {
|
|
646
|
-
"Content-Type": "application/json",
|
|
647
|
-
Authorization: this.apiKey,
|
|
648
|
-
},
|
|
649
|
-
},
|
|
650
|
-
);
|
|
651
|
-
const statistics = await res.json();
|
|
652
|
-
return statistics;
|
|
653
|
-
},
|
|
654
|
-
|
|
655
|
-
/**
|
|
656
|
-
* Return domain statistics. The same as getByDomain(), but uses POST method and sends all parameters in the body including filter parameters (include and exclude)
|
|
657
|
-
* API reference: https://developers.short.io/reference/postdomaindomainid
|
|
658
|
-
* @param domainId Domain id
|
|
659
|
-
* @param options Options for the request
|
|
660
|
-
* @returns Domain statistics
|
|
661
|
-
*/
|
|
662
|
-
getByDomainPost: async (
|
|
663
|
-
domainId: Domain["id"],
|
|
664
|
-
options?: GetStatisticsOptions & IncludeExcludeOptions,
|
|
665
|
-
): Promise<DomainStatistics | ErrorResBody> => {
|
|
666
|
-
const res = await fetch(`${this.baseStatisticsUrl}/domain/${domainId}`, {
|
|
667
|
-
method: "POST",
|
|
668
|
-
headers: {
|
|
669
|
-
"Content-Type": "application/json",
|
|
670
|
-
Authorization: this.apiKey,
|
|
671
|
-
},
|
|
672
|
-
body: JSON.stringify(options),
|
|
673
|
-
});
|
|
674
|
-
const statistics = await res.json();
|
|
675
|
-
return statistics;
|
|
676
|
-
},
|
|
677
|
-
|
|
678
|
-
/**
|
|
679
|
-
* Gets link clicks for link ids
|
|
680
|
-
* API reference: https://developers.short.io/reference/getdomaindomainidlink_clicks
|
|
681
|
-
* @param domainId Domain id
|
|
682
|
-
* @param options Options for the request. Ids is a string with comma separated link id strings
|
|
683
|
-
* @returns Link clicks for requested links
|
|
684
|
-
*/
|
|
685
|
-
getLinkClicks: async (
|
|
686
|
-
domainId: Domain["id"],
|
|
687
|
-
options: StartEndDate & LinkIds,
|
|
688
|
-
): Promise<LinkClicks | ErrorResBody> => {
|
|
689
|
-
let queryString = "";
|
|
690
|
-
for (const param in options) {
|
|
691
|
-
queryString += `&${param}=${options[param as keyof (StartEndDate & LinkIds)]}`;
|
|
692
|
-
}
|
|
693
|
-
const res = await fetch(
|
|
694
|
-
`${this.baseStatisticsUrl}/domain/${domainId}/link_clicks${queryString ? "?" + queryString : ""}`,
|
|
695
|
-
{
|
|
696
|
-
method: "GET",
|
|
697
|
-
headers: {
|
|
698
|
-
"Content-Type": "application/json",
|
|
699
|
-
Authorization: this.apiKey,
|
|
700
|
-
},
|
|
701
|
-
},
|
|
702
|
-
);
|
|
703
|
-
const statistics = await res.json();
|
|
704
|
-
return statistics;
|
|
705
|
-
},
|
|
706
|
-
|
|
707
|
-
/**
|
|
708
|
-
* Gets link clicks for link paths and dates in the body
|
|
709
|
-
* API reference: https://developers.short.io/reference/postdomaindomainidlink_clicks
|
|
710
|
-
* @param domainId Domain id
|
|
711
|
-
* @param options Options for the request
|
|
712
|
-
* @returns Link clicks for requested links
|
|
713
|
-
*/
|
|
714
|
-
getLinkClicksByPathDates: async (
|
|
715
|
-
domainId: Domain["id"],
|
|
716
|
-
pathsDates: PathDate[],
|
|
717
|
-
options?: StartEndDate,
|
|
718
|
-
): Promise<PathClicks | ErrorResBody> => {
|
|
719
|
-
let queryString = "";
|
|
720
|
-
if (options) {
|
|
721
|
-
for (const param in options) {
|
|
722
|
-
queryString += `&${param}=${options[param as keyof StartEndDate]}`;
|
|
723
|
-
}
|
|
724
|
-
}
|
|
725
|
-
const res = await fetch(
|
|
726
|
-
`${this.baseStatisticsUrl}/domain/${domainId}/link_clicks${queryString ? "?" + queryString : ""}`,
|
|
727
|
-
{
|
|
728
|
-
method: "POST",
|
|
729
|
-
headers: {
|
|
730
|
-
"Content-Type": "application/json",
|
|
731
|
-
Authorization: this.apiKey,
|
|
732
|
-
},
|
|
733
|
-
body: JSON.stringify({ pathsDates }),
|
|
734
|
-
},
|
|
735
|
-
);
|
|
736
|
-
const statistics = await res.json();
|
|
737
|
-
return statistics;
|
|
738
|
-
},
|
|
739
|
-
|
|
740
|
-
/**
|
|
741
|
-
* Get top values of specified column, ordered by clicks desc
|
|
742
|
-
* API reference: https://developers.short.io/reference/postdomaindomainidtop
|
|
743
|
-
* @param domainId Domain id
|
|
744
|
-
* @param column Column to get top values for
|
|
745
|
-
* @param options Options for the request
|
|
746
|
-
* @returns Top values of specified column for the domain
|
|
747
|
-
*/
|
|
748
|
-
getTopByColumn: async (
|
|
749
|
-
domainId: Domain["id"],
|
|
750
|
-
column: Column,
|
|
751
|
-
options?: TopByColumnOptions,
|
|
752
|
-
): Promise<TopColumnRes[]> => {
|
|
753
|
-
const res = await fetch(`${this.baseStatisticsUrl}/domain/${domainId}/top`, {
|
|
754
|
-
method: "POST",
|
|
755
|
-
headers: {
|
|
756
|
-
"Content-Type": "application/json",
|
|
757
|
-
Authorization: this.apiKey,
|
|
758
|
-
},
|
|
759
|
-
body: JSON.stringify({ column, ...options }),
|
|
760
|
-
});
|
|
761
|
-
const statistics = await res.json();
|
|
762
|
-
return statistics;
|
|
763
|
-
},
|
|
764
|
-
|
|
765
|
-
/**
|
|
766
|
-
* Get values by interval and counts for specified column
|
|
767
|
-
* @param domainId Domain id
|
|
768
|
-
* @param column Column to get top values for
|
|
769
|
-
* @param options Options for the request
|
|
770
|
-
* @returns Values by interval and counts for specified column
|
|
771
|
-
*/
|
|
772
|
-
getTopByInterval: async (
|
|
773
|
-
domainId: Domain["id"],
|
|
774
|
-
column: Column,
|
|
775
|
-
options?: TopByIntervalOptions,
|
|
776
|
-
): Promise<TopByIntervalRes[] | ErrorResBody> => {
|
|
777
|
-
const res = await fetch(`${this.baseStatisticsUrl}/domain/${domainId}/top_by_interval`, {
|
|
778
|
-
method: "POST",
|
|
779
|
-
headers: {
|
|
780
|
-
"Content-Type": "application/json",
|
|
781
|
-
Authorization: this.apiKey,
|
|
782
|
-
},
|
|
783
|
-
body: JSON.stringify({ column, ...options }),
|
|
784
|
-
});
|
|
785
|
-
const statistics = await res.json();
|
|
786
|
-
return statistics;
|
|
787
|
-
},
|
|
788
|
-
|
|
789
|
-
/**
|
|
790
|
-
* Get list of latest raw clicks
|
|
791
|
-
* API reference: https://developers.short.io/reference/postdomaindomainidlast_clicks
|
|
792
|
-
* @param domainId Domain id
|
|
793
|
-
* @param options Options for the request
|
|
794
|
-
* @returns List of latest raw clicks
|
|
795
|
-
*/
|
|
796
|
-
getLastClicks: async (
|
|
797
|
-
domainId: Domain["id"],
|
|
798
|
-
options?: GetLastClicksOptions,
|
|
799
|
-
): Promise<LastClicksRes | ErrorResBody> => {
|
|
800
|
-
const res = await fetch(`${this.baseStatisticsUrl}/domain/${domainId}/last_clicks`, {
|
|
801
|
-
method: "POST",
|
|
802
|
-
headers: {
|
|
803
|
-
"Content-Type": "application/json",
|
|
804
|
-
Authorization: this.apiKey,
|
|
805
|
-
},
|
|
806
|
-
body: JSON.stringify(options),
|
|
807
|
-
});
|
|
808
|
-
const statistics = await res.json();
|
|
809
|
-
return statistics;
|
|
810
|
-
},
|
|
811
|
-
|
|
812
|
-
/**
|
|
813
|
-
* Clear statistics of specified domain
|
|
814
|
-
* API reference: https://developers.short.io/reference/deletedomaindomainidstatistics
|
|
815
|
-
* @param domainId Domain id
|
|
816
|
-
* @returns Empty response body
|
|
817
|
-
*/
|
|
818
|
-
clear: async (domainId: Domain["id"]): Promise<SuccessResBody | ErrorResBody> => {
|
|
819
|
-
const res = await fetch(`${this.baseStatisticsUrl}/domain/${domainId}/statistics`, {
|
|
820
|
-
method: "DELETE",
|
|
821
|
-
headers: {
|
|
822
|
-
"Content-Type": "application/json",
|
|
823
|
-
Authorization: this.apiKey,
|
|
824
|
-
},
|
|
825
|
-
});
|
|
826
|
-
const deleteRes = await res.json();
|
|
827
|
-
return deleteRes;
|
|
828
|
-
},
|
|
829
|
-
};
|
|
830
|
-
}
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
export * from "./types.gen";
|
|
3
|
+
export * from "./sdk.gen";
|