
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
futoin-invoker
Advanced tools
FutoIn Invoker - Reference Implementation. Transparently and efficiently invoke remote or local service methods with strict API definition for Node and Browser
Reference implementation of:
FTN7: FutoIn Invoker Concept
Version: 1.4
FTN3: FutoIn Interface Definition
Version: 1.2
FTN5: FutoIn HTTP integration
Version: 1.2
FTN9: FutoIn Interface - AuditLog
Version: 1.0 (client)
FTN14: FutoIn Cache
Version: 1.0 (client)
FutoIn Invoker is a peer which initiates a request - invokes a FutoIn interface method as described in FTN3: FutoIn Interface Definition. It is not necessary a client - e.g. server may initiate request for event delivery to client.
The method can be implemented locally or remotely - it is transparent to invoking code. A similar concept can be found in CORBA and other more heavy request brokers.
Strict FutoIn interface (iface) definition and transport protocol is defined in FTN3 spec mentioned above. As it is based on JSON, both client and server can be implemented in a few minutes almost in any technology. However, Invoker and Executor concept provide significant benefits for efficiency, reliability and error control.
The core of invoker is CCM - Connection and Credentials Manager. It has the following advantages:
The primary communication channel is WebSockets. Large raw data upload and download is also supported through automatic fallback to HTTP(S).
SimpleCCM - a light version without heavy processing of iface definition (ideal for browser) AdvancedCCM - full featured CCM (extends SimpleCCM)
Communication methods:
Note: Invoker and Executor are platform/technology-neutral concepts. The implementation is already available in JS and PHP. Hopefully, others are upcoming
Command line:
$ npm install futoin-invoker --save
All public classes can be accessed through module:
var AdvancedCCM = require('futoin-invoker').AdvancedCCM;
or included modular way, e.g.:
var AdvancedCCM = require('futoin-invoker/AdvancedCCM');
$ bower install futoin-invoker --save
Please note that browser build is available under in dist/ folder in sources generated with pure-sjc. It includes modular parts of lodash.
Note: there are the following globals available:
NOTE: more complex examples should be found in futoin-executor
var async_steps = require( 'futoin-asyncsteps' );
var SimpleCCM = require( 'futoin-invoker/SimpleCCM' );
// Initalize CCM, no configuration is required
var ccm = new SimpleCCM();
async_steps()
.add(
function( as ){
// Register interfaces without loading their specs
ccm.register( as, 'localone', 'some.iface:1.0',
'https://localhost/some/path' );
ccm.register( as, 'localtwo', 'other.iface:1.0',
'https://localhost/some/path',
'user:pass' ); // optional credentials
as.add( function( as ){
// Get NativeIface representation of remote interface
// after registration is complete
var localone = ccm.iface( 'localone' );
var localtwo = ccm.iface( 'localtwo' );
// SimpleCCM is not aware of available functions.
// It is the only way to perform a call.
localone.call( as, 'somefunc', {
arg1 : 1,
arg2 : 'abc',
arg3 : true,
} );
as.add( function( as, res ){
// As function prototype is not know
// all invalid HTTP 200 responses may
// get returned as "raw data" in res
// parameter.
console.log( res.result1, res.result2 );
} );
} );
},
function( as, err )
{
console.log( err + ': ' + as.state.error_info );
console.log( as.state.last_exception.stack );
}
)
.execute();
var async_steps = require( 'futoin-asyncsteps' );
var invoker = require( 'futoin-invoker' );
// Define interface, which should normally be put into
// file named "some.iface-1.0-iface.json" and put into
// a folder added to the "specDirs" option.
var some_iface_v1_0 = {
"iface" : "some.iface",
"version" : "1.0",
"ftn3rev" : "1.1",
"funcs" : {
"somefunc" : {
"params" : {
"arg1" : {
"type" : "integer"
},
"arg2" : {
"type" : "string"
},
"arg3" : {
"type" : "boolean"
}
},
"result" : {
"result1" : {
"type" : "number"
},
"result2" : {
"type" : "any"
}
},
"throws" : [
"MyError"
]
}
},
"requires" : [
"SecureChannel",
"AllowAnonymous"
]
};
var other_iface_v1_0 = {
"iface" : "other.iface",
"version" : "1.0",
"ftn3rev" : "1.1"
}
// Initialize CCM. We provide interface definitions directly
var ccm = new invoker.AdvancedCCM({
specDirs : [ __dirname + '/specs', some_iface_v1_0, other_iface_v1_0 ]
});
// AsyncSteps processing is required
async_steps()
.add(
function( as ){
// Register interfaces - it is done only once
ccm.register( as, 'localone',
'some.iface:1.0', 'https://localhost/some/path' );
ccm.register( as, 'localtwo',
'other.iface:1.0', 'https://localhost/some/path',
'user:pass' ); // optional credentials
as.add( function( as ){
// Get NativeIface representation of remote interface
// after registration is complete
var localone = ccm.iface( 'localone' );
var localtwo = ccm.iface( 'localtwo' );
localone.somefunc( as, 1, 'abc', true );
as.add( function( as, res ){
console.log( res.result1, res.result2 );
} );
} );
},
function( as, err )
{
console.log( err + ': ' + as.state.error_info );
console.log( as.state.last_exception.stack );
}
)
.execute();
The concept is described in FutoIn specification: FTN7: Interface Invoker Concept v1.x
#Index
Modules
Classes
Members
#futoin-invoker
#class: AdvancedCCM
Extends: SimpleCCM
Members
##new AdvancedCCM(options) Advanced CCM - Reference Implementation
Params
object
- see AdvancedCCMOptionsExtends: SimpleCCM
##advancedCCM.register(as, name, ifacever, endpoint, [credentials], [options])
Register standard MasterService end-point (adds steps to as)
Params
AsyncSteps
- AsyncSteps instance as registration may be waiting for external resourcesstring
- unique identifier in scope of CCM instancestring
- interface identifier and its version separated by colonstring
- URI
OR any other resource identifier of function( ccmimpl, info )
returning iface implementing peer, accepted by CCM implementation
OR instance of Executorstring
- optional, authentication credentials:
'master' - enable MasterService authentication logic (Advanced CCM only)
'{user}:{clear-text-password}' - send as is in the 'sec' section
NOTE: some more reserved words and/or patterns can appear in the futureobject
- fine tune global CCM options per endpointFires
##advancedCCM.iface(name) Get native interface wrapper for invocation of iface methods
Params
string
- see register()Returns: NativeInterface
- - native interface
##advancedCCM.unRegister(name)
Unregister previously registered interface (should not be used, unless really needed)
Params
string
- see register()Fires
##advancedCCM.defense() Shortcut to iface( "#defense" )
##advancedCCM.log() Returns extended API interface as defined in FTN9 IF AuditLogService
Returns: object
##advancedCCM.cache()
Returns extended API interface as defined in [FTN14 Cache][]
Returns: object
##advancedCCM.assertIface(name, ifacever)
Assert that interface registered by name matches major version and minor is not less than required.
This function must generate fatal error and forbid any further execution
Params
string
- unique identifier in scope of CCM instancestring
- interface identifier and its version separated by colon##advancedCCM.alias(name, alias) Alias interface name with another name
Params
string
- unique identifier in scope of CCM instancestring
- alternative name for registered interfaceFires
##advancedCCM.close() Shutdown CCM (close all active comms)
Fires
##event: "register" CCM regiser event. Fired on new interface registration. ( name, ifacever, info )
##event: "unregister" CCM regiser event. Fired on interface unregistration. ( name, info )
##event: "close" CCM close event. Fired on CCM shutdown.
#class: CacheFace
Extends: NativeIface
Members
##new CacheFace() Cache Native interface
Register with CacheFace.register()
NOTE: it is not directly available in Invoker module interface, include separately
Extends: NativeIface
##CacheFace.ifacespec
Embedded spec for FutoIn CacheFace
##CacheFace.register() Cache Native interface registration helper
##cacheFace.getOrSet(as, key_prefix, callable, params, ttl_ms) Get or Set cached value
NOTE: the actual cache key is formed with concatenation of key_prefix and join of params values
Params
AsyncSteps
string
- unique key prefixfunction
- func( as, params.. ) - a callable
which is called to generated value on cache missArray
- parameters to be passed to callableinteger
- time to live in ms to use, if value is set on cache miss##cacheFace.call(as, name, params, upload_data, [download_stream], [timeout]) Generic FutoIn function call interface Result is passed through AsyncSteps.success() as a map.
Params
AsyncSteps
- AsyncSteps objectstring
- FutoIn iface function nameobject
- map of func parametersstring
| stream.Readable
- raw upload data or input stramstream.Writable
- output stream for raw download dataint
- if provided, overrides the default. <=0 - disables timeout##cacheFace.ifaceInfo() Get interface info
Returns: object
##cacheFace.bindDerivedKey()
Results with DerivedKeyAccessor through as.success()
##event: "connect" Fired when interface establishes connection.
##event: "disconnect" Fired when interface connection is closed.
##event: "close" Interface close event. Fired on interface unregistration.
##event: "commError" Interface communication error. Fired during call processing. ( error_info, rawreq )
##new InterfaceInfo() FutoIn interface info
##interfaceInfo.name() Get FutoIn interface type
Returns: string
##interfaceInfo.version()
Get FutoIn interface version
Returns: string
##interfaceInfo.inherits()
Get list of inherited interfaces starting from the most derived, may be null
Returns: object
##interfaceInfo.funcs()
Get list of available functions, may be null
Returns: object
##interfaceInfo.constraints()
Get list of interface constraints, may be null
Returns: object
#class: LogFace
Extends: NativeIface
Members
##new LogFace() AuditLog Native interface
Register with LogFace.register().
NOTE: it is not directly available Invoker module interface, include separately
Extends: NativeIface
##LogFace.ifacespec
Embedded spec for FutoIn LogFace
##LogFace.register() AuditLog Native interface registration helper
##logFace.msg(lvl, txt) Log message
Params
string
- debug|info|warn|error|securitystring
- message to log##logFace.hexdump(lvl, txt, data) Log message
Params
string
- debug|info|warn|error|securitystring
- message to logstring
- raw data##logFace.debug(txt) Log message in debug level
Params
string
- message to log##logFace.info(txt) Log message in info level
Params
string
- message to log##logFace.warn(txt) Log message in warn level
Params
string
- message to log##logFace.error(txt) Log message in error level
Params
string
- message to log##logFace.security(txt) Log message in security level
Params
string
- message to log##logFace.call(as, name, params, upload_data, [download_stream], [timeout]) Generic FutoIn function call interface Result is passed through AsyncSteps.success() as a map.
Params
AsyncSteps
- AsyncSteps objectstring
- FutoIn iface function nameobject
- map of func parametersstring
| stream.Readable
- raw upload data or input stramstream.Writable
- output stream for raw download dataint
- if provided, overrides the default. <=0 - disables timeout##logFace.ifaceInfo() Get interface info
Returns: object
##logFace.bindDerivedKey()
Results with DerivedKeyAccessor through as.success()
##const: LogFace.LVL_DEBUG Debug log level
##const: LogFace.LVL_INFO Info log level
##const: LogFace.LVL_WARN Warn log level
##const: LogFace.LVL_ERROR Error log level
##const: LogFace.LVL_SECURITY Security log level
##event: "connect" Fired when interface establishes connection.
##event: "disconnect" Fired when interface connection is closed.
##event: "close" Interface close event. Fired on interface unregistration.
##event: "commError" Interface communication error. Fired during call processing. ( error_info, rawreq )
##new NativeIface() Native Interface for FutoIn ifaces
##nativeIface.call(as, name, params, upload_data, [download_stream], [timeout]) Generic FutoIn function call interface Result is passed through AsyncSteps.success() as a map.
Params
AsyncSteps
- AsyncSteps objectstring
- FutoIn iface function nameobject
- map of func parametersstring
| stream.Readable
- raw upload data or input stramstream.Writable
- output stream for raw download dataint
- if provided, overrides the default. <=0 - disables timeout##nativeIface.ifaceInfo() Get interface info
Returns: object
##nativeIface.bindDerivedKey()
Results with DerivedKeyAccessor through as.success()
##event: "connect" Fired when interface establishes connection.
##event: "disconnect" Fired when interface connection is closed.
##event: "close" Interface close event. Fired on interface unregistration.
##event: "commError" Interface communication error. Fired during call processing. ( error_info, rawreq )
##new SimpleCCM([options]) Simple CCM - Reference Implementation
Base Connection and Credentials Manager with limited error control
Params
object
- map of options##simpleCCM.register(as, name, ifacever, endpoint, [credentials], [options]) Register standard MasterService end-point (adds steps to as)
Params
AsyncSteps
- AsyncSteps instance as registration may be waiting for external resourcesstring
- unique identifier in scope of CCM instancestring
- interface identifier and its version separated by colonstring
- URI
OR any other resource identifier of function( ccmimpl, info )
returning iface implementing peer, accepted by CCM implementation
OR instance of Executorstring
- optional, authentication credentials:
'master' - enable MasterService authentication logic (Advanced CCM only)
'{user}:{clear-text-password}' - send as is in the 'sec' section
NOTE: some more reserved words and/or patterns can appear in the futureobject
- fine tune global CCM options per endpointFires
##simpleCCM.iface(name) Get native interface wrapper for invocation of iface methods
Params
string
- see register()Returns: NativeInterface
- - native interface
##simpleCCM.unRegister(name)
Unregister previously registered interface (should not be used, unless really needed)
Params
string
- see register()Fires
##simpleCCM.defense() Shortcut to iface( "#defense" )
##simpleCCM.log() Returns extended API interface as defined in FTN9 IF AuditLogService
Returns: object
##simpleCCM.cache()
Returns extended API interface as defined in [FTN14 Cache][]
Returns: object
##simpleCCM.assertIface(name, ifacever)
Assert that interface registered by name matches major version and minor is not less than required.
This function must generate fatal error and forbid any further execution
Params
string
- unique identifier in scope of CCM instancestring
- interface identifier and its version separated by colon##simpleCCM.alias(name, alias) Alias interface name with another name
Params
string
- unique identifier in scope of CCM instancestring
- alternative name for registered interfaceFires
##simpleCCM.close() Shutdown CCM (close all active comms)
Fires
##const: SimpleCCM.SAFE_PAYLOAD_LIMIT Maximum FutoIn message payload size (not related to raw data)
Default: 65536
##const: SimpleCCM.SVC_RESOLVER
Runtime iface resolution v1.x
##const: SimpleCCM.SVC_AUTH AuthService v1.x
##const: SimpleCCM.SVC_DEFENSE Defense system v1.x
##const: SimpleCCM.SVC_ACL Access Control system v1.x
##const: SimpleCCM.SVC_LOG Audit Logging v1.x
##const: SimpleCCM.SVC_CACHE_ cache v1.x iface name prefix
##event: "register" CCM regiser event. Fired on new interface registration. ( name, ifacever, info )
##event: "unregister" CCM regiser event. Fired on interface unregistration. ( name, info )
##event: "close" CCM close event. Fired on CCM shutdown.
##SpecTools.loadIface(as, info, specdirs) Load FutoIn iface definition.
NOTE: Browser uses XHR to load specs, Node.js searches in local fs.
Params
AsyncSteps
Object
- destination object with "iface" and "version" fields already setArray
- each element - search path/url (string) or raw iface (object)##SpecTools.parseIface(as, info, specdirs, raw_spec) Parse raw futoin spec (preloaded)
Params
AsyncSteps
Object
- destination object with "iface" and "version" fields already setArray
- each element - search path/url (string) or raw iface (object)Object
- iface definition object##SpecTools.checkConsistency(as, info) Deeply check consistency of loaded interface.
NOTE: not yet implemented
Params
AsyncSteps
Object
- previously loaded iface##SpecTools.checkType(info, type, val) Check if value matches required type
Params
Object
- previously loaded ifacestring
- standard or custom iface type*
- value to checkReturns: Boolean
##SpecTools.checkParameterType(info, funcname, varname, value)
Check if parameter value matches required type
Params
Object
- previously loaded ifacestring
- function namestring
- parameter name*
- value to check##SpecTools.checkResultType(as, info, funcname, varname, value) Check if result value matches required type
Params
AsyncSteps
Object
- previously loaded ifacestring
- function namestring
- result variable name*
- value to check##SpecTools.genHMAC(as, info, ftnreq) Generate HMAC
NOTE: for simplicity, 'sec' field must not be present
Params
AsyncSteps
object
- Interface raw info objectobject
- Request ObjectReturns: Buffer
- Binary HMAC signature
##const: SpecTools.standard_errors
Enumeration of standard errors
#class: AdvancedCCMOptions
Extends: SimpleCCMOptions
Members
##new AdvancedCCMOptions() This is a pseudo-class for documentation purposes
NOTE: Each option can be set on global level and overriden per interface.
Extends: SimpleCCMOptions
##AdvancedCCMOptions.specDirs
Search dirs for spec definition or spec instance directly. It can
be single value or array of values. Each value is either path/URL (string) or
iface spec instance (object).
Default: []
##AdvancedCCMOptions.hmacKey
Base64 encoded key for HMAC generation. See FTN6/FTN7
##AdvancedCCMOptions.hmacAlgo Hash algorithm for HMAC generation: MD5(default), SHA224, SHA256, SHA384, SHA256
Default: MD5
#class: SimpleCCMOptions
Members
##new SimpleCCMOptions() This is a pseudo-class for documentation purposes.
NOTE: Each option can be set on global level and overriden per interface.
##SimpleCCMOptions.callTimeoutMS Overall call timeout (int)
Default: 3000
##SimpleCCMOptions.prodMode
Production mode - disables some checks without compomising security
Default: false
##SimpleCCMOptions.commConfigCallback
Communication configuration callback( type, specific-args )
Default: null
##SimpleCCMOptions.executor
Client-side executor for bi-directional communication channels
##SimpleCCMOptions.targetOrigin browser-only. Origin of target for window.postMessage()
##SimpleCCMOptions.retryCount How many times to retry the call on CommError. NOTE: actual attempt count is retryCount + 1
Default: 1
##SimpleCCMOptions.messageSniffer()
Message sniffer callback( iface_info, msg, is_incomming ).
Useful for audit logging.
Default: dummy
##SimpleCCMOptions.disconnectSniffer()
Bi-directional channel disconnect sniffer callback( iface_info ).
Useful for audit logging.
Default: dummy
#SimpleCCM
window.SimpleCCM - Browser-only reference to futoin-asyncsteps.SimpleCCM
#AdvancedCCM window.AdvancedCCM - Browser-only reference to futoin-asyncsteps.AdvancedCCM
#Invoker futoin.Invoker - Browser-only reference to futoin-invoker module
#FutoInInvoker window.FutoInInvoker - Browser-only reference to futoin-invoker module
#SimpleCCM window.SimpleCCM - Browser-only reference to futoin-asyncsteps.SimpleCCM
documented by jsdoc-to-markdown.
FAQs
Transparently, efficiently and securely invoke remote or local service methods with strict API definition for Node and Browser
The npm package futoin-invoker receives a total of 2 weekly downloads. As such, futoin-invoker popularity was classified as not popular.
We found that futoin-invoker demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.