@zairn/sdk
v0.7.2
Published
SDK for zairn location sharing platform
Maintainers
Readme
@zairn/sdk
TypeScript SDK for the Zairn location sharing platform. Built on Supabase.
Installation
pnpm add @zairn/sdk @supabase/supabase-jsQuick Start
import { createLocationCore } from '@zairn/sdk';
const core = createLocationCore({
supabaseUrl: 'https://your-project.supabase.co',
supabaseAnonKey: 'your-anon-key',
});
// Sign in
await core.signIn('[email protected]', 'password');
// Share your location
await core.sendLocation({ lat: 35.6812, lon: 139.7671, accuracy: 10 });
// See friends on the map
const friends = await core.getVisibleFriends();
// Real-time location updates
const channel = core.subscribeLocations(row => {
console.log('Friend moved:', row);
});Features
Location Sharing
sendLocation(update)— Send current locationsendLocationWithTrail(update)— Send location + record trail historygetVisibleFriends()— Get all friends whose locations you can seegetLocationHistory(userId, options?)— Get location trail
Friends
sendFriendRequest(toUserId)— Send a friend requestacceptFriendRequest(requestId)— Accept a request (creates bidirectional share rules)getFriends()— List all friendsremoveFriend(friendId)— Remove a friend
Profile
getProfile(userId)— Get user profileupdateProfile(data)— Update your profilesearchProfiles(query)— Search users by name
Groups
createGroup(name, memberIds)— Create a groupjoinGroup(inviteCode)— Join via invite codegetGroups()— List your groupsleaveGroup(groupId)— Leave a group
Chat
getOrCreateDirectChat(userId)— Open a DMsendMessage(roomId, body)— Send a messagegetMessages(roomId, options?)— Get message historysubscribeMessages(roomId, callback)— Real-time messages
Reactions & Bump
sendReaction(toUserId, emoji)— Send an emoji pokegetReceivedReactions()— Get reactions receivedfindNearbyFriends(lat, lon)— Detect friends nearbyrecordBump(friendId, lat, lon)— Record a bump event
Favorites
addFavoritePlace(data)— Add a favorite place (home, work, school, etc.)getFavoritePlaces()— List favorite placesupdateFavoritePlace(id, data)/deleteFavoritePlace(id)
Sharing Policies (SecureCheck)
addSharingPolicy(policy)— Add a context-dependent sharing policygetSharingPolicies()— List your policiesupdateSharingPolicy(id, updates)— Update a policydeleteSharingPolicy(id)— Delete a policygetVisibleFriendsFiltered(lat, lon)— Get friends with policy-based filtering
Policies support conditions: time_range, geofence, proximity, trust_score.
Effect levels: none, coarse (grid-snapped), current, history.
// Auto-ghost when at home
await core.addSharingPolicy({
conditions: [{ type: 'geofence', lat: 35.68, lon: 139.76, radius_m: 100, inside: true }],
effect_level: 'none',
priority: 10,
label: 'Ghost at home',
});
// Show coarse location at night
await core.addSharingPolicy({
conditions: [{ type: 'time_range', start: '00:00', end: '06:00', timezone: 'Asia/Tokyo' }],
effect_level: 'coarse',
coarse_radius_m: 500,
priority: 5,
});Settings
enableGhostMode(until?)— Hide your locationdisableGhostMode()— Become visible againupdateSettings(data)— Update user settings
Exploration
getMyVisitedCells(options?)— Get your visited geohash cellsgetFriendVisitedCells(friendId, options?)— Get a friend's visited cellsgetAreaRanking(areaPrefix, limit?)— Leaderboard for an areaencodeGeohash(lat, lon, precision?)/decodeGeohash(hash)
Realtime
subscribeLocations(callback)— Real-time friend location updatessubscribeFriendRequests(callback)— Real-time friend request notificationssubscribeReactions(callback)— Real-time reaction notifications
Database Setup
Apply the core schema and RLS policies to your Supabase project:
# In Supabase SQL Editor, run:
# 1. database/schema.sql
# 2. database/policies.sqlSecurity
- All tables use Row Level Security (RLS)
- Location viewing requires explicit share rules
- Ghost mode prevents location tracking
- GPS coordinate validation prevents NaN/Infinity injection
- All user-provided IDs are validated before use in queries
License
MIT
