New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@trayio/connector-utils

Package Overview
Dependencies
Maintainers
11
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@trayio/connector-utils

Common utility functions used in connectors.

  • 0.2.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
41
increased by95.24%
Maintainers
11
Weekly downloads
 
Created
Source

Connector-utils

Common utility functions used in connectors.

Installation

The connector-utils package will be inherently included as part of a new connector scaffold (as part of the Trayio yeoman generator).

When adding the package as part of an existing connector, first ensure you have the appropriate .npmrc present, then in your terminal, run:

npm i @trayio/connector-utils --save

Basic Usage

To require the package, require as @trayio/connector-utils:

const utils = require('@trayio/connector-utils')

This will give full access to the library. We can then reference utilities such as UserInputError by using:

utils.error.UserInputError('custom error message')

A better usage alternative is to use destructuring, as in the example:

const { UserInputError } = require('@trayio/connector-utils/lib/errors')

A full breakdown of available utilities is included in the documentation below.

Please be sure to add any discovered issues or improvement recommendations to the Issues tab of this repo.

Documentation

Classes

GenericErrorError

Class representing the base error for all connector errors

UserInputErrorGenericError

Class representing a UserInputError

ConnectorErrorGenericError

Class representing a ConnectorError

ApiErrorGenericError

Class representing a ConnectorError

OAuthRefreshGenericError

Class representing a ConnectorError

NoTriggerErrorGenericError

Class representing a ConnectorError

Functions

mustachedDDL(object, text, value, isInteger)

Takes value paths as mustached values and returns correct DDL outputs. A custom flag is in place to allow for keeping integer types for the value key if required, as mustaching will convert an integer to string.

DDL(object, textPath, valuePath)

Takes value paths as explicit strings and returns correct DDL outputs.

deepMapKeys(collection, iteratee)

Maps object keys and formats according to specified casing.

userInputErrorRejection(message, body)

Return a User Input Error with option to pass a body argument. The use case for this over the custom Error class is to pass a body to provide error context.

connectorErrorRejection(message, body)

Return a Connector Error with option to pass a body argument. The use case for this over the custom Error class is to pass a body to provide error context.

apiErrorRejection(message, body)

Return a API Error with option to pass a body argument. The use case for this over the custom Error class is to pass a body to provide error context.

oauthErrorRejection(message, body)

Return a oAuth Error with option to pass a body argument. The use case for this over the custom Error class is to pass a body to provide error context.

noTriggerErrorRejection(message, body)

Return a No Trigger Error with option to pass a body argument. The use case for this over the custom Error class is to pass a body to provide error context.

lookup(message, [step_settings])

Generates a lookup object for DDL operations.

removeEmptyObjects(collection)

Recursively removes empty objects, arrays and strings from a collection. It's important to note that this method will remove objects if they become empty as a result of the nested key/value containing an empty object (the same goes for arrays).

validatePaginationRange(value, validation)

Helper for validating user pagination input for a given range.

GenericError ⇐ Error

Class representing the base error for all connector errors

Kind: global class
Extends: Error

UserInputError ⇐ GenericError

Class representing a UserInputError

Kind: global class
Extends: GenericError

new UserInputError(message, ...errorArgs)

Custom error to throw for issues concerning User Input.

ParamTypeDescription
messageStringCustom error message to return.
...errorArgsanyError args allowing for extra parameters native to the normal Error class.

ConnectorError ⇐ GenericError

Class representing a ConnectorError

Kind: global class
Extends: GenericError

new ConnectorError(message, ...errorArgs)

Custom error to throw for issues concerning the Connector.

ParamTypeDescription
messageStringCustom error message to return.
...errorArgsanyError args allowing for extra parameters native to the normal Error class.

ApiError ⇐ GenericError

Class representing a ConnectorError

Kind: global class
Extends: GenericError

new ApiError(message, ...errorArgs)

Custom error to throw for issues concerning the Api;;.

ParamTypeDescription
messageStringCustom error message to return.
...errorArgsanyError args allowing for extra parameters native to the normal Error class.

OAuthRefresh ⇐ GenericError

Class representing a ConnectorError

Kind: global class
Extends: GenericError

new OAuthRefresh(message, ...errorArgs)

Custom error to throw when an oAuth token has expired.

ParamTypeDescription
messageStringCustom error message to return.
...errorArgsanyError args allowing for extra parameters native to the normal Error class.

