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

api-key-service

v1.0.8

Published

A wrapper for the api key service https://apikeys.wbsoftwaresolutions.com

Downloads

8

Readme

Api Key Service

api-key-service provides a class called ApiKeyService that allows you to interact with an Api key service. It offers the following functionality:

  • Generate Api Key: You can generate a new Api key with arbitrary properties and values.
  • Update Api Key: You can update an existing Api key by modifying its properties.
  • Validate Api Key: You can validate an Api key by checking the values of its properties.
  • Get all Api Keys: You can retrieve all Api keys stored in the service.
  • Delete Api Key: You can delete an Api key from the service.

API Documentation

Installation

First, install the api-key-service package using npm:

$ npm install api-key-service

After you have it installed you need to get an api key from the Api key service

Below are examples that demonstrate the usage of the ApiKeyService class

const { ApiKeyService } = require("api-key-service");

async function someFunction() {
  const apiKeyService = new ApiKeyService("your-api-key");

  // Generate an Api Key
  const initialProperties = {
    enabled: false,
    isAdmin: true,
    ip: "127.0.0.1",
    five: 5
  };

  const key = await apiKeyService.generateApiKey(initialProperties);

  const { apiKey } = key;
  console.log("Generated Api Key:", key);

  // Update an Api Key
  const updatedProperties = {
    enabled: true,
    isAdmin: false,
    ip: "localhost",
    five: 5
  };

  const updatedKey = await apiKeyService.updateApiKey(apiKey, updatedProperties);

  console.log("Updated Api Key:", updatedKey);

  // Validate an Api Key
  const propertiesToValidate = {isAdmin: true, ip: "127.0.0.1", five: 4};

  const validationResult = await apiKeyService.validate(apiKey, propertiesToValidate);
  console.log("Validation Result:", validationResult);

  // Get all Api Keys
  const allKeys = await apiKeyService.getApiKeys();
  console.log("All Api Keys:", allKeys);

  // Delete an Api Key
  const deletedKey = await apiKeyService.deleteApiKey(apiKey);
  console.log("Deleted Api Key:", deletedKey);
}

Example output

Please note that the enabled property is set to true by default unless specified otherwise. If the enabled property is explicitly set to false, the apiKeyService.validate method will always return { valid: false }

Generated Api Key: {
  enabled: false,
  isAdmin: true,
  ip: '127.0.0.1',
  five: 5,
  apiKey: 'someRandomKey'
}
Updated Api Key: {
  enabled: true,
  isAdmin: false,
  ip: 'localhost',
  five: 5,
  apiKey: 'someRandomKey'
}
Validation Result: { valid: false, invalid: { isAdmin: false, ip: 'localhost', five: 5 } }
All Api Keys: [
  {
    enabled: true,
    isAdmin: false,
    ip: 'localhost',
    five: 5,
    apiKey: 'someRandomKey'
  }
]
Deleted Api Key: {
  enabled: true,
  isAdmin: false,
  ip: 'localhost',
  five: 5,
  apiKey: 'someRandomKey'
}

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT