@showell-labs/showell-web-app-client
v1.2.15
Published
Client for managing plugins and postMessage interfaces
Downloads
3
Readme
Showell Web App Client
This is a tool to make discussing with Showell app or API easier. Import it as regular package, initialize and start communicating!
Import
import WebAppClient from '@showell-labs/showell-web-app-client/lib';
Initialization
WebAppClient.init(
plugins: RequestedServiceDefinitions,
env: 'prod' | 'dev',
channel: 'app' | 'api' | 'auto' = 'auto',
credentials?: {
username: string;
authToken: string;
}
)
Init
returns a promise you can wait for, to ensure that it's ready before you start making any calls.
| Parameter | Meaning | Default | | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- | | plugins | Import and include the plugins you want to use here. This is an object where keys are known plugin names | required | | env | If working in production or developement mode | required | | channel | Used to specify if client should try to communicate with App over the postMessage or with API over the Fetch. Auto means that client tries to check if known constants or globals are found that indicate it's being run within WebView of the app | auto | | credentials | If you want to use API mode, you must provide credentials for client to fetch identity for you | undefined |
Plugins
List of supported plugins:
DownloadPlugin
- Manage offline content, check download status, force downloading etc. App only.FilePlugin
- Get information about file(s) or folder(s). App & API.IdentityPlugin
- Manage Showell user. This plugin is always included. App & API.SelectedPlugin
- Manually use the selected feature of the app. App only.SyncPlugin
- Control how app syncs contents between local database and server. App only.UiPlugin
- Trigger specific UI actions like showing or hiding navbar. App only.
All plugins can be found from plugins
folder. You must provide a set of plugins you plan on using when calling init
.
import FilePlugin from '@showell-labs/showell-web-app-client/lib/plugins/FilePlugin';
// ...
WebAppClient.Client.init(
plugins: { filePlugin: FilePlugin },
// ...
)
If you don't really care about code splitting and you are feeling lazy, you can also do this:
import { ALL_PLUGINS } from '@showell-labs/showell-web-app-client/lib';
// ...
WebAppClient.Client.init(
plugins: ALL_PLUGINS,
// ...
)
Object keys are specific to plugin and it's the same name thats in folder name but the first letter is lower cased.
Prefer TypeScript
Usage
Once you have initialized the client and waited for it to be ready, you can start doing calls. Client provides service
method for getting specific plugin. Here's how you would list files in directory called Photos.
const files = await WebAppClient.Client.service('filePlugin').listDir('Photos');
Advanced
In case you need to call plugin directly through postMessage, or call Showell API directly, you can use
makePluginCall
and makeApiCall
functions from client.