4.1.0 • Published 8 years ago

apigee-utils v4.1.0

Weekly downloads
24
License
MIT
Repository
github
Last release
8 years ago

apigee-utils

A set of utility functions to ease javascript development on the Apigee Edge api platform

Installation

npm i -S apigee-utils
yarn add apigee-utils

How to use?

The utilities can be imported directly by using the modular build or all of them directly.

import getBody from 'apigee-utils/getBody';
import {getBody} from 'apigee-utils';

Reference

getBody

This will get the post body from the request

Returns any The body of the request

getQueryParam

This will get a queryParam from the passed url string

Parameters

  • queryParamKey string The key for the queryParam
  • defaultValue string? The default value to return when nothing is available

Returns string? The value of the queryParam

getQueryParams

This will get a set of queryParams from the passed url string

Parameters

  • possibleQueryParams Array<string> An array containing possible queryparams
  • settings any Object containing the settings for getting the queryparams
    • settings.defaultValues The value to return when no value is found. The keys of the default values should be identical to the queryparam keys.

Returns {} An object containing values for the passed in queryparams

setQueryParam

This will set a query parameter to the provided value

Parameters

  • key string The key of the queryparam to set
  • value any The value to set the queryparam to

Returns void

setQueryParams

This will convert an object with key value pairs to query parameters

Parameters

  • queryParams {} An object containing key value pairs to be used as query parameters

Returns void

validateValues

This will validate a set of query parameters and will set a error variable in the apigee with an errorpayload variable which can be send down to the client It is advised to set up a raise on error policy which will return the payload when the error variable == true

Parameters

  • values {} The keys the values to get are stored with
  • settings any Object containing the settings for getting the variables
    • settings.validator The validator is an object containing functions which take a value and tests whether the value matches to required format returning true for a valid parameter and false for invalid. Or it can return a custom error message as a string. It is also possible to return mutliple error messages as an array of strings. The keys of the validator should be identical to the queryparam keys.
    • settings.prefix The prefix to use for the variables which will be used to set the potential error messages

Returns boolean A boolean indicating whether the query param were valid or not

createErrorObject

This will create the default error message

Parameters

  • key string The key of the query parameter
  • value any The value of the query parameter
  • message string The custom message to use

Returns {title: string, message: string, source: string} A default error object

setVariable

This will store a value in the Apigee flow

Parameters

  • key string The key the value should be stored in
  • value any The value to store
  • settings any Object containing the settings for setting the variable
    • settings.prefix A prefix which is used to store the value with

Returns void

setVariables

This will store a set of values in the Apigee flow

Parameters

  • variables {} An object containing key value pairs to store
  • settings any Object containing the settings for setting the variables
    • settings.prefix A prefix which is used to store the value with

Returns void

validateBoolean

This will do a simple check if the passed string is a stringified boolean or not

Parameters

  • settings any An object containing the options for validation
    • settings.name The name of the variable to check
    • settings.value The value of the variable to check
    • settings.required Whether it's required (allow undefined values or not)

Returns string A default error message or an empty string

validateEnum

This will do a simple check if the passed value is one of the valid values

Parameters

  • settings any An object containing the options for validation
    • settings.name The name of the variable to check
    • settings.value The value of the variable to check
    • settings.required Whether it's required (allow undefined values or not)
    • settings.validValues The possible values

Returns string A default error message or an empty string

validateMultipleEnum

This will do a simple check if the passed string of values contains one or more valid values

Parameters

  • settings any An object containing the options for validation
    • settings.name The name of the variable to check
    • settings.values The values of the variable to check (must be a string seperated by commas)
    • settings.required Whether it's required (allow undefined values or not)
    • settings.validValues The possible values

Returns string A default error message or an empty string

validateBounds

This will do a simple check if the passed string of values is a valid latitude and longitude map bounds

Parameters

  • settings any An object containing the options for validation
    • settings.name The name of the variable to check
    • settings.value The bounds value
    • settings.required Whether it's required (allow undefined values or not)

Returns any A default error message or an empty array

getProxyResponse

This will get the response from the proxy

Parameters

  • settings any Object containing the settings for getting the response from the proxy
    • settings.characterEncoding Optionally convert the response to UTF-8

Returns any The response from the targetted API

setResponse

This will set the response to the provided content

Parameters

  • content any The response to set for the proxy
  • settings any Object containing the settings for setting the response
    • settings.contentType An optional contenttype header to set for the response

Returns void

getVariable

This will get a value from the Apigee flow

Parameters

  • key string The key the value to get is stored with
  • settings any Object containing the settings for getting the variable
    • settings.prefix A prefix which is used to store the value with
    • settings.defaultValue The value to return when no value is found
    • settings.parser The parser is a function which takes a value and transforms it to return something else

Returns any The value parsed from the apigee flow

getVariables

This will get a set of values from the Apigee flow

Parameters

  • keys Array<string> The keys the values to get are stored with
  • settings any Object containing the settings for getting the variables
    • settings.prefix A prefix which is used to store the value with
    • settings.defaultValues The value to return when no value is found. The keys of the default values should be identical to the variable keys.
    • settings.parser The parser is an object containing functions which take a value and transforms it to return something else. The keys of the parser should be identical to the variable keys.

Returns {} The values parsed from the apigee flow

logMessage

This will log a message to the syslog variable

Parameters

  • additionalLogvalues {}? Object containing additional key values to be logged

Returns void

4.1.0

8 years ago

4.0.0

8 years ago

3.5.0

8 years ago

3.4.0

8 years ago

3.3.0

8 years ago

3.2.2

9 years ago

3.2.1

9 years ago

3.1.0

9 years ago

3.0.0

9 years ago

2.15.0

9 years ago

2.14.1

9 years ago

2.14.0

9 years ago

2.13.0

9 years ago

2.12.1

9 years ago

2.12.0

9 years ago

2.11.0

9 years ago

2.10.1

9 years ago

2.10.0

9 years ago

2.9.3

10 years ago

2.9.2

10 years ago

2.9.1

10 years ago

2.9.0

10 years ago

2.8.0

10 years ago

2.7.0

10 years ago

2.6.0

10 years ago

2.5.0

10 years ago

2.4.0

10 years ago

2.3.0

10 years ago

2.2.1

10 years ago

2.2.0

10 years ago

2.1.0

10 years ago

2.0.0

10 years ago

1.3.0

10 years ago

1.2.0

10 years ago

1.1.1

10 years ago

1.1.0

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago