Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

axway-flow-sdk

Package Overview
Dependencies
Maintainers
11
Versions
82
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

axway-flow-sdk

SDK for implementing custom flow nodes for API Builder flows

  • 2.0.16
  • npm
  • Socket score

Version published
Weekly downloads
77
increased by450%
Maintainers
11
Weekly downloads
 
Created
Source

axway-flow-sdk

SDK for implementing custom flow nodes for API Builder flows

Features

  • CLI tool for starting a new flow-node plugin
  • SDK for building custom flow-node plugins for API Builder flows

Install

npm install -g axway-flow-sdk

Generating a new flow-node plugin

Generates a new flow-node plugin named "mynode" in the current directory.

axway-flow -n mynode
cd api-builder-plugin-fn-mynode
npm install --no-optional
npm run build (optional)

encodeURI example

const sdk = require('axway-flow-sdk');

function getFlowNodes() {
	const flownodes = sdk.init(module)
		.add('encodeURI', {
			name: 'Encode URI',
			icon: 'encode.svg',
			description: 'URI encoder'
		})
		.method('encode', {
			name: 'Encode URI',
			description: 'Encodes a URI by replacing each instance of certain characters with UTF-8 encodings.'
		})
		.parameter('uri', {
			type: 'string',
			description: 'The URI to encode.'
		})
		.output('encoded', {
			name: 'Encoded',
			description: 'The encoded URI.',
			context: '$.encodedURI',
			schema: {
				type: 'string'
			}
		})
		.action((req, cb) => {
			cb.encoded(null, encodeURI(req.params.uri));
		});
	return Promise.resolve(flownodes);
}

exports = module.exports = getFlowNodes;

Notice that this encodeURI example is returning a function, getFlowNodes, that returns a promise. This allows for the generation of the flow-node to be asynchronous, for example, to allow the loading of content from a remote source. In this example it is used for demostration purposes only, flownodes could have been returned from getFlowNodes instead.

Type references

In Axway API Builder, it is possible to reference other types. For example, types can be loaded from ./schemas, registered from Models, or registered from service connectors. Any registered schema can be referenced whenever a schema is required.

.parameter('greeting', {
	"$ref": "schema://model/appc.arrowdb/user"
})
.output('next', {
	schema: {
		"$ref": "schema://model/appc.arrowdb/user"
	}
})

Testing your flow-node module

The cli will automatically generate a unit test in ./test/test.js. The test will use mocknode to mock an API Builder flow-node.

mocknode(flownodes) : function

Mocks an API Builder flow-node using the flow-node generated with NodeBuilder.

Access: public

ParamTypeDescription
flownodesNodeBuilderThe NodeBuilder object.

Testing a successful output callback: cb.next(null, 'stuff')

This example uses mocha and promises to check that the flow-node is defined well enough to pass the argument foo to the method method. It also mocks the callback using the flow-node's defined output, and ensures that the method invokes the correct callback.

Note if the flow-node is asynchronous, i.e. returns a promise, the promise must be resolved to get the flow-nodes defined in the plugin. This can simply be done using a before block that waits for the resolved promise.

const flownodesPromise = require('../src');
const { mocknode } = require('axway-flow-sdk');

let flownodes;
before(() => {
	return flownodesPromise.then((resolvedFlownodes) => {
		flownodes = resolvedFlownodes;
	});
});

it('describes a test', () => {
	const args = { foo: undefined };
	return mocknode(flownodes).node('example').invoke('method', args)
		.then((response) => {
			expect(response).to.deep.equal({
				next: [null, 'stuff']
			})
		});
})

Testing an error default callback: cb('invalid argument')

This example is similar to the previous example, save that the expectation is that the method will invoke cb('invalid argument') when given an undefined parameter.

const flownodes = require('../src');
const { mocknode } = require('axway-flow-sdk');

it('describes a test', () => {
	const args = { foo: undefined };
	return mocknode(flownodes).node('example').invoke('method', args)
		.then((response) => {
			expect(response).to.deep.equal(['invalid argument'])
		});
})

API Reference

axway-flow-sdk~NodeBuilder

Kind: inner class of axway-flow-sdk

new NodeBuilder(srcModule)
ParamTypeDescription
srcModuleobjecta node module

nodeBuilder.add(key, [options]) ⇒ NodeBuilder

Adds a new flownode and prepares the NodeBuilder to accept the following flownode operations:

The key parameter is used to uniquely identify the flownode and represents a distinct instance of a node for the flow editor. The key will be used as the name unless the name option is provided. The new node will appear under the "general" category by default, or under the provided category option.

The icon option can be bmp, jpeg, png, gif, tiff, or svg file. After, .method can be used to add method(s), and .output can be used to define an output. When done, .action can be used to define an action function and finish the flownode.

Kind: instance method of NodeBuilder
Returns: NodeBuilder - The current object (this).
Access: public

ParamTypeDefaultDescription
keystringA unique key identifier for the node.
[options]objectOptions for the node.
[options.name]stringA friendly name for the node as it will appear in the UI.
[options.icon]stringAn icon file.
[options.description]stringA description for the node.
[options.category]string"general"A category under which the node will appear in the UI (defaults to "general").

Example

sdk.init(module).add('encodeURI', { icon: 'encode.svg' });

nodeBuilder.method(key, [options]) ⇒ NodeBuilder

Adds a new method to the current node flownode and prepares the NodeBuilder to accept the following method operations:

.add(key, [options]) must be called prior to adding a method.

The key uniquely identifies the method for the node and will be used as the name unless the name option is provided.

