@linktwin/client
v1.0.0
Published
TypeScript client for the LinkTwin link management API (links, deep links, QR codes, collections, pixels, domains and analytics).
Maintainers
Readme
@linktwin/client
A small, typed TypeScript/JavaScript client for the
LinkTwin link-management API. It powers
@linktwin/mcp and
@linktwin/cli, and you can use
it directly.
Install
npm install @linktwin/clientRequires Node.js 18+ (uses the global fetch).
Usage
import { LinkTwinClient, LinkTwinApiError } from "@linktwin/client";
const client = new LinkTwinClient({
apiKey: process.env.LINKTWIN_API_KEY, // or set LINKTWIN_API_KEY
baseUrl: "https://linktw.in", // optional; or LINKTWIN_BASE_URL
});
try {
const link = await client.links.create({
url: "https://example.com",
custom: "spring-sale",
geotarget: [{ location: "Canada", link: "https://example.ca" }],
});
console.log(link.shorturl);
const list = await client.links.list({ search: "sale", limit: 20 });
const stats = await client.stats.link(link.id);
} catch (err) {
if (err instanceof LinkTwinApiError) {
console.error(err.message, err.status, err.isRateLimited);
}
}API surface
client.links · client.collections · client.domains · client.pixels ·
client.qr · client.stats · client.account
Every method returns the parsed JSON response. Any unsuccessful call (transport
error, non-JSON body, auth failure, rate limit, or an API error flag other
than 0) throws a LinkTwinApiError with status, code, isAuthError,
isRateLimited and isLimitReached helpers. Rate-limited requests are retried
once with a bounded wait.
License
MIT
