A TypeScript SDK for interacting with the Clnk URL shortener GraphQL API.
- Create and manage short URLs
- Generate QR codes for short URLs
- Authentication (login, register, token refresh)
- API key management
- TypeScript support with full type definitions
npm install @clnk/sdk
# or
yarn add @clnk/sdkimport { ClnkSDK } from '@clnk/sdk';
// Initialize the SDK
const sdk = new ClnkSDK({
apiKey: 'your-api-key', // Required
accessToken: 'your-access-token' // Optional, can be set later with sdk.setAccessToken()
});
// Login
const auth = await sdk.login({
email: 'user@example.com',
password: 'password123'
});
// Create a short URL
const shortUrl = await sdk.createUrl({
url: 'https://example.com/very-long-url',
shorten: true // Let the API auto-generate a short code
});
// Generate a QR code URL
const qrCodeUrl = sdk.generateQRCodeUrl(shortUrl.shortUrl);const authData = await sdk.login({
email: 'user@example.com',
password: 'password123'
});
// The SDK automatically saves the access token for future requests
console.log(authData.accessToken);
console.log(authData.refreshToken);
console.log(authData.user);const registerData = await sdk.register({
name: 'John Doe',
email: 'user@example.com',
password: 'password123'
});const refreshData = await sdk.refreshToken('your-refresh-token');
// The SDK automatically saves the new access tokensdk.setAccessToken('your-access-token');// Auto-generated short code
const url1 = await sdk.createUrl({
url: 'https://example.com/long-url',
shorten: true
});
// Custom short code
const url2 = await sdk.createUrl({
url: 'https://example.com/long-url',
code: 'custom-code'
});
// With an image (for visual links)
const url3 = await sdk.createUrl({
url: 'https://example.com/long-url',
shorten: true,
image: 'https://example.com/image.jpg'
});const updatedUrl = await sdk.updateUrl({
id: 'url-id',
url: 'https://example.com/updated-url',
shortUrl: 'new-custom-code'
});const deleted = await sdk.deleteUrl('url-id');// By ID
const url1 = await sdk.getUrl({ id: 'url-id' });
// By code
const url2 = await sdk.getUrl({ code: 'abc123' });// Get user's URLs
const urlData = await sdk.getUrls({
pagination: { page: 1, limit: 10 }
});
// With filtering
const filteredUrls = await sdk.getUrls({
filter: {
url: 'example.com'
},
pagination: { page: 1, limit: 20 }
});const allUrls = await sdk.getAllUrls({
pagination: { page: 1, limit: 50 }
});// Default size (300x300)
const qrUrl1 = sdk.generateQRCodeUrl('https://clnk.to/abc123');
// Custom size
const qrUrl2 = sdk.generateQRCodeUrl('https://clnk.to/abc123', 500);// Generate new API key
const apiKey = await sdk.generateApiKey();// Get current user info
const currentUser = await sdk.getCurrentUser();- API Key is required when initializing the SDK
- Access token can be provided during initialization or set later with
setAccessToken() - The SDK automatically manages the access token after login or token refresh
MIT