Skip to content

@xtandard/links/import

Bulk import and export of links as CSV.

  • parseLinksCsv turns a CSV export from another shortener (or our own linksToCsv export) into CreateLinkInput rows for core.importLinks(tenant, rows, { dryRun, onConflict }). Row i of the result is data row i of the file, so import errors point at file rows.
  • linksToCsv exports links in the native format (round-trips).

Column maps are header-alias based and tolerant: headers are compared after lowercasing and dropping everything but letters and digits ("Long URL", "long_url" and "longUrl" all read as longurl), and unknown columns are ignored. Assumptions per format (vendor exports change; extra aliases are cheap — every map also accepts the API field names):

format destination slug / short link other
native url slug (+ domain) every column linksToCsv writes
bitly Destination URL, Long URL, long_url Custom Bitlink / custom_bitlinks, else Bitlink / Short link / link (path → slug) Title, Tags, Archived
dub Destination URL, url key, else Short link / shortLink (path → slug) domain, title, description, tags, externalId, expiresAt, archived, utm_*, ios, android
shlink Long URL, longUrl Short code, shortCode, else shortUrl domain, title, tags (|-separated), validUntil, maxVisits
kutt target address, else link / shortUrl domain, description, expire_in

Bitly’s dashboard export (paid plans) has Title, Bitlink, Custom Bitlink, Destination URL, Date created, Engagements; its API uses long_url, title, tags, custom_bitlinks. Dub’s dashboard export defaults to Short link, Destination URL, Clicks, Created at with optional columns named after its API (key, domain, title, tags, …). Shlink’s own importer and web-client export use Short code / Long URL / Title / Domain / Tags (shortCode, longUrl, …). Kutt has no first-party CSV export; the map follows its API’s link object (address, target, description, domain, expire_in).

Domains: foreign formats drop the source domain by default (bit.ly is not yours), so links land on the tenant’s default domain; pass keepDomains: true when migrating a branded domain you have registered, or domain to put every row on one domain. native keeps domains.

import { … } from "@xtandard/links/import";
Name Summary
detectLinksCsvFormat Guess the source format from a header row. Defaults to native.
linksToCsv Export links as CSV in the native format (every column re-imports; passwords are never exported). Tags are comma-joined.
normalizeHeader Normalize a header for alias matching: lowercase letters and digits only.
parseCsv Parse CSV text into rows of fields.
parseCsvRecords Parse CSV with a header row into records keyed by header. Blank lines are skipped; missing trailing fields read as "".
parseLinksCsv Parse a links CSV into CreateLinkInput rows.
stringifyCsv Serialize rows to CSV (\r\n line endings, trailing newline).
Name Summary
CsvParseError Thrown for malformed CSV (an unterminated quoted field).
Name Summary
LinksToCsvOptions Options for linksToCsv.
ParseCsvOptions Options for parseCsv.
ParseLinksCsvOptions Options for parseLinksCsv.
Name Summary
CsvValue A value stringifyCsv can write. null/undefined become empty fields.
LinksCsvFormat Supported source formats. auto picks one from the header row.
Name Summary
LINKS_CSV_FORMATS Every supported format.
NATIVE_CSV_COLUMNS The columns linksToCsv writes, in order.