Kind: instance method of NodeBuilder
Returns: NodeBuilder - The current object (this).
Access: public

ParamTypeDescription
keystringA unique key identifier for the method.
[options]objectOptions for the method.
[options.name]stringA friendly name for the method as it will appear in the UI.
[options.description]stringA description for the method.

Example

sdk.init(module).add('encodeURI', { icon: 'encode.svg' })
	.method('encode', { name: 'Encode URI' });

nodeBuilder.parameter(name, schema, [required]) ⇒ NodeBuilder

Adds a new parameter to the current method. Any number of parameters can be added to a method.

.method(key, [options]) must be called prior to adding a parameter.

The name uniquely identifies the the parameter, and the schema is a valid JSON Schema definition (both draft-04 and draft-06 are supported).

Kind: instance method of NodeBuilder
Returns: NodeBuilder - The current object (this).
Access: public

ParamTypeDefaultDescription
namestringA unique name for the parameter as it will appear in the UI.
schemaobjectA schema used to validate the parameter.
[required]booleantrueA flag to indicate the parameter is required or optional.

Example

sdk.init(module).add('encodeURI', { icon: 'encode.svg' })
	.method('encode', { name: 'Encode URI' })
	.parameter('uri', { type: 'string' });

nodeBuilder.output(key, [options]) ⇒ NodeBuilder

Adds a new output to the current method. Any number of outputs can be added to a method, but for usability-sake, you should limit this. The output represents one of the possible callback routes for your method. For example, if your method tested prime numbers, then one output might be prime, and the other not-prime.

.method(key, [options]) must be called prior to adding an output.

The key uniquely identifies the the output route. The schema is a valid JSON Schema definition (both draft-04 and draft-06 are supported). If schema is not provided, then the output type is effectively any type.

The context is a valid JSON Path and is used as the default by the flow editor. When the output is invoked, the configured context is where the output value will be written.

Kind: instance method of NodeBuilder
Returns: NodeBuilder - The current object (this).
Access: public

ParamTypeDescription
keystringA unique key for the output.
[options]objectoutput options
[options.name]stringA friendly name for the output as it will appear in the UI.
[options.description]stringThe output description.
[options.context]stringThe default context string.
[options.schema]objectThe expected JSON schema for the output value.

Example

sdk.init(module).add('encodeURI', { icon: 'encode.svg' })
	.method('encode', { name: 'Encode URI' })
	.parameter('uri', { type: 'string' })
	.output('encoded', { context: '$.encodedURI', schema: { type: 'string' } });

nodeBuilder.action(handler) ⇒ NodeBuilder

Assigns an action handler to the current method. The method can only have one action handler. Assigning an action will terminate the current method definition.

Kind: instance method of NodeBuilder
Returns: NodeBuilder - The current object (this).
Access: public

ParamTypeDescription
handlerhandlerThe action handler function.

Example

sdk.init(module).add('encodeURI', { icon: 'encode.svg' })
	.method('encode', { name: 'Encode URI' })
	.parameter('uri', { type: 'string' })
	.output('encoded', { context: '$.encodedURI', schema: { type: 'string' } })
	.action((req, cb) => cb.encoded(null, encodeURI(req.params.uri));

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

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

Kind: inner method of axway-flow-sdk
Returns: NodeBuilder - A newly constructed NodeBuilder object

ParamTypeDescription
moduleobjectThe node module.

Example

const sdk = require('axway-flow-sdk');
exports = module.exports = sdk.init(module);

axway-flow-sdk~validate(nodes)

Validates the flownodes against the Axway Flow schema.

Kind: inner method of axway-flow-sdk
Throws:

  • Error If nodes contains invalid flownodes.

Access: public

ParamTypeDescription
nodesNodeBuildernodes to validate

Example

const nodes = sdk.init(module).add('encodeURI', { icon: 'encode.svg' })
	.method('encode', { name: 'Encode URI' })
	.parameter('uri', { type: 'string' })
	.output('encoded', { context: '$.encodedURI', schema: { type: 'string' } })
	.action((req, cb) => cb.encoded(null, encodeURI(req.params.uri));
sdk.validate(nodes);

Author

Axway support@axway.com https://axway.com

Changes

axway-flow-sdk@2.0.9
  • RDPP-4757: Changed SCM repository and associated internal cleanup.

License

This code is proprietary, closed source software licensed to you by Axway. All Rights Reserved. You may not modify Axway’s code without express written permission of Axway. You are licensed to use and distribute your services developed with the use of this software and dependencies, including distributing reasonable and appropriate portions of the Axway code and dependencies. Except as set forth above, this code MUST not be copied or otherwise redistributed without express written permission of Axway. This module is licensed as part of the Axway Platform and governed under the terms of the Axway license agreement (General Conditions) located here: https://support.axway.com/en/auth/general-conditions; EXCEPT THAT IF YOU RECEIVED A FREE SUBSCRIPTION, LICENSE, OR SUPPORT SUBSCRIPTION FOR THIS CODE, NOTWITHSTANDING THE LANGUAGE OF THE GENERAL CONDITIONS, AXWAY HEREBY DISCLAIMS ALL SUPPORT AND MAINTENANCE OBLIGATIONS, AS WELL AS ALL EXPRESS AND IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO IMPLIED INFRINGEMENT WARRANTIES, WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, AND YOU ACCEPT THE PRODUCT AS-IS AND WITH ALL FAULTS, SOLELY AT YOUR OWN RISK. Your right to use this software is strictly limited to the term (if any) of the license or subscription originally granted to you.

Keywords

FAQs

Package last updated on 25 Jan 2019

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