## Classes
spawnpoint

Agnostic JS framework that empowers devs to focus on quickly building apps, rather than focusing on application config, health-checks, application structure, or architecture to build a 12 factor app in Docker.

Spawnpoint can be configured to manage the entire application life-cycle or standalone as a utility library.

## Typedefs
callbackthis

Initializes framework to read the configFile, init config, Spawnpoint plugins, errorCodes and autoload folders. This also starts the application life-cycle so the app can stop gracefully.

## spawnpoint Agnostic JS framework that empowers devs to focus on quickly building apps, rather than focusing on application config, health-checks, application structure, or architecture to build a 12 factor app in Docker. Spawnpoint can be configured to manage the entire application life-cycle or standalone as a utility library. **Kind**: global class * [spawnpoint](#spawnpoint) * [new spawnpoint([configFile])](#new_spawnpoint_new) * [.recursiveList(dir, [exts])](#spawnpoint+recursiveList) ⇒ Array * [.random([length], [hashMethod])](#spawnpoint+random) ⇒ String * [.sample(items)](#spawnpoint+sample) ⇒ \* * [.roundRobin(items)](#spawnpoint+roundRobin) ⇒ roundRobin * [.getAndLock(items)](#spawnpoint+getAndLock) ⇒ roundRobin * [.omit(items, keysToOmit)](#spawnpoint+omit) ⇒ Object * [.isRoot()](#spawnpoint+isRoot) ⇒ Boolean * [.isSecure([uid], [gid])](#spawnpoint+isSecure) ⇒ Boolean * [.require(filePath)](#spawnpoint+require) * [.code(code, [data])](#spawnpoint+code) ⇒ Object * [.errorCode(code, [data])](#spawnpoint+errorCode) ⇒ Object * [.failCode(code, [data])](#spawnpoint+failCode) ⇒ Object * [.registerLimit(code, threshold, options, callback)](#spawnpoint+registerLimit) ⇒ this * [.debug()](#spawnpoint+debug) ⇒ this * [.info()](#spawnpoint+info) ⇒ this * [.log()](#spawnpoint+log) ⇒ this * [.warn()](#spawnpoint+warn) ⇒ this * [.error()](#spawnpoint+error) ⇒ this * [.registerError(code, error)](#spawnpoint+registerError) ⇒ this * [.registerErrors(errors)](#spawnpoint+registerErrors) ⇒ this * [.maskErrorToCode(error)](#spawnpoint+maskErrorToCode) ⇒ errorCode \| false ### new spawnpoint([configFile]) Creates new instance of spawnpoint | Param | Type | Default | Description | | --- | --- | --- | --- | | [configFile] | string | "/config/app.json" | Sets the JSON file spawnpoint uses to setup the framework. | ### spawnpoint.recursiveList(dir, [exts]) ⇒ Array Recursively list files in a directory by an optional file extension. NOTE: This is an event blocking sync method. **Kind**: instance method of [spawnpoint](#spawnpoint) **Returns**: Array - Absolute/full path of filenames found. | Param | Type | Description | | --- | --- | --- | | dir | String | Directory to list files from. | | [exts] | Array \| string | Optional list of file extensions to return. Defaults to .js files. Set to a falsy value to disable this filter. | ### spawnpoint.random([length], [hashMethod]) ⇒ String Utility: Create random string. **Kind**: instance method of [spawnpoint](#spawnpoint) **Returns**: String - Random string of characters. | Param | Type | Default | Description | | --- | --- | --- | --- | | [length] | Number | 16 | How long of a random string to create. | | [hashMethod] | String | | Which crypto hash method to use. | ### spawnpoint.sample(items) ⇒ \* Utility: get random element from `collection`. This is a copy of the lodash _.sample method. **Kind**: instance method of [spawnpoint](#spawnpoint) **Returns**: \* - Returns the random element. | Param | Type | Description | | --- | --- | --- | | items | Array \| Object | The collection to sample. | ### spawnpoint.roundRobin(items) ⇒ roundRobin Utility: Creates new `roundRobin` class with collection. **Kind**: instance method of [spawnpoint](#spawnpoint) **Returns**: roundRobin - Returns new instance of `roundRobin` class. | Param | Type | Description | | --- | --- | --- | | items | Array \| Object | The collection to sample. | ### spawnpoint.getAndLock(items) ⇒ roundRobin Utility: get random element from `collection` in an async lock. **Kind**: instance method of [spawnpoint](#spawnpoint) **Returns**: roundRobin - Returns new instance of `roundRobin` class. | Param | Type | Description | | --- | --- | --- | | items | Array \| Object | The collection to sample. | ### spawnpoint.omit(items, keysToOmit) ⇒ Object Utility: omit keys from an object. Similar to Lodash omit, but much faster. **Kind**: instance method of [spawnpoint](#spawnpoint) **Returns**: Object - Returns object with requested keys removed. | Param | Type | Description | | --- | --- | --- | | items | Object | The source object. | | keysToOmit | Array | Keys to omit from the object. | ### spawnpoint.isRoot() ⇒ Boolean Checks if the current application runtime is running as a root user/group. **Kind**: instance method of [spawnpoint](#spawnpoint) **Returns**: Boolean - When true: the application is running as a root user/group. ### spawnpoint.isSecure([uid], [gid]) ⇒ Boolean Checks if the current application runtime is running as a specific `uid` and/or `gid`. **Kind**: instance method of [spawnpoint](#spawnpoint) **Returns**: Boolean - When true: the application is running as the user/group. | Param | Type | Description | | --- | --- | --- | | [uid] | Number | Unix `uid` to check against. | | [gid] | Number | Unix `gid` to check against. When not set will match `uid`. | ### spawnpoint.require(filePath) Helper method that requires a file and hoists the current spawnpoint application reference. **Kind**: instance method of [spawnpoint](#spawnpoint) | Param | Type | Description | | --- | --- | --- | | filePath | String | File path to require. | ### spawnpoint.code(code, [data]) ⇒ Object Builds a Spawnpoint code object. Codes are used to create a link between a human readable message and a computer readable string. Example: `file.not_found` -> "The requested file was not found." **Kind**: instance method of [spawnpoint](#spawnpoint) **Returns**: Object - Code Object with a `message` with the computer readable message and the `code` matching the input code. | Param | Type | Description | | --- | --- | --- | | code | String | computer readable string code. | | [data] | Object | Object to extend the code Object with | ### spawnpoint.errorCode(code, [data]) ⇒ Object Spawnpoint code that wraps a Javascript `Error` as a hard application error. **Kind**: instance method of [spawnpoint](#spawnpoint) **Returns**: Object - Error Code Object with a `message` with the computer readable message and the `code` matching the input code. | Param | Type | Description | | --- | --- | --- | | code | String | computer readable string code. | | [data] | Object | Object to extend the code Object with | ### spawnpoint.failCode(code, [data]) ⇒ Object Spawnpoint code that wraps a Javascript `Error`, as a soft error. **Kind**: instance method of [spawnpoint](#spawnpoint) **Returns**: Object - Error Code Object with a `message` with the computer readable message and the `code` matching the input code. | Param | Type | Description | | --- | --- | --- | | code | String | computer readable string code. | | [data] | Object | Object to extend the code Object with | ### spawnpoint.registerLimit(code, threshold, options, callback) ⇒ this Error Monitoring, when enabled. This allows you to track how often an error occurs and issue a callback once that threadhold is met. **Kind**: instance method of [spawnpoint](#spawnpoint) | Param | Type | Description | | --- | --- | --- | | code | String | Spawnpoint code to match against | | threshold | Number | Number of occurrences required to trigger callback. | | options | Object | Extra limit options | | [options.time] | Object | When set, number of milliseconds that the threshold cools down. On each tick this will reduce bv one until it reaches zero. | | callback | Callback | Triggered when threshold is met. | ### spawnpoint.debug() ⇒ this Console.log wrapper that only triggers with when `config.debug` is enabled. **Kind**: instance method of [spawnpoint](#spawnpoint) **Params**: \* [args..] Arguments to be passed to logging. ### spawnpoint.info() ⇒ this Console.log wrapper that adds an INFO tag and timestamp to the log. **Kind**: instance method of [spawnpoint](#spawnpoint) **Params**: String\|Object\|Array\|Number [args..] Arguments to be passed to logging. ### spawnpoint.log() ⇒ this Console.log wrapper that adds an LOG tag and timestamp to the log. **Kind**: instance method of [spawnpoint](#spawnpoint) **Params**: String\|Object\|Array\|Number [args..] Arguments to be passed to logging. ### spawnpoint.warn() ⇒ this Console.error` wrapper that adds an WARN tag and timestamp to the log. This prints to STDERR. **Kind**: instance method of [spawnpoint](#spawnpoint) **Params**: String\|Object\|Array\|Number [args..] Arguments to be passed to logging. ### spawnpoint.error() ⇒ this Console.error` wrapper that adds an ERROR tag and timestamp to the log. This prints to STDERR. **Kind**: instance method of [spawnpoint](#spawnpoint) **Params**: String\|Object\|Array\|Number [args..] Arguments to be passed to logging. ### spawnpoint.registerError(code, error) ⇒ this Registers multiple custom Errors to a specific errorCode. This helps wrap errors into a singular errorCode system. **Kind**: instance method of [spawnpoint](#spawnpoint) | Param | Type | Description | | --- | --- | --- | | code | String | The errorCode human readable Spawnpoint code. | | error | Error | Instance of the error to map to.. | ### spawnpoint.registerErrors(errors) ⇒ this Registers multiple custom Errors to a specific errorCode, using the `registerError` method. **Kind**: instance method of [spawnpoint](#spawnpoint) | Param | Type | Description | | --- | --- | --- | | errors | Object | Errors being registered. Each index/key is the errorCode string that the custom Error represents. The Value must be an uninitialized instance of the error. | ### spawnpoint.maskErrorToCode(error) ⇒ errorCode \| false Checks for Spawnpoint wrapped code, errorCode, or failCode when a potential error map is found (and previously registered). This method is useful as middleware to your application error handling so that you don't have to have the server reply with a generic error. **Kind**: instance method of [spawnpoint](#spawnpoint) **Returns**: errorCode \| false - Returns Spawnpoint mapped code, errorCode, or failCode or false when no mapped error was found. | Param | Type | Description | | --- | --- | --- | | error | Error | Error to check for mapped error. | ## callback ⇒ this Initializes framework to read the `configFile`, init config, Spawnpoint plugins, errorCodes and autoload folders. This also starts the application life-cycle so the app can stop gracefully. **Kind**: global typedef