SDK Reference
This document provides detailed information about the FluxLink JavaScript/TypeScript SDK.
Installation
npm install @fluxlink/client
# or
yarn add @fluxlink/clientInitialization
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:
| Property | Type | Description |
|---|---|---|
title | string | Title of the link for management purposes |
defaultUrl | string | Fallback URL if no platform match is found |
androidLink | AndroidLinkConfig | Android-specific configuration |
iosLink | IOSLinkConfig | iOS-specific configuration |
desktopUrl | string | Optional URL for desktop users |
expirationDate | Date | Optional expiration date for the link |
customParameters | Object | Optional custom parameters for tracking |
AndroidLinkConfig:
| Property | Type | Description |
|---|---|---|
url | string | Deep link URL (e.g., myapp://path) |
appPackageName | string | Android app package name |
minimumVersion | string | Optional minimum app version |
fallbackUrl | string | Optional specific Android fallback URL |
IOSLinkConfig:
| Property | Type | Description |
|---|---|---|
url | string | Deep link URL (e.g., myapp://path) |
bundleId | string | iOS app bundle identifier |
minimumVersion | string | Optional minimum app version |
fallbackUrl | string | Optional 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 updateconfig: 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 foroptions: 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;
}