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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@mimik/api-helper

v3.0.4

Published

helper for openAPI backend and mimik service

Downloads

549

Readme

Modules

Typedefs

api-helper

Example

import apiHelper from '@mimik/api-helper';
// or
import { apiSetup, securityLib, getAPIFile, validateSecuritySchemes, extractProperties, setupServerFiles } from '@mimik/api-helper';

api-helper~apiSetup(setup, registeredOperations, securityHandlers, extraFormats, config, correlationId) ⇒ Promise.<object>

Set up the API to be used for a service

Kind: inner method of api-helper
Returns: Promise.<object> - The initialized OpenAPIBackend instance.
Category: async
Throws:

  • Error Rejects with an error if the initialization failed.

The following scheme names are reserved: SystemSecurity, AdminSecurity, UserSecurity, PeerSecurity, ApiKeySecurity. The following security schemes can be defaulted: SystemSecurity, AdminSecurity, UserSecurity, ApiKeySecurity. The secOptions in the options property passed when using init allows the following operations:

  • introduce a custom security scheme, in this case secOptions contains: { newSecurityScheme: {function}newSecurityHandler },
  • disable a security scheme that is defined in the swagger API, in this case secOptions contains: { securitySchemeToDisable: { {boolean}notEnabled: true } },
  • overwrite an existing security scheme, in this case secOptions contains: { securitySchemeToOverwrite: {function}newSecurityHandler }. If the secOptions is not present either to introduce, disable or overwrite a security scheme that is present in the swagger API file an error is generated. If the secOptions contains unused security schemes, an error is generated.

The default formats for validation are: date, time, date-time, byte, uuid, uri, email, ipv4, ipv6, semver, ip.

Requires: module:@mimik/response-helper, module:@mimik/sumologic-winston-logger, module:openapi-backend

| Param | Type | Description | | --- | --- | --- | | setup | object | Object containing the apiFilename and the existing security schemes in the API definition. | | setup.apiFilename | PATH | Path to the resolved API definition file. | | setup.existingSecuritySchemes | Array.<string> | Known security scheme names present in the API definition. | | setup.definedSecuritySchemes | Array.<string> | All security scheme names defined in the API definition. | | registeredOperations | object | Map of operationId to handler function to register for the API. | | securityHandlers | object | Map of security scheme name to handler object to add for the service. | | extraFormats | object | Map of format name to format definition for validating properties. Each entry is either an empty object (to use a built-in ajv-formats format) or an object with type and validate properties (to define a custom format). | | config | object | Configuration of the service. | | correlationId | UUID | CorrelationId when logging activities. |

api-helper~getAPIFile(apiFilename, correlationId, options) ⇒ Promise.<object>

Gets and resolves the API definition, loading from local file, Bitbucket, or SwaggerHub, and stores it in the given PATH location.

Kind: inner method of api-helper
Returns: Promise.<object> - The API file itself.
Category: async
Throws:

  • Error Rejects with an error if the apiFilename resolution generates an error or the request to the API provider fails or the file cannot be saved.

apiInfo options has the following format:

{
   "provider": "provider of the api file, can be `swaggerhub` or `bitbucket`",
   "apiBasicAuth": {
     "username": "username for bitbucket",
     "password": "password for bitbucket"
   },
   "apiApiKey": "apiKey to access private API on swaggerhub, can be optional if the API is accessible publicly"
}

Requires: module:@mimik/request-retry, module:@mimik/response-helper, module:@mimik/sumologic-winston-logger, module:fs, module:js-yaml, module:path

| Param | Type | Description | | --- | --- | --- | | apiFilename | PATH | Name of the file where the API file will be stored. | | correlationId | UUID | CorrelationId when logging activities. | | options | object | Options associated with the call. Use to pass metrics to rpRetry and apiInfo to access the api file in the api provider. |

api-helper~setupServerFiles(apiFilename, controllersDirectory, buildDirectory, correlationId, options) ⇒ Promise.<object>

Sets up and validates files for the server

Kind: inner method of api-helper
Returns: Promise.<object> - The API file, the API filename, the existing known security schemes and the defined security schemes.
Category: async
Throws:

  • Error Rejects with an error for many reasons associated with getAPIFile or validateSecuritySchemes or extractProperties.

Requires: module:@mimik/request-retry, module:@mimik/response-helper, module:@mimik/sumologic-winston-logger, module:fs, module:js-yaml, module:path

| Param | Type | Description | | --- | --- | --- | | apiFilename | PATH | Name of the file where the API file will be stored. | | controllersDirectory | PATH | Directory to find the controller files. | | buildDirectory | PATH | Directory where the register file will be stored. | | correlationId | UUID | CorrelationId when logging activities. | | options | object | Options associated with the call. Use to pass metrics to rpRetry and apiKey to access private API. |

api-helper~securityLib(config) ⇒ object

Implements the security flows for the API.

Kind: inner method of api-helper
Returns: object - An object containing SystemSecurity, AdminSecurity, UserSecurity, and ApiKeySecurity handlers.

This function is used to set up the following security handlers for the API:

  • SystemSecurity - used for system-to-system operations, validates client credentials tokens.
  • AdminSecurity - used for admin operations, validates admin/subAdmin client credentials tokens.
  • UserSecurity - used for user operations, validates implicit flow tokens.
  • ApiKeySecurity - used for API key authenticated operations, validates API keys from headers. The security handlers are used to validate the tokens and scopes for the API operations.
    Category: sync
    Requires: module:@mimik/swagger-helper, module:jsonwebtoken

| Param | Type | Description | | --- | --- | --- | | config | object | Configuration of the service. |

api-helper~validateSecuritySchemes(apiDefinition, correlationId) ⇒ Array.<string>

Validates the known SecuritySchemes: SystemSecurity, AdminSecurity, UserSecurity, PeerSecurity, ApiKeySecurity.

Kind: inner method of api-helper
Returns: Array.<string> - An array of the known securitySchemes that are in the API definition.
Category: sync
Throws:

  • Error An error is thrown if a validation fails.

Requires: module:@mimik/sumologic-winston-logger, module:@mimik/response-helper

| Param | Type | Description | | --- | --- | --- | | apiDefinition | object | JSON object containing the API definition. | | correlationId | UUID | CorrelationId when logging activities. |

api-helper~extractProperties(apiDefinition, controllersDirectory, buildDirectory, correlationId) ⇒ void

Extracts the properties from API definition and creates a register.js file in the build directory binding the handler with the controller operations.

Kind: inner method of api-helper
Category: sync
Throws:

  • Error An error is thrown for many reasons, like operationId does not exist in controllers, controller does not exist...

Requires: module:@mimik/response-helper, module:@mimik/sumologic-winston-logger, module:fs

| Param | Type | Description | | --- | --- | --- | | apiDefinition | object | JSON object containing the API definition. | | controllersDirectory | PATH | Directory to find the controller files. | | buildDirectory | PATH | Directory where the register file will be stored. | | correlationId | UUID | CorrelationId when logging activities. |

UUID : string

UUID string in RFC 4122 format.

Kind: global typedef

PATH : string

File system path string.

Kind: global typedef