@mimik/api-helper

1.1.3 • Public • Published

Functions

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

Setup the API to be use for a service

getAPIFile(apiFilename, correlationId, options)Promise

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

setupServerFiles(apiFilename, controllersDirectory, buidDirectory, correlationId, options)Promise

Setup and validates files for the server

validateSecuritySchemes(apiDefinition, correlationId)

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

extractProperties(apiDefinition, controllersDirectory, buidDirectory, correlationId)

Extracts the properties from API definiton and creates a file binding the handler with the controller operations.

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.

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 customer 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 } },
  • overwite 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:@mimik/swagger-helper, module:ajv-formats, module:fs, module:jsonwebtoken, module:lodash

Param Type Description
setup object Object containing the apiFilename and the exisiting security schemes in the API definition.
registeredOperations object List of the operation to register for the API.
securityHandlers object List of the security handlers 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, the existing known security schemes and the defined 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`, `ApiKeySecurity`.

**Kind**: global function  
**Returns**: An array of the known 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. |

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.1.3
    3
    • latest

Version History

Package Sidebar

Install

npm i @mimik/api-helper

Weekly Downloads

3

Version

1.1.3

License

MIT

Unpacked Size

51.4 kB

Total Files

11

Last publish

Collaborators

  • sasan.raisdana
  • miburger
  • hofachiang
  • mimik-npm-editor
  • mimikopensource