mirror of
https://github.com/hanzo-dart/base.git
synced 2026-09-11 18:41:29 +00:00
main
The package goes out from the release script, not from here: this file has never produced a run on either plane. Co-authored-by: Hanzo Dev <[email protected]>
hanzo_base — Dart SDK for Hanzo Base
Small, typed Dart client for Hanzo Base, the reactive
backend. Auth is Hanzo IAM-native: the client holds the
IAM-issued JWT and validates its exp claim locally.
It mirrors the shape of the JavaScript client
@hanzo/base and covers exactly what
apps need: auth, records/collections CRUD, realtime (SSE), and files.
Install
dependencies:
hanzo_base: ^0.1.0
import 'package:hanzo_base/hanzo_base.dart';
final base = HanzoBase('https://base.hanzo.ai');
Auth (Hanzo IAM)
await base.collection('users').authWithPassword('[email protected]', 'secret');
base.authStore.isValid; // JWT present and unexpired
base.authStore.token; // the IAM JWT
base.authStore.record; // the authenticated record
base.authStore.clear(); // sign out
Persist the session with an AsyncAuthStore (e.g. secure storage):
final base = HanzoBase(
'https://base.hanzo.ai',
authStore: AsyncAuthStore(
save: (data) => storage.write(key: 'hanzo_auth', value: data),
initial: await storage.read(key: 'hanzo_auth'),
),
);
Records / collections
final page = await base.collection('posts').getList(
page: 1,
perPage: 20,
filter: base.filter('published = {:v}', {'v': true}),
sort: '-created',
);
final one = await base.collection('posts').getOne('RECORD_ID');
final all = await base.collection('posts').getFullList();
final made = await base.collection('posts').create({'title': 'hi'});
final edited = await base.collection('posts').update('RECORD_ID', {'title': 'yo'});
await base.collection('posts').delete('RECORD_ID');
Realtime (SSE)
final off = base.collection('posts').subscribe('*', (e) {
print('${e.action}: ${e.record.id}'); // create | update | delete
});
off(); // stop listening
Files
final url = base.files.getUrl(record, 'photo.png', thumb: '100x100');
// upload via multipart
await base.collection('posts').create(
{'title': 'with image'},
files: [http.MultipartFile.fromBytes('image', bytes, filename: 'p.png')],
);
Errors
Every request throws a typed HanzoException on failure:
try {
await base.collection('posts').getOne('missing');
} on HanzoException catch (e) {
print(e.statusCode); // 404
print(e.message); // server message
}
Develop
dart pub get
dart analyze
dart test
License
MIT © Hanzo AI, Inc. See LICENSE.
Languages
Dart
100%