Flyone Library

Introduction

Flyone is a TypeScript-based library for interacting with the Flyone API, providing seamless integration and functionality for link management.

Features

  • Create links
  • Update existing links
  • Delete links
  • Fetch all links or specific links by ID
  • Track clicks over time
  • Manage device-specific and country-specific targeting

Installation

Install the library via npm or yarn:

npm install flyone

or

yarn add flyone

Usage

Importing the Library

import { Flyone } from "flyone";

Initializing the Flyone Instance

const flyone = new Flyone({
  apiKey: "SavanaPoint Your-API-Key-Here",
  orgId: "Your-Organization-Id-Here",
});

Examples

Create a Short Link

const newLink = await flyone.createShortLink({
  originalUrl: "https://example.com",
  title: "My Example Link",
});
console.log("Created Link:", newLink);

Fetch All Links

const links = await flyone.getAllLinks();
console.log("All Links:", links);

Get a Link by ID

const link = await flyone.getLinkById("link-id-here");
console.log("Link Details:", link);

Update a Short Link

const updatedLink = await flyone.updateShortLink("link-id-here", {
  title: "Updated Title",
});
console.log("Updated Link:", updatedLink);

Delete a Short Link

await flyone.deleteShortLink("link-id-here");
console.log("Link deleted successfully.");

Track Clicks Over Time

const clicks = await flyone.getClicksOverTime("link-id-here");
console.log("Clicks Over Time:", clicks);

Remove a Device Target

await flyone.removeDevice("link-id-here", "device-id-here");
console.log("Device removed successfully.");

Remove a Country Target

await flyone.removeCountry("link-id-here", "country-id-here");
console.log("Country removed successfully.");

Error Handling

Errors are handled using a centralized mechanism. In case of an error, the library will throw an exception with a descriptive message. Below are the possible error messages and their corresponding HTTP status codes:

Status CodeMessageDescription
400Invalid request parametersThe request payload is invalid.
401UnauthorizedThe API key or organization ID is missing/invalid.
403ForbiddenYou do not have permission to perform this action.
404Resource not foundThe requested resource does not exist.
500Internal server errorAn unexpected error occurred on the server.
503Service unavailableThe service is temporarily unavailable.

Example Error Handling

try {
  await flyone.createShortLink({
    originalUrl: "https://example.com",
    title: "My Example Link",
  });
} catch (error) {
  console.error("Error creating link:", error.message);
}

Configuration Options

FlyoneConfig

PropertyTypeDescription
apiKeystringYour API key for authentication.
orgIdstringThe ID of your organization.

Contributing

Contributions are welcome! Please follow the guidelines below:

  1. Fork the repository.
  2. Create a new branch for your feature/fix.
  3. Commit your changes with clear commit messages.
  4. Submit a pull request.

License

This library is licensed under the MIT License. See the LICENSE file for details.