Files
zeekay 42fdfa209d Rename Dart package hanzo -> hanzo_base
pub.dev names 'hanzo' and 'base' are taken by unrelated packages;
'hanzo_base' is the correct available name. Renames the library
(lib/hanzo.dart -> lib/hanzo_base.dart), example, and test, and
fixes all package: imports, README, badge, and pubspec repository
to hanzo-dart/base. dart analyze --fatal-infos + dart test green;
pub publish --dry-run clean (0 warnings).
2026-07-03 14:33:01 -07:00

2.6 KiB

hanzo_base — Dart SDK for Hanzo Base

pub package

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.