@mozia/js
v0.2.0
Published
Mozia JavaScript/TypeScript SDK for MBaaS
Maintainers
Readme
@mozia/js
Mozia JavaScript/TypeScript SDK for MBaaS — a thin wrapper around the Mozia API.
Installation
npm install @mozia/jsQuick Start
import { Mozia } from '@mozia/js';
const mozia = new Mozia({
serverURL: 'https://your-mozia-server.com',
appKey: 'your-app-key',
});
// Auth
const { data } = await mozia.auth.login(appId, {
email: '[email protected]',
password: 'secret',
});
const client = mozia.withSession(data.session_token);
// Records
const { data: records } = await client.records.query(appId, collectionId, {
where: { status: 'active' },
limit: 10,
});
await client.records.create(appId, collectionId, { title: 'Hello' });
await client.records.patch(appId, collectionId, recordId, { status: 'archived' });
// Files
await client.files.upload(appId, fileBlob, 'photo.jpg');
// Push
await client.push.send(appId, { title: 'Hi', body: 'Hello!' });
await client.push.register(appId, {
device_token: 'fcm-token',
device_type: 'android',
});
// Cloud Functions
await client.functions.invoke(appId, 'myFunction', { foo: 'bar' });
// LiveQuery (realtime)
const unsubscribe = await mozia.livequery.subscribe(
appId,
'posts',
{ where: { status: 'published' }, order: '-created_at' },
{
onEnter: (r) => console.log('created', r),
onUpdate: (r) => console.log('updated', r),
onLeave: (r) => console.log('deleted', r),
}
);
// later: await unsubscribe();API
- Auth:
signup,login,logout,me,withSession - Records:
query,get,create,update,patch,delete - Files:
list,upload,getUrl,delete - Push:
send,register - Functions:
invoke - LiveQuery:
subscribe(realtime record events)
LiveQuery config
For WebSocket connection, pass Reverb/Pusher options:
const mozia = new Mozia({
serverURL: 'https://api.mozia.io',
appKey: 'your-app-key',
reverbKey: 'your-reverb-key',
reverbHost: 'reverb.mozia.io',
reverbPort: 443,
reverbSecure: true,
});