Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The starter project is heavily commented to simplify the process of customizing it. It also comes with the eslint configuration and the mocha unit tests incorporated to help you ensure the quality of your custom flow-node.

Sample encodeURI flow-node

As an example of how to write a flow-node, we will examine creating a flow-node that URI encodes a string.

...

Customize the flow-node definition in the index.js file

Code Block
const sdk = require('axway-flow-sdk');
const action = require('./action');

const flownodes = sdk.init(module);

flownodes
    .add('encodeuri', {
        name: 'Encode URI',
        icon: 'icon.svg',
        description: 'URI encoder.',
        category: 'utils'
    })
    .method('encode', {
        name: 'Encode URI',
        description: 'Encodes a URI by replacing each instance of certain characters with UTF-8 encodings.'
    })
    .parameter('uri', {
        description: 'The URI to encode.',
        type: 'string'
    })
    .output('next', {
        name: 'Next',
        description: 'The URI was encoded successfully.',
        context: '$.encodedURI',
        schema: {
            type: 'string'
        }
    })
    .action(action);
exports = module.exports = flownodes;

...

The starter project includes automatically generated unit tests in the ./test directory of your project. The tests are for example purposes and will need to be customized to your specific use case. The SDK provides a mocknode that allows for mock invocations of your flow-node methods.

Use mocknode to test error callback existence - valid argument

...

Code Block
    it('[TEST-2] should succeed', () => {
        return mocknode(specs).node('encodeuri')
            .invoke('encode', { uri: 'some string' })
            .then((data) => {
                expect(data).to.deep.equal({
                        next: [ null, 'some%20string' ]
                });
            });
    });

Using mocknode to test error callback existence - invalid argument

...

ParameterTypeDefaultDescription
key

string

 A unique key identifier for the flow-node.
[options]

object

 Options for the flow-node.
[options.name]

string

 A friendly name for the flow-node as it will appear in the UI.
[options.icon]

string

 An icon file.
[options.description]

string

 A description for the flow-node.
[options.category]

string

general

A category under which the flow-node will appear in the UI.

...

ParameterTypeDescription
key

string

A unique key identifier for the method.
[options]

object

Options for the method.
[options.name]

string

A friendly name for the method as it will appear in the UI.

...

ParameterTypeDefaultDescription
name

string

 A unique name for the parameter as it will appear in the UI.
schema

object

 A schema used to validate the parameter.
[required]

boolean

true

A flag to indicate the parameter is required or optional.

...

ParameterTypeDescription
key

string

A unique key for the output.
[options.name]

string

A friendly name for the output as it will appear in the UI.
[options.description]

string

The output description.
[options.context]

string

The default context string.
[options.schema]

object

The expected JSON schema for the output value.

...

ParameterTypeDescription
handler

handler

The action handler function.

...

Anchor
init
init
axway-flow-sdk~init(module) - NodeBuilder

Axway API Builder SDK for creating custom flow-nodes to work with flows.

...

ParameterTypeDescription
module

object

The flow-node module.

Example:

...

Anchor
handler
handler
axway-flow-sdk~handler: function

A handler function to perform the flow-node method's action. The function will receive all of the provided parameters in req.params.  If any parameters are not provided or are at the wrong time, or some have defaults, your function will need to handle those situations. On success, your function should invoke the named output. On error, your function should invoke a callback with a non-null err value.

...

ParameterTypeDescription
req

request

The Request object.
cb

callback

The output callback.

Example:

...

Anchor
flow
flow
axway-flow-sdk~flowCallback: function

A callback function that your method handler must invoke.

...

ParameterTypeDescription

[err]

*

A non null value indicates a terminal error (flow processing will stop).
[value]

*

The output value to be written back to the flow processing context.

Anchor
request
request
axway-flow-sdk~Request: object

The request object.

Kind: Inner type definition of axway-flow-sdk

Properties:

NameTypeDescription
envobjectThe application configuration.
paramsobjectThe params method, as supplied during runtime (see .parameter).