@orcsrvcs/remote-api-core
v0.0.12
Published
Core logic for inter-app APIs
Downloads
2
Readme
Remote API Core
EventHander is the primary object of this package. It handles the passing and receiving of events. To ensure an event reaches only its desired destination, the event relies on information about its app, its remote, and an optional unique identifier.
Using the API Core
For the convenience of possibly extending this package to not exclusively rely on events, EventHandler is renamed as Api to abstract away from the remote which technique is used. EventHandler will be instantiated new Api()
with attributes specific to the remote supporting these events, and publish()
and subscribe()
will be called to send and receive events.
interface EventOne {
value: string,
success: () => void
};
const eventOne = {
name: 'eventOne',
direction: Direction.BOTH,
version: 1,
convertToOtherVersion: (response: EventOne, otherVersion: number): any => {
// Convert response from the current supported structure to a structure supported by otherVersion
return response;
},
convertToLocalVersion: (response: any, otherVersion: number): EventOne => {
// Convert response from the otherVersion structure to the current supported structure
return response;
}
};
const remoteType = {
name: 'remoteName',
events: [
eventOne
]
};
const remoteApi = new Api(AppType.SHELL, 'appName', remoteType);
remoteApi.publish(
eventOne,
{
value: 'someValue',
success: () => {
// Do stuff with callback
}
}
);
remoteApi.subscribe(
eventOne,
(event: EventOne) => {
// Do stuff with event
}
);
remoteApi.connect();