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

@mimik/api-helper

v1.0.2

Published

helper for openAPI backend and mimik service

Downloads

16

Readme

Functions

apiSetup(setup, registeredOperations, securityHandlers, extraFormats, config, correlationId) ⇒ Promise

Setup the API to be use for a service

Kind: global function
Returns: Promise - . &fulfil {object} The API file itself.
Category: async
Throws:

  • Promise An error is thrown if the initiatilization failed.

By default System and Admin security are automatically registered

Requires: module:@mimik/response-helper, module:@mimik/sumologic-winston-logger, module:@mimik/swagger-helper, module:ajv-formats, module:fs, module:jsonwebtoken, module:lodash

| Param | Type | Description | | --- | --- | --- | | setup | object | Object containing the apiFilename and the exisiting securitySchemes in the API definition. | | registeredOperations | object | List of the operation to register for the API. | | securityHandlers | object | List of the securityHandlers to add for the service. | | extraFormats | object | list of the formats to add for validatng properties. | | config | object | Configuration of the service. | | correlationId | UUID.<string> | CorrelationId when logging activites. |

getAPIFile(apiFilename, correlationId, options) ⇒ Promise

Gets the API file from swaggerhub and store it in the give PATH location.

Kind: global function
Returns: Promise - . &fulfil {object} The API file itself.
Category: async
Throws:

  • Promise An error is thrown if the apiFilename resolution generates an error or the request to the API provider fails or the file connot 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 for access private API on swaggerhub, can be optional if the API is accessible publically"
}

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

| Param | Type | Description |
| --- | --- | --- |
| apiFilename | <code>PATH.&lt;string&gt;</code> | Name of the file where the API file will be stored. |
| correlationId | <code>UUID.&lt;string&gt;</code> | CorrelationId when logging activites. |
| options | <code>object</code> | Options associated with the call. Use to pass `metrics` to `rpRetry` and `apiInfo` to access the api file in the api provider. |

<a name="setupServerFiles"></a>

## setupServerFiles(apiFilename, controllersDirectory, buidDirectory, correlationId, options) ⇒ <code>Promise</code>
Setup and validates files for the server

**Kind**: global function  
**Returns**: <code>Promise</code> - .
&fulfil {object} The API file, the API filename, and the existing know security schemes.  
**Category**: async  
**Throws**:

- <code>Promise</code> An error is thrown for many reasons assocated with getAPIFile or validateSecuritySchemes or extractProperties.

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

| Param | Type | Description |
| --- | --- | --- |
| apiFilename | <code>PATH.&lt;string&gt;</code> | Name of the file where the API file will be stored. |
| controllersDirectory | <code>PATH.&lt;string&gt;</code> | Directory to find the controller files. |
| buidDirectory | <code>PATH.&lt;string&gt;</code> | = Directory where the register file will be stored. |
| correlationId | <code>UUID.&lt;string&gt;</code> | CorrelationId when logging activites. |
| options | <code>object</code> | Options associated with the call. Use to pass `metrics` to `rpRetry` and `apiKey`` to access private API. |

<a name="validateSecuritySchemes"></a>

## validateSecuritySchemes(apiDefinition, correlationId) ⇒
Validates the known SecuritySchemes: `SystemSecurity`, `AdminSecurity`, `UserSecurity`, `PeerSecurity`.

**Kind**: global function  
**Returns**: An array of the know securitySchemes that are in the API definition.  
**Category**: sync  
**Throws**:

- An error is thrown for the first validation fails.

**Requires**: <code>module:@mimik/sumologic-winston-logger</code>, <code>module:@mimik/response-helper</code>  

| Param | Type | Description |
| --- | --- | --- |
| apiDefinition | <code>object</code> | JSON object containing the API definition. |
| correlationId | <code>UUID.&lt;string&gt;</code> | CorrelationId when logging activites. |

<a name="extractProperties"></a>

## extractProperties(apiDefinition, controllersDirectory, buidDirectory, correlationId) ⇒
Extracts the properties from API definiton and creates a file binding the handler with the controller operations.

**Kind**: global function  
**Returns**: null  
**Category**: sync  
**Throws**:

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

**Requires**: <code>module:@mimik/response-helper</code>, <code>module:@mimik/sumologic-winston-logger</code>, <code>module:fs</code>  

| Param | Type | Description |
| --- | --- | --- |
| apiDefinition | <code>object</code> | JSON object containing the API definition. |
| controllersDirectory | <code>PATH.&lt;string&gt;</code> | Directory to find the controller files. |
| buidDirectory | <code>PATH.&lt;string&gt;</code> | = Directory where the register file will be stored. |
| correlationId | <code>UUID.&lt;string&gt;</code> | CorrelationId when logging activites. |