SDK Reference

SDK Reference

This document provides detailed information about the FluxLink JavaScript/TypeScript SDK.

Installation

npm install @fluxlink/client
# or
yarn add @fluxlink/client

Initialization

The FluxLink SDK requires initialization with your API key.

import FluxLink from "@fluxlink/client";
 
const fluxlink = new FluxLink({
  apiKey: "your-api-key",
  // Optional: specify a custom API URL if not using the default
  apiUrl: "https://your-fluxlink-api.com",
});

API Reference

Link Management

Create a Dynamic Link

async function createLink(config: LinkConfig): Promise<LinkResponse>;

Parameters:

LinkConfig object with the following properties:

PropertyTypeDescription
titlestringTitle of the link for management purposes
defaultUrlstringFallback URL if no platform match is found
androidLinkAndroidLinkConfigAndroid-specific configuration
iosLinkIOSLinkConfigiOS-specific configuration
desktopUrlstringOptional URL for desktop users
expirationDateDateOptional expiration date for the link
customParametersObjectOptional custom parameters for tracking

AndroidLinkConfig:

PropertyTypeDescription
urlstringDeep link URL (e.g., myapp://path)
appPackageNamestringAndroid app package name
minimumVersionstringOptional minimum app version
fallbackUrlstringOptional specific Android fallback URL

IOSLinkConfig:

PropertyTypeDescription
urlstringDeep link URL (e.g., myapp://path)
bundleIdstringiOS app bundle identifier
minimumVersionstringOptional minimum app version
fallbackUrlstringOptional specific iOS fallback URL

Returns:

LinkResponse object with the created link details, including a unique ID and URL.

Example:

const link = await fluxlink.createLink({
  title: "Product Link",
  defaultUrl: "https://example.com/fallback",
  androidLink: {
    url: "myapp://product/123",
    appPackageName: "com.example.myapp",
  },
  iosLink: {
    url: "myapp://product/123",
    bundleId: "com.example.myapp",
  },
});

Get a Link

async function getLink(linkId: string): Promise<LinkResponse>;

Parameters:

  • linkId: The ID of the link to retrieve

Returns:

LinkResponse object with the link details.

Example:

const link = await fluxlink.getLink("abc123");

List Links

async function listLinks(options?: ListOptions): Promise<LinkListResponse>;

Parameters:

  • options: Optional pagination and filtering options

Returns:

LinkListResponse object containing an array of links and pagination info.

Example:

const links = await fluxlink.listLinks({
  page: 1,
  limit: 10,
  sortBy: "createdAt",
  sortDirection: "desc",
});

Update a Link

async function updateLink(
  linkId: string,
  config: Partial<LinkConfig>
): Promise<LinkResponse>;

Parameters:

  • linkId: The ID of the link to update
  • config: Partial LinkConfig object with the fields to update

Returns:

LinkResponse object with the updated link details.

Example:

const updatedLink = await fluxlink.updateLink("abc123", {
  title: "Updated Title",
  androidLink: {
    minimumVersion: "2.0.0",
  },
});

Delete a Link

async function deleteLink(linkId: string): Promise<void>;

Parameters:

  • linkId: The ID of the link to delete

Example:

await fluxlink.deleteLink("abc123");

Analytics

Get Link Analytics

async function getLinkAnalytics(
  linkId: string,
  options?: AnalyticsOptions
): Promise<AnalyticsResponse>;

Parameters:

  • linkId: The ID of the link to get analytics for
  • options: Optional filtering options (date range, etc.)

Returns:

AnalyticsResponse object with click data and other analytics.

Example:

const analytics = await fluxlink.getLinkAnalytics("abc123", {
  startDate: new Date("2023-01-01"),
  endDate: new Date("2023-12-31"),
  timeBucket: "day",
});

Error Handling

The SDK throws specific errors that you can catch and handle:

try {
  const link = await fluxlink.createLink({
    /* ... */
  });
} catch (error) {
  if (error.name === "FluxLinkAuthError") {
    // Handle authentication errors
  } else if (error.name === "FluxLinkValidationError") {
    // Handle validation errors
  } else if (error.name === "FluxLinkNetworkError") {
    // Handle network errors
  } else {
    // Handle other errors
  }
}

TypeScript Types

The SDK provides type definitions for all parameters and responses:

interface FluxLinkConfig {
  apiKey: string;
  apiUrl?: string;
}
 
interface LinkConfig {
  title: string;
  defaultUrl: string;
  androidLink?: AndroidLinkConfig;
  iosLink?: IOSLinkConfig;
  desktopUrl?: string;
  expirationDate?: Date;
  customParameters?: Record<string, string>;
}
 
interface AndroidLinkConfig {
  url: string;
  appPackageName: string;
  minimumVersion?: string;
  fallbackUrl?: string;
}
 
interface IOSLinkConfig {
  url: string;
  bundleId: string;
  minimumVersion?: string;
  fallbackUrl?: string;
}
 
interface LinkResponse {
  id: string;
  url: string;
  title: string;
  defaultUrl: string;
  androidLink?: AndroidLinkConfig;
  iosLink?: IOSLinkConfig;
  desktopUrl?: string;
  expirationDate?: string;
  customParameters?: Record<string, string>;
  createdAt: string;
  updatedAt: string;
}