npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

directorydockclient

v1.1.9

Published

Client library for the DirecoryDock API

Downloads

503

Readme

DirectoryDock API Client library

DirectoryDockClient is a powerful API client for seamless interaction with the DirectoryDock service. It provides an easy-to-use interface for managing and retrieving directory entries.

Features

  • Fetch paginated entries
  • Retrieve specific entries by slug
  • Filter entries based on custom criteria
  • Get available filterable fields
  • Built-in error handling for robust integration
  • Strong TypeScript support with detailed type definitions

Installation

To install the directorydockclient npm package, run:

npm install directorydockclient

Usage

TypeScript

import DirectoryDockClient from "directorydockclient";
import { TransformedEntry, FilterableField } from "directorydockclient";

const client = new DirectoryDockClient("your_directorydock_api_key_here");

// Fetching Entries
async function fetchEntries() {
  const {
    entries,
    totalEntries,
  }: { entries: TransformedEntry[]; totalEntries: number } =
    await client.getEntries(1, 10);

  console.log(`Fetched ${entries.length} entries out of ${totalEntries}`);
}

// Getting a Single Entry
async function getSingleEntry() {
  try {
    const entry: TransformedEntry = await client.getEntry("example-entry-slug");

    console.log("Entry:", entry);
  } catch (error) {
    console.error("Entry not found:", error.message);
  }
}

// Filtering Entries
async function filterEntries() {
  const filter = { Name: "Example Entry Name" };

  const filteredEntries: TransformedEntry[] = await client.getEntriesByFilter(
    filter
  );

  console.log("Filtered entries:", filteredEntries);
}

// Getting Filterable Fields
async function getFilterableFields() {
  const filterableFields: FilterableField[] = await client.getFilters();

  console.log("Filterable fields:", filterableFields);
}

// Getting Filters
async function getFilters() {
  const filters: Filter[] = await client.getFilters();
  console.log("Available filters:", filters);
}

// Getting Categories
async function getCategories() {
  const categories: Category[] = await client.getCategories();
  console.log("Available categories:", categories);
}

// Getting Submit Fields
async function getSubmitFields() {
  const submitFields: SubmitField[] = await client.getSubmitFields();
  console.log("Available submit fields:", submitFields);
}

JavaScript

const DirectoryDockClient = require("directorydockclient").default;
const client = new DirectoryDockClient("your_directorydock_api_key_here");

// Fetching Entries
async function fetchEntries() {
  const { entries, totalEntries } = await client.getEntries(1, 10);

  console.log(`Fetched ${entries.length} entries out of ${totalEntries}`);
}

// Getting a Single Entry
async function getSingleEntry() {
  try {
    const entry = await client.getEntry("example-entry-slug");

    console.log("Entry:", entry);
  } catch (error) {
    console.error("Entry not found:", error.message);
  }
}

// Filtering Entries
async function filterEntries() {
  const filter = { Name: "Example Entry Name" };

  const filteredEntries = await client.getEntriesByFilter(filter);

  console.log("Filtered entries:", filteredEntries);
}

// Getting Filterable Fields
async function getFilterableFields() {
  const filterableFields = await client.getFilters();

  console.log("Filterable fields:", filterableFields);
}

// Getting Filters
async function getFilters() {
  const filters: Filter[] = await client.getFilters();
  console.log("Available filters:", filters);
}

// Getting Categories
async function getCategories() {
  const categories: Category[] = await client.getCategories();
  console.log("Available categories:", categories);
}

// Getting Submit Fields
async function getSubmitFields() {
  const submitFields: SubmitField[] = await client.getSubmitFields();
  console.log("Available submit fields:", submitFields);
}

Type Definitions

The library includes several TypeScript interfaces and types to provide strong typing support:

  • EntryData: Represents the structure of each field in an entry.
  • BaseEntry: Defines the basic structure of an entry.
  • TransformedEntry: An enhanced version of BaseEntry with direct access to entry properties.
  • GetEntriesResponse: The structure of the response when fetching entries.
  • FilterableField: Represents a field that can be used for filtering.
  • BaseData: The structure of the raw data returned by the API.

These types are exported and can be imported from the library for use in your TypeScript projects.

Project Structure

The project uses a modular structure with separate files for each type definition:

src/
├── DirectoryDockClient.ts
└── types/
    ├── BaseData.ts
    ├── BaseEntry.ts
    ├── Category.ts
    ├── EntryData.ts
    ├── FilterableField.ts
    ├── GetEntriesResponse.ts
    └── TransformedEntry.ts

This structure makes it easier to maintain and extend the library.

Error Handling

The client includes built-in error handling for common issues:

  • Invalid API key
  • Entry not found
  • Network errors

Always wrap your API calls in try-catch blocks to handle potential errors gracefully.

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any bugs, features, or improvements. When contributing, please maintain the current file structure, with separate files for each type definition in the src/types directory.

License

This project is licensed under the MIT License.

Support

For additional assistance or information, please open an issue on the GitHub repository or reach out directly on X (formerly Twitter) @Stellan79.

Streamline your directory management with DirectoryDockClient. Get started today!