@short.io/client-node 2.1.1 → 3.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 +744 -35
- package/dist/example.d.ts +0 -0
- package/dist/example.js +1 -0
- package/dist/example.js.map +1 -0
- package/dist/generated/client/client.d.ts +2 -0
- package/dist/generated/client/client.gen.d.ts +2 -0
- package/dist/generated/client/client.gen.js +225 -0
- package/dist/generated/client/client.gen.js.map +1 -0
- package/dist/generated/client/client.js +141 -0
- package/dist/generated/client/client.js.map +1 -0
- package/dist/generated/client/index.d.ts +8 -0
- package/dist/generated/client/index.js +6 -0
- package/dist/generated/client/index.js.map +1 -0
- package/dist/generated/client/types.d.ts +70 -0
- package/dist/generated/client/types.gen.d.ts +68 -0
- package/dist/generated/client/types.gen.js +2 -0
- package/dist/generated/client/types.gen.js.map +1 -0
- package/dist/generated/client/types.js +2 -0
- package/dist/generated/client/types.js.map +1 -0
- package/dist/generated/client/utils.d.ts +42 -0
- package/dist/generated/client/utils.gen.d.ts +30 -0
- package/dist/generated/client/utils.gen.js +224 -0
- package/dist/generated/client/utils.gen.js.map +1 -0
- package/dist/generated/client/utils.js +277 -0
- package/dist/generated/client/utils.js.map +1 -0
- package/dist/generated/client.gen.d.ts +4 -0
- package/dist/generated/client.gen.js +3 -0
- package/dist/generated/client.gen.js.map +1 -0
- package/dist/generated/core/auth.d.ts +8 -0
- package/dist/generated/core/auth.gen.d.ts +8 -0
- package/dist/generated/core/auth.gen.js +14 -0
- package/dist/generated/core/auth.gen.js.map +1 -0
- package/dist/generated/core/auth.js +14 -0
- package/dist/generated/core/auth.js.map +1 -0
- package/dist/generated/core/bodySerializer.d.ts +17 -0
- package/dist/generated/core/bodySerializer.gen.d.ts +21 -0
- package/dist/generated/core/bodySerializer.gen.js +57 -0
- package/dist/generated/core/bodySerializer.gen.js.map +1 -0
- package/dist/generated/core/bodySerializer.js +54 -0
- package/dist/generated/core/bodySerializer.js.map +1 -0
- package/dist/generated/core/params.d.ts +23 -0
- package/dist/generated/core/params.gen.d.ts +26 -0
- package/dist/generated/core/params.gen.js +100 -0
- package/dist/generated/core/params.gen.js.map +1 -0
- package/dist/generated/core/params.js +88 -0
- package/dist/generated/core/params.js.map +1 -0
- package/dist/generated/core/pathSerializer.d.ts +30 -0
- package/dist/generated/core/pathSerializer.gen.d.ts +30 -0
- package/dist/generated/core/pathSerializer.gen.js +114 -0
- package/dist/generated/core/pathSerializer.gen.js.map +1 -0
- package/dist/generated/core/pathSerializer.js +114 -0
- package/dist/generated/core/pathSerializer.js.map +1 -0
- package/dist/generated/core/queryKeySerializer.gen.d.ts +6 -0
- package/dist/generated/core/queryKeySerializer.gen.js +84 -0
- package/dist/generated/core/queryKeySerializer.gen.js.map +1 -0
- package/dist/generated/core/serverSentEvents.gen.d.ts +23 -0
- package/dist/generated/core/serverSentEvents.gen.js +131 -0
- package/dist/generated/core/serverSentEvents.gen.js.map +1 -0
- package/dist/generated/core/types.d.ts +32 -0
- package/dist/generated/core/types.gen.d.ts +32 -0
- package/dist/generated/core/types.gen.js +2 -0
- package/dist/generated/core/types.gen.js.map +1 -0
- package/dist/generated/core/types.js +2 -0
- package/dist/generated/core/types.js.map +1 -0
- package/dist/generated/core/utils.gen.d.ts +19 -0
- package/dist/generated/core/utils.gen.js +84 -0
- package/dist/generated/core/utils.gen.js.map +1 -0
- package/dist/generated/index.d.ts +2 -0
- package/dist/generated/index.js +2 -0
- package/dist/generated/index.js.map +1 -0
- package/dist/generated/sdk.gen.d.ts +48 -0
- package/dist/generated/sdk.gen.js +300 -0
- package/dist/generated/sdk.gen.js.map +1 -0
- package/dist/generated/types.gen.d.ts +1707 -0
- package/dist/generated/types.gen.js +2 -0
- package/dist/generated/types.gen.js.map +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +13 -2
- package/dist/index.js.map +1 -1
- package/package.json +12 -12
package/README.md
CHANGED
|
@@ -1,65 +1,774 @@
|
|
|
1
1
|
# Short.io Node.js SDK
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
This SDK contains methods for working with links and domains.
|
|
3
|
+
Official Node.js SDK for the [Short.io](https://short.io) URL shortening and link management API.
|
|
5
4
|
|
|
6
|
-
##
|
|
5
|
+
## Table of Contents
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
- [Features](#features)
|
|
8
|
+
- [Requirements](#requirements)
|
|
9
|
+
- [Installation](#installation)
|
|
10
|
+
- [Quick Start](#quick-start)
|
|
11
|
+
- [Usage Examples](#usage-examples)
|
|
12
|
+
- [Link Management](#link-management)
|
|
13
|
+
- [Domain Management](#domain-management)
|
|
14
|
+
- [Bulk Operations](#bulk-operations)
|
|
15
|
+
- [QR Codes](#qr-codes)
|
|
16
|
+
- [Geographic Targeting](#geographic-targeting)
|
|
17
|
+
- [Folders](#folders)
|
|
18
|
+
- [OpenGraph](#opengraph)
|
|
19
|
+
- [Permissions](#permissions)
|
|
20
|
+
- [API Reference](#api-reference)
|
|
21
|
+
- [Advanced Configuration](#advanced-configuration)
|
|
22
|
+
- [TypeScript Support](#typescript-support)
|
|
23
|
+
- [Rate Limits](#rate-limits)
|
|
24
|
+
- [Error Handling](#error-handling)
|
|
25
|
+
- [Support](#support)
|
|
26
|
+
- [License](#license)
|
|
9
27
|
|
|
10
|
-
##
|
|
28
|
+
## Features
|
|
11
29
|
|
|
12
|
-
|
|
30
|
+
- **Link Management** - Create, update, delete, duplicate, and archive short links
|
|
31
|
+
- **Domain Management** - Handle custom domains and their settings
|
|
32
|
+
- **QR Code Generation** - Generate QR codes for single links or in bulk
|
|
33
|
+
- **Bulk Operations** - Create, delete, or archive up to 1000 links at once
|
|
34
|
+
- **Geographic Targeting** - Set country and region-specific redirects
|
|
35
|
+
- **Link Analytics** - Get detailed link statistics and expand information
|
|
36
|
+
- **Folder Organization** - Organize links into folders
|
|
37
|
+
- **OpenGraph Control** - Customize link preview metadata
|
|
38
|
+
- **Permissions Management** - Control user access to links
|
|
39
|
+
- **Full TypeScript Support** - Comprehensive type definitions included
|
|
40
|
+
- **Modern ESM** - Built with ES modules
|
|
13
41
|
|
|
14
|
-
|
|
15
|
-
|
|
42
|
+
## Requirements
|
|
43
|
+
|
|
44
|
+
- Node.js 18.0.0 or higher
|
|
45
|
+
- npm or yarn package manager
|
|
46
|
+
|
|
47
|
+
## Installation
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
npm install @short.io/client-node
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Or with yarn:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
yarn add @short.io/client-node
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Quick Start
|
|
60
|
+
|
|
61
|
+
### 1. Get Your API Key
|
|
62
|
+
|
|
63
|
+
Get your API key from the Short.io dashboard: [Integrations & API](https://app.short.io/settings/integrations/api-key)
|
|
64
|
+
|
|
65
|
+
### 2. Initialize the SDK
|
|
66
|
+
|
|
67
|
+
```javascript
|
|
68
|
+
import { setApiKey } from "@short.io/client-node";
|
|
69
|
+
|
|
70
|
+
setApiKey("YOUR_API_KEY");
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Or using environment variables:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
export SHORT_IO_API_KEY="your-api-key"
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
```javascript
|
|
80
|
+
import { setApiKey } from "@short.io/client-node";
|
|
81
|
+
|
|
82
|
+
setApiKey(process.env.SHORT_IO_API_KEY);
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### 3. Create Your First Short Link
|
|
86
|
+
|
|
87
|
+
```javascript
|
|
88
|
+
import { createLink } from "@short.io/client-node";
|
|
89
|
+
|
|
90
|
+
const result = await createLink({
|
|
91
|
+
body: {
|
|
92
|
+
originalURL: "https://example.com/very-long-url",
|
|
93
|
+
domain: "your-domain.com",
|
|
94
|
+
path: "custom-path", // Optional
|
|
95
|
+
title: "My Link" // Optional
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
console.log("Short URL:", result.data.shortURL);
|
|
100
|
+
console.log("Link ID:", result.data.idString);
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Usage Examples
|
|
104
|
+
|
|
105
|
+
### Link Management
|
|
106
|
+
|
|
107
|
+
#### Create a Link
|
|
108
|
+
|
|
109
|
+
```javascript
|
|
110
|
+
import { createLink } from "@short.io/client-node";
|
|
111
|
+
|
|
112
|
+
const result = await createLink({
|
|
113
|
+
body: {
|
|
114
|
+
originalURL: "https://example.com",
|
|
115
|
+
domain: "your-domain.com",
|
|
116
|
+
path: "my-link", // Optional: custom path
|
|
117
|
+
title: "Example Link", // Optional: link title
|
|
118
|
+
tags: ["marketing"], // Optional: tags for organization
|
|
119
|
+
expiresAt: "2025-12-31", // Optional: expiration date
|
|
120
|
+
password: "secret123" // Optional: password protection
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
#### Get Link Information
|
|
126
|
+
|
|
127
|
+
```javascript
|
|
128
|
+
import { getLink, expandLink } from "@short.io/client-node";
|
|
129
|
+
|
|
130
|
+
// Get link by ID
|
|
131
|
+
const linkInfo = await getLink({
|
|
132
|
+
path: { linkId: "your-link-id" }
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
console.log("Original URL:", linkInfo.data.originalURL);
|
|
136
|
+
console.log("Clicks:", linkInfo.data.clicks);
|
|
137
|
+
|
|
138
|
+
// Get link by domain and path
|
|
139
|
+
const expanded = await expandLink({
|
|
140
|
+
query: {
|
|
141
|
+
domain: "your-domain.com",
|
|
142
|
+
path: "my-link"
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
#### Update a Link
|
|
148
|
+
|
|
149
|
+
```javascript
|
|
150
|
+
import { updateLink } from "@short.io/client-node";
|
|
151
|
+
|
|
152
|
+
const updated = await updateLink({
|
|
153
|
+
path: { linkId: "your-link-id" },
|
|
154
|
+
body: {
|
|
155
|
+
originalURL: "https://new-destination.com",
|
|
156
|
+
title: "Updated Title"
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
#### Delete a Link
|
|
162
|
+
|
|
163
|
+
```javascript
|
|
164
|
+
import { deleteLink } from "@short.io/client-node";
|
|
165
|
+
|
|
166
|
+
await deleteLink({
|
|
167
|
+
path: { link_id: "your-link-id" }
|
|
168
|
+
});
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
#### Duplicate a Link
|
|
172
|
+
|
|
173
|
+
```javascript
|
|
174
|
+
import { duplicateLink } from "@short.io/client-node";
|
|
175
|
+
|
|
176
|
+
const duplicate = await duplicateLink({
|
|
177
|
+
path: { linkId: "your-link-id" },
|
|
178
|
+
body: {
|
|
179
|
+
path: "new-custom-path" // Optional: specify new path
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
#### Archive/Unarchive Links
|
|
185
|
+
|
|
186
|
+
```javascript
|
|
187
|
+
import { archiveLink, unarchiveLink } from "@short.io/client-node";
|
|
188
|
+
|
|
189
|
+
// Archive a link
|
|
190
|
+
await archiveLink({
|
|
191
|
+
body: { link_id: "your-link-id" }
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
// Unarchive a link
|
|
195
|
+
await unarchiveLink({
|
|
196
|
+
body: { link_id: "your-link-id" }
|
|
197
|
+
});
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
#### List Links
|
|
201
|
+
|
|
202
|
+
```javascript
|
|
203
|
+
import { listLinks } from "@short.io/client-node";
|
|
204
|
+
|
|
205
|
+
const links = await listLinks({
|
|
206
|
+
query: {
|
|
207
|
+
domain_id: "your-domain-id",
|
|
208
|
+
limit: 50,
|
|
209
|
+
offset: 0
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
console.log("Total links:", links.data.length);
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### Domain Management
|
|
217
|
+
|
|
218
|
+
```javascript
|
|
219
|
+
import {
|
|
220
|
+
listDomains,
|
|
221
|
+
getDomain,
|
|
222
|
+
createDomain,
|
|
223
|
+
updateDomainSettings
|
|
224
|
+
} from "@short.io/client-node";
|
|
225
|
+
|
|
226
|
+
// List all domains
|
|
227
|
+
const domains = await listDomains();
|
|
228
|
+
console.log("Domains:", domains.data);
|
|
229
|
+
|
|
230
|
+
// Get specific domain
|
|
231
|
+
const domain = await getDomain({
|
|
232
|
+
path: { domainId: "your-domain-id" }
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
// Create a new domain
|
|
236
|
+
const newDomain = await createDomain({
|
|
237
|
+
body: {
|
|
238
|
+
hostname: "links.example.com"
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
// Update domain settings
|
|
243
|
+
await updateDomainSettings({
|
|
244
|
+
path: { domainId: "your-domain-id" },
|
|
245
|
+
body: {
|
|
246
|
+
hideReferer: true,
|
|
247
|
+
cloaking: false
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
### Bulk Operations
|
|
253
|
+
|
|
254
|
+
#### Create Multiple Links
|
|
255
|
+
|
|
256
|
+
```javascript
|
|
257
|
+
import { createLinksBulk } from "@short.io/client-node";
|
|
258
|
+
|
|
259
|
+
// Create up to 1000 links at once
|
|
260
|
+
const bulkResult = await createLinksBulk({
|
|
261
|
+
body: [
|
|
262
|
+
{ originalURL: "https://example1.com", domain: "your-domain.com" },
|
|
263
|
+
{ originalURL: "https://example2.com", domain: "your-domain.com", path: "custom" },
|
|
264
|
+
{ originalURL: "https://example3.com", domain: "your-domain.com", title: "Third Link" }
|
|
265
|
+
]
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
// Results array contains link objects or error objects
|
|
269
|
+
bulkResult.data.forEach((item, index) => {
|
|
270
|
+
if (item.shortURL) {
|
|
271
|
+
console.log(`Link ${index}: ${item.shortURL}`);
|
|
272
|
+
} else {
|
|
273
|
+
console.log(`Link ${index} failed:`, item.error);
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
#### Delete Multiple Links
|
|
279
|
+
|
|
280
|
+
```javascript
|
|
281
|
+
import { deleteLinksBulk } from "@short.io/client-node";
|
|
282
|
+
|
|
283
|
+
await deleteLinksBulk({
|
|
284
|
+
body: {
|
|
285
|
+
links: ["link-id-1", "link-id-2", "link-id-3"]
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
#### Archive Multiple Links
|
|
291
|
+
|
|
292
|
+
```javascript
|
|
293
|
+
import { archiveLinksBulk, unarchiveLinksBulk } from "@short.io/client-node";
|
|
294
|
+
|
|
295
|
+
// Archive multiple links
|
|
296
|
+
await archiveLinksBulk({
|
|
297
|
+
body: { links: ["link-id-1", "link-id-2"] }
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
// Unarchive multiple links
|
|
301
|
+
await unarchiveLinksBulk({
|
|
302
|
+
body: { links: ["link-id-1", "link-id-2"] }
|
|
303
|
+
});
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
#### Bulk Tagging
|
|
307
|
+
|
|
308
|
+
```javascript
|
|
309
|
+
import { addTagsBulk } from "@short.io/client-node";
|
|
310
|
+
|
|
311
|
+
await addTagsBulk({
|
|
312
|
+
body: {
|
|
313
|
+
links: ["link-id-1", "link-id-2"],
|
|
314
|
+
tag: "marketing-campaign"
|
|
315
|
+
}
|
|
316
|
+
});
|
|
16
317
|
```
|
|
17
318
|
|
|
18
|
-
|
|
319
|
+
### QR Codes
|
|
19
320
|
|
|
20
|
-
|
|
21
|
-
|
|
321
|
+
```javascript
|
|
322
|
+
import { generateQrCode, generateQrCodesBulk } from "@short.io/client-node";
|
|
22
323
|
|
|
23
|
-
|
|
324
|
+
// Generate QR code for a single link
|
|
325
|
+
const qrCode = await generateQrCode({
|
|
326
|
+
path: { linkIdString: "your-link-id" },
|
|
327
|
+
body: {
|
|
328
|
+
size: 300,
|
|
329
|
+
format: "png" // or "svg"
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
// Bulk QR code generation (rate limited: 1 request per minute)
|
|
334
|
+
const bulkQr = await generateQrCodesBulk({
|
|
335
|
+
body: {
|
|
336
|
+
links: ["link-id-1", "link-id-2"],
|
|
337
|
+
size: 200,
|
|
338
|
+
format: "svg"
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
### Geographic Targeting
|
|
344
|
+
|
|
345
|
+
#### Country Targeting
|
|
346
|
+
|
|
347
|
+
```javascript
|
|
348
|
+
import {
|
|
349
|
+
createLinkCountry,
|
|
350
|
+
getLinkCountries,
|
|
351
|
+
deleteLinkCountry,
|
|
352
|
+
createLinkCountriesBulk
|
|
353
|
+
} from "@short.io/client-node";
|
|
354
|
+
|
|
355
|
+
// Set country-specific redirect
|
|
356
|
+
await createLinkCountry({
|
|
357
|
+
path: { linkId: "your-link-id" },
|
|
358
|
+
body: {
|
|
359
|
+
country: "US",
|
|
360
|
+
url: "https://us-specific-page.com"
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
// Get all country redirects for a link
|
|
365
|
+
const countries = await getLinkCountries({
|
|
366
|
+
path: { linkId: "your-link-id" }
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
// Remove country targeting
|
|
370
|
+
await deleteLinkCountry({
|
|
371
|
+
path: {
|
|
372
|
+
linkId: "your-link-id",
|
|
373
|
+
country: "US"
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
// Bulk country targeting
|
|
378
|
+
await createLinkCountriesBulk({
|
|
379
|
+
path: { linkId: "your-link-id" },
|
|
380
|
+
body: [
|
|
381
|
+
{ country: "US", url: "https://us.example.com" },
|
|
382
|
+
{ country: "UK", url: "https://uk.example.com" },
|
|
383
|
+
{ country: "DE", url: "https://de.example.com" }
|
|
384
|
+
]
|
|
385
|
+
});
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
#### Region Targeting
|
|
389
|
+
|
|
390
|
+
```javascript
|
|
391
|
+
import {
|
|
392
|
+
createLinkRegion,
|
|
393
|
+
getLinkRegions,
|
|
394
|
+
getRegionsByCountry,
|
|
395
|
+
createLinkRegionsBulk
|
|
396
|
+
} from "@short.io/client-node";
|
|
397
|
+
|
|
398
|
+
// Get available regions for a country
|
|
399
|
+
const regions = await getRegionsByCountry({
|
|
400
|
+
path: { country: "US" }
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
// Set region-specific redirect
|
|
404
|
+
await createLinkRegion({
|
|
405
|
+
path: { linkId: "your-link-id" },
|
|
406
|
+
body: {
|
|
407
|
+
country: "US",
|
|
408
|
+
region: "CA", // California
|
|
409
|
+
url: "https://california.example.com"
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
// Get all region redirects for a link
|
|
414
|
+
const linkRegions = await getLinkRegions({
|
|
415
|
+
path: { linkId: "your-link-id" }
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
// Bulk region targeting
|
|
419
|
+
await createLinkRegionsBulk({
|
|
420
|
+
path: { linkId: "your-link-id" },
|
|
421
|
+
body: [
|
|
422
|
+
{ country: "US", region: "CA", url: "https://ca.example.com" },
|
|
423
|
+
{ country: "US", region: "NY", url: "https://ny.example.com" }
|
|
424
|
+
]
|
|
425
|
+
});
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
### Folders
|
|
429
|
+
|
|
430
|
+
```javascript
|
|
431
|
+
import {
|
|
432
|
+
listFolders,
|
|
433
|
+
getFolder,
|
|
434
|
+
createFolder
|
|
435
|
+
} from "@short.io/client-node";
|
|
436
|
+
|
|
437
|
+
// List all folders for a domain
|
|
438
|
+
const folders = await listFolders({
|
|
439
|
+
path: { domainId: "your-domain-id" }
|
|
440
|
+
});
|
|
441
|
+
|
|
442
|
+
// Get specific folder
|
|
443
|
+
const folder = await getFolder({
|
|
444
|
+
path: {
|
|
445
|
+
domainId: "your-domain-id",
|
|
446
|
+
folderId: "your-folder-id"
|
|
447
|
+
}
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
// Create a new folder
|
|
451
|
+
const newFolder = await createFolder({
|
|
452
|
+
body: {
|
|
453
|
+
domainId: "your-domain-id",
|
|
454
|
+
name: "Marketing Links"
|
|
455
|
+
}
|
|
456
|
+
});
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
### OpenGraph
|
|
460
|
+
|
|
461
|
+
```javascript
|
|
462
|
+
import {
|
|
463
|
+
getLinkOpengraph,
|
|
464
|
+
updateLinkOpengraph
|
|
465
|
+
} from "@short.io/client-node";
|
|
466
|
+
|
|
467
|
+
// Get OpenGraph properties
|
|
468
|
+
const og = await getLinkOpengraph({
|
|
469
|
+
path: {
|
|
470
|
+
domainId: "your-domain-id",
|
|
471
|
+
linkId: "your-link-id"
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
// Set OpenGraph properties
|
|
476
|
+
await updateLinkOpengraph({
|
|
477
|
+
path: {
|
|
478
|
+
domainId: "your-domain-id",
|
|
479
|
+
linkId: "your-link-id"
|
|
480
|
+
},
|
|
481
|
+
body: {
|
|
482
|
+
title: "Custom Title",
|
|
483
|
+
description: "Custom description for social sharing",
|
|
484
|
+
image: "https://example.com/image.png"
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
### Permissions
|
|
490
|
+
|
|
491
|
+
```javascript
|
|
492
|
+
import {
|
|
493
|
+
getLinkPermissions,
|
|
494
|
+
addLinkPermission,
|
|
495
|
+
deleteLinkPermission
|
|
496
|
+
} from "@short.io/client-node";
|
|
497
|
+
|
|
498
|
+
// Get link permissions
|
|
499
|
+
const permissions = await getLinkPermissions({
|
|
500
|
+
path: {
|
|
501
|
+
domainId: "your-domain-id",
|
|
502
|
+
linkId: "your-link-id"
|
|
503
|
+
}
|
|
504
|
+
});
|
|
505
|
+
|
|
506
|
+
// Add user permission
|
|
507
|
+
await addLinkPermission({
|
|
508
|
+
path: {
|
|
509
|
+
domainId: "your-domain-id",
|
|
510
|
+
linkId: "your-link-id",
|
|
511
|
+
userId: "user-id"
|
|
512
|
+
},
|
|
513
|
+
body: {
|
|
514
|
+
permission: "read" // or "write"
|
|
515
|
+
}
|
|
516
|
+
});
|
|
517
|
+
|
|
518
|
+
// Remove user permission
|
|
519
|
+
await deleteLinkPermission({
|
|
520
|
+
path: {
|
|
521
|
+
domainId: "your-domain-id",
|
|
522
|
+
linkId: "your-link-id",
|
|
523
|
+
userId: "user-id"
|
|
524
|
+
}
|
|
525
|
+
});
|
|
526
|
+
```
|
|
527
|
+
|
|
528
|
+
## API Reference
|
|
529
|
+
|
|
530
|
+
### Link Operations
|
|
531
|
+
|
|
532
|
+
| Function | Description | Rate Limit |
|
|
533
|
+
|----------|-------------|------------|
|
|
534
|
+
| `createLink` | Create a new short link | 50/s |
|
|
535
|
+
| `listLinks` | List all links for a domain | - |
|
|
536
|
+
| `getLink` | Get link info by ID | 20/s |
|
|
537
|
+
| `updateLink` | Update an existing link | 20/s |
|
|
538
|
+
| `deleteLink` | Delete a link | 20/s |
|
|
539
|
+
| `expandLink` | Get link info by domain and path | 20/s |
|
|
540
|
+
| `getLinkByOriginalUrl` | Get link by original URL (deprecated) | 20/s |
|
|
541
|
+
| `getLinksByUrl` | Get all links with same original URL | - |
|
|
542
|
+
| `duplicateLink` | Duplicate an existing link | 50/s |
|
|
543
|
+
| `archiveLink` | Archive a link | - |
|
|
544
|
+
| `unarchiveLink` | Unarchive a link | - |
|
|
545
|
+
| `createLinkPublic` | Create link using public API key | 50/s |
|
|
546
|
+
| `createLinkSimple` | Create link (GET method) | 50/s |
|
|
547
|
+
| `createExampleLinks` | Generate example links | 5/10s |
|
|
548
|
+
|
|
549
|
+
### Bulk Operations
|
|
550
|
+
|
|
551
|
+
| Function | Description | Rate Limit |
|
|
552
|
+
|----------|-------------|------------|
|
|
553
|
+
| `createLinksBulk` | Create up to 1000 links | 5/10s |
|
|
554
|
+
| `deleteLinksBulk` | Delete multiple links | 1/s |
|
|
555
|
+
| `archiveLinksBulk` | Archive multiple links | - |
|
|
556
|
+
| `unarchiveLinksBulk` | Unarchive multiple links | - |
|
|
557
|
+
| `addTagsBulk` | Add tag to multiple links | - |
|
|
558
|
+
|
|
559
|
+
### Domain Operations
|
|
560
|
+
|
|
561
|
+
| Function | Description |
|
|
562
|
+
|----------|-------------|
|
|
563
|
+
| `listDomains` | List all domains |
|
|
564
|
+
| `getDomain` | Get domain details |
|
|
565
|
+
| `createDomain` | Create a new domain |
|
|
566
|
+
| `updateDomainSettings` | Update domain settings |
|
|
567
|
+
|
|
568
|
+
### QR Code Operations
|
|
569
|
+
|
|
570
|
+
| Function | Description | Rate Limit |
|
|
571
|
+
|----------|-------------|------------|
|
|
572
|
+
| `generateQrCode` | Generate QR code for a link | - |
|
|
573
|
+
| `generateQrCodesBulk` | Generate QR codes in bulk | 1/min |
|
|
574
|
+
|
|
575
|
+
### Geographic Targeting
|
|
576
|
+
|
|
577
|
+
| Function | Description |
|
|
578
|
+
|----------|-------------|
|
|
579
|
+
| `getLinkCountries` | Get country redirects |
|
|
580
|
+
| `createLinkCountry` | Set country redirect |
|
|
581
|
+
| `createLinkCountriesBulk` | Set multiple country redirects |
|
|
582
|
+
| `deleteLinkCountry` | Remove country redirect |
|
|
583
|
+
| `getLinkRegions` | Get region redirects |
|
|
584
|
+
| `createLinkRegion` | Set region redirect |
|
|
585
|
+
| `createLinkRegionsBulk` | Set multiple region redirects |
|
|
586
|
+
| `deleteLinkRegion` | Remove region redirect |
|
|
587
|
+
| `getRegionsByCountry` | List available regions |
|
|
588
|
+
|
|
589
|
+
### Folder Operations
|
|
590
|
+
|
|
591
|
+
| Function | Description |
|
|
592
|
+
|----------|-------------|
|
|
593
|
+
| `listFolders` | List folders for a domain |
|
|
594
|
+
| `getFolder` | Get folder details |
|
|
595
|
+
| `createFolder` | Create a new folder |
|
|
596
|
+
|
|
597
|
+
### OpenGraph Operations
|
|
598
|
+
|
|
599
|
+
| Function | Description |
|
|
600
|
+
|----------|-------------|
|
|
601
|
+
| `getLinkOpengraph` | Get OpenGraph properties |
|
|
602
|
+
| `updateLinkOpengraph` | Set OpenGraph properties |
|
|
603
|
+
|
|
604
|
+
### Permission Operations
|
|
605
|
+
|
|
606
|
+
| Function | Description |
|
|
607
|
+
|----------|-------------|
|
|
608
|
+
| `getLinkPermissions` | Get link permissions |
|
|
609
|
+
| `addLinkPermission` | Add user permission |
|
|
610
|
+
| `deleteLinkPermission` | Remove user permission |
|
|
611
|
+
|
|
612
|
+
## Advanced Configuration
|
|
613
|
+
|
|
614
|
+
### Custom Client Configuration
|
|
615
|
+
|
|
616
|
+
```javascript
|
|
24
617
|
import { client } from "@short.io/client-node";
|
|
25
618
|
|
|
26
619
|
client.setConfig({
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
620
|
+
baseUrl: "https://api.short.io",
|
|
621
|
+
headers: {
|
|
622
|
+
"User-Agent": "MyApp/1.0.0",
|
|
623
|
+
"authorization": "your-api-key"
|
|
624
|
+
}
|
|
31
625
|
});
|
|
32
626
|
```
|
|
33
627
|
|
|
34
|
-
|
|
628
|
+
### Using a Custom Client Instance
|
|
35
629
|
|
|
36
|
-
|
|
630
|
+
```javascript
|
|
631
|
+
import { createClient } from "@short.io/client-node";
|
|
632
|
+
import { createLink } from "@short.io/client-node";
|
|
37
633
|
|
|
38
|
-
|
|
634
|
+
const customClient = createClient({
|
|
635
|
+
baseUrl: "https://api.short.io",
|
|
636
|
+
headers: {
|
|
637
|
+
authorization: "your-api-key"
|
|
638
|
+
}
|
|
639
|
+
});
|
|
640
|
+
|
|
641
|
+
const result = await createLink({
|
|
642
|
+
client: customClient,
|
|
643
|
+
body: {
|
|
644
|
+
originalURL: "https://example.com",
|
|
645
|
+
domain: "your-domain.com"
|
|
646
|
+
}
|
|
647
|
+
});
|
|
648
|
+
```
|
|
649
|
+
|
|
650
|
+
## TypeScript Support
|
|
651
|
+
|
|
652
|
+
The SDK provides comprehensive TypeScript definitions for all operations:
|
|
653
|
+
|
|
654
|
+
```typescript
|
|
39
655
|
import {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
656
|
+
CreateLinkData,
|
|
657
|
+
CreateLinkResponse,
|
|
658
|
+
ListLinksResponse,
|
|
659
|
+
type Options
|
|
44
660
|
} from "@short.io/client-node";
|
|
661
|
+
|
|
662
|
+
// Typed request
|
|
663
|
+
const linkData: CreateLinkData = {
|
|
664
|
+
body: {
|
|
665
|
+
originalURL: "https://example.com",
|
|
666
|
+
domain: "your-domain.com",
|
|
667
|
+
path: "typed-link"
|
|
668
|
+
}
|
|
669
|
+
};
|
|
670
|
+
|
|
671
|
+
// Typed response
|
|
672
|
+
const result: CreateLinkResponse = await createLink(linkData);
|
|
673
|
+
|
|
674
|
+
if (result.data) {
|
|
675
|
+
console.log(result.data.shortURL); // TypeScript knows this is a string
|
|
676
|
+
console.log(result.data.idString); // TypeScript knows all available properties
|
|
677
|
+
}
|
|
45
678
|
```
|
|
46
679
|
|
|
47
|
-
|
|
680
|
+
### Response Types
|
|
48
681
|
|
|
49
|
-
|
|
50
|
-
|
|
682
|
+
All functions return a response object with the following structure:
|
|
683
|
+
|
|
684
|
+
```typescript
|
|
685
|
+
interface Response<T> {
|
|
686
|
+
data?: T; // Response data on success
|
|
687
|
+
error?: unknown; // Error details on failure
|
|
688
|
+
response: Response; // Raw fetch Response object
|
|
689
|
+
}
|
|
51
690
|
```
|
|
52
691
|
|
|
53
|
-
|
|
692
|
+
## Rate Limits
|
|
693
|
+
|
|
694
|
+
| Endpoint Category | Rate Limit |
|
|
695
|
+
|-------------------|------------|
|
|
696
|
+
| Link Creation | 50 requests/second |
|
|
697
|
+
| Link Updates/Deletes | 20 requests/second |
|
|
698
|
+
| Link Info | 20 requests/second |
|
|
699
|
+
| Bulk Operations | 5 requests per 10 seconds |
|
|
700
|
+
| Bulk Delete | 1 request/second |
|
|
701
|
+
| QR Bulk Generation | 1 request/minute |
|
|
702
|
+
| Public API | 50 requests/second |
|
|
703
|
+
|
|
704
|
+
## Error Handling
|
|
705
|
+
|
|
706
|
+
```javascript
|
|
707
|
+
import { createLink } from "@short.io/client-node";
|
|
54
708
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
path: "lnk_abc123_abcde12345,
|
|
61
|
-
},
|
|
709
|
+
const result = await createLink({
|
|
710
|
+
body: {
|
|
711
|
+
originalURL: "https://example.com",
|
|
712
|
+
domain: "your-domain.com"
|
|
713
|
+
}
|
|
62
714
|
});
|
|
715
|
+
|
|
716
|
+
if (result.error) {
|
|
717
|
+
// Handle specific error codes
|
|
718
|
+
switch (result.response.status) {
|
|
719
|
+
case 400:
|
|
720
|
+
console.error("Bad request - check your parameters");
|
|
721
|
+
break;
|
|
722
|
+
case 401:
|
|
723
|
+
console.error("Unauthorized - check your API key");
|
|
724
|
+
break;
|
|
725
|
+
case 403:
|
|
726
|
+
console.error("Forbidden - insufficient permissions");
|
|
727
|
+
break;
|
|
728
|
+
case 404:
|
|
729
|
+
console.error("Not found - resource doesn't exist");
|
|
730
|
+
break;
|
|
731
|
+
case 409:
|
|
732
|
+
console.error("Conflict - link with this path already exists");
|
|
733
|
+
break;
|
|
734
|
+
case 429:
|
|
735
|
+
console.error("Rate limit exceeded - slow down requests");
|
|
736
|
+
break;
|
|
737
|
+
default:
|
|
738
|
+
console.error("Unexpected error:", result.error);
|
|
739
|
+
}
|
|
740
|
+
} else {
|
|
741
|
+
console.log("Success:", result.data.shortURL);
|
|
742
|
+
}
|
|
63
743
|
```
|
|
64
744
|
|
|
65
|
-
|
|
745
|
+
### Using ThrowOnError
|
|
746
|
+
|
|
747
|
+
```typescript
|
|
748
|
+
import { createLink } from "@short.io/client-node";
|
|
749
|
+
|
|
750
|
+
try {
|
|
751
|
+
const result = await createLink({
|
|
752
|
+
throwOnError: true,
|
|
753
|
+
body: {
|
|
754
|
+
originalURL: "https://example.com",
|
|
755
|
+
domain: "your-domain.com"
|
|
756
|
+
}
|
|
757
|
+
});
|
|
758
|
+
|
|
759
|
+
console.log("Success:", result.data.shortURL);
|
|
760
|
+
} catch (error) {
|
|
761
|
+
console.error("Request failed:", error);
|
|
762
|
+
}
|
|
763
|
+
```
|
|
764
|
+
|
|
765
|
+
## Support
|
|
766
|
+
|
|
767
|
+
- **API Documentation**: [https://developers.short.io](https://developers.short.io)
|
|
768
|
+
- **API Reference**: [https://developers.short.io/reference](https://developers.short.io/reference)
|
|
769
|
+
- **Issues**: [https://github.com/Short-io/client-node/issues](https://github.com/Short-io/client-node/issues)
|
|
770
|
+
- **Dashboard**: [https://app.short.io](https://app.short.io)
|
|
771
|
+
|
|
772
|
+
## License
|
|
773
|
+
|
|
774
|
+
FSL (Functional Source License)
|