NoTriggerError ⇐ GenericError

Class representing a ConnectorError

Kind: global class
Extends: GenericError

new NoTriggerError(message, ...errorArgs)

Custom error to throw for issues when a trigger request is ignored.

ParamTypeDescription
messageStringCustom error message to return.
...errorArgsanyError args allowing for extra parameters native to the normal Error class.

mustachedDDL(arr, text, value, isInteger)

Takes value paths as mustached values and returns correct DDL outputs. A custom flag is in place to allow for keeping integer types for the value key if required, as mustaching will convert an integer to string. If there does not exist a path, the whole result will not return.

Kind: global function

ParamTypeDescription
arrObjectAn array of objects with keys to iterate over and format.
textStringThe path for the required text value.
valueStringThe path for the required value, value.
isIntegerBooleanFlag for whether or not the value field needs to an integer rather than a string.

DDL(arr, textPath, valuePath, options)

Takes value paths as explicit strings and returns correct DDL outputs. If a text value does not exist, the DDL falls back to using the 'value' path.

Kind: global function

ParamTypeDescription
arrObjectAn array of objects with keys to iterate over and format.
textPathStringThe path for the required text value.
valuePathStringThe path fot the required value, value.
optionsStringOptions to provide to the DDL

deepMapKeys(collection, iteratee)

Maps object keys and formats according to specified casing.

Kind: global function

ParamTypeDescription
collectionObjectThe collection with keys to iterate over and format.
iterateefunctionThe format function used to format keys IE Lodash _.camelCase('some_string').

userInputErrorRejection(message, body)

Return a User Input Error with option to pass a body argument. The use case for this over the custom Error class is to pass a body to provide error context.

Kind: global function

ParamTypeDescription
messageStringThe error message to be returned.
bodyanyCustom body to be returned when providing more error context.

connectorErrorRejection(message, body)

Return a Connector Error with option to pass a body argument. The use case for this over the custom Error class is to pass a body to provide error context.

Kind: global function

ParamTypeDescription
messageStringThe error message to be returned.
bodyanyCustom body to be returned when providing more error context.

apiErrorRejection(message, body)

Return a API Error with option to pass a body argument. The use case for this over the custom Error class is to pass a body to provide error context.

Kind: global function

ParamTypeDescription
messageStringThe error message to be returned.
bodyanyCustom body to be returned when providing more error context.

oauthErrorRejection(message, body)

Return a oAuth Error with option to pass a body argument. The use case for this over the custom Error class is to pass a body to provide error context.

Kind: global function

ParamTypeDescription
messageStringThe error message to be returned.
bodyanyCustom body to be returned when providing more error context.

noTriggerErrorRejection(message, body)

Return a No Trigger Error with option to pass a body argument. The use case for this over the custom Error class is to pass a body to provide error context.

Kind: global function

ParamTypeDescription
messageStringThe error message to be returned.
bodyanyCustom body to be returned when providing more error context.

lookup(message, [step_settings])

Generates a lookup object for DDL operations.

Kind: global function

ParamTypeDefaultDescription
messageStringThe DDL operation that is run when the lookup is executed.
[step_settings]Object{}The custom step settings for the lookup.

removeEmptyObjects(collection)

Recursively removes empty objects, arrays and strings from a collection. It's important to note that this method will remove objects if they become empty as a result of the nested key/value containing an empty object (the same goes for arrays).

Kind: global function

ParamTypeDescription
collectionObjectThe collection from which to remove empty objects.

validatePaginationRange(value, validation)

Helper for validating user pagination input for a given range.

Kind: global function

ParamTypeDescription
valueInteger | StringThe value specified by user input.
validationObjectValues relating specifically to the validation requirements.
validation.minRangeInteger | StringThe minimum range specified by the API.
validation.maxRangeInteger | StringThe maximum range specified by the API.
validation.inputNameStringThe name of the input the range is associated with.

Example

validatePaginationRange(50, {
	minRange: 1,
	maxRange: 100,
	inputName: 'page size',
});
// no error thrown as pagination is within range

validatePaginationRange(101, {
	minRange: 1,
	maxRange: 100,
	inputName: 'page size',
});
// will throw a UserInputError as the pageSize is outside the range
// Error message returned: 'The page size must be between 1 - 100.'

Keywords

FAQs

Package last updated on 25 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc