Skip to content

tryclnk/sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Clnk URL Shortener SDK

A TypeScript SDK for interacting with the Clnk URL shortener GraphQL API.

Features

  • 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

Installation

npm install @clnk/sdk
# or
yarn add @clnk/sdk

Quick Start

import { 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);

Authentication

Login

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);

Register

const registerData = await sdk.register({
  name: 'John Doe',
  email: 'user@example.com',
  password: 'password123'
});

Refresh Token

const refreshData = await sdk.refreshToken('your-refresh-token');
// The SDK automatically saves the new access token

Set Access Token Manually

sdk.setAccessToken('your-access-token');

URL Management

Create URL

// 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'
});

Update URL

const updatedUrl = await sdk.updateUrl({
  id: 'url-id',
  url: 'https://example.com/updated-url',
  shortUrl: 'new-custom-code'
});

Delete URL

const deleted = await sdk.deleteUrl('url-id');

Get URL

// By ID
const url1 = await sdk.getUrl({ id: 'url-id' });

// By code
const url2 = await sdk.getUrl({ code: 'abc123' });

Get URLs

// 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 }
});

Get All URLs (Admin)

const allUrls = await sdk.getAllUrls({
  pagination: { page: 1, limit: 50 }
});

QR Code Generation

// Default size (300x300)
const qrUrl1 = sdk.generateQRCodeUrl('https://clnk.to/abc123');

// Custom size
const qrUrl2 = sdk.generateQRCodeUrl('https://clnk.to/abc123', 500);

API Key Management

// Generate new API key
const apiKey = await sdk.generateApiKey();

User Management

// Get current user info
const currentUser = await sdk.getCurrentUser();

Important Notes

  1. API Key is required when initializing the SDK
  2. Access token can be provided during initialization or set later with setAccessToken()
  3. The SDK automatically manages the access token after login or token refresh

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published