onecrew-api-client
v2.26.0
Published
OneCrew Backend API Client for Expo/React Native - A comprehensive TypeScript client for film and entertainment industry APIs with user profile management, talent profiles, skills, abilities, languages, portfolio management, project management, task assig
Downloads
65
Maintainers
Keywords
Readme
OneCrew API Client
A TypeScript/JavaScript client library for the OneCrew Backend API, designed for Expo and React Native applications.
Installation
npm install onecrew-api-clientQuick Start
import { OneCrewApi } from 'onecrew-api-client';
// Initialize the API client
const api = new OneCrewApi('https://your-api-url.com');
// Initialize authentication
await api.initialize();
// Example: Login and manage user details
await api.auth.login({
email: '[email protected]',
password: 'password'
});
// Create user details
const userDetails = await api.createUserDetails({
gender: 'female',
birthday: '1998-05-15', // Date string in ISO format (YYYY-MM-DD)
nationality: 'American',
height_cm: 165,
weight_kg: 58,
skin_tone: 'medium',
hair_color: 'brown',
willing_to_travel: true
});
// Get user details
const details = await api.getUserDetails();
console.log('User details:', details.data);
// Example: Managing talent profile with dropdowns
const [hairColors, skinTones, profile] = await Promise.all([
api.getAvailableHairColors(),
api.getAvailableSkinTones(),
api.getTalentProfile()
]);
// Create dropdown options with current selection
const hairColorOptions = hairColors.data.map(option => ({
id: option.id,
name: option.name,
selected: option.id === profile.data.hair_color_id
}));
const skinToneOptions = skinTones.data.map(option => ({
id: option.id,
name: option.name,
selected: option.id === profile.data.skin_tone_id
}));
// Update talent profile
await api.updateTalentProfile({
hair_color_id: 'selected-hair-color-id',
skin_tone_id: 'selected-skin-tone-id',
eye_color: 'brown',
height_cm: 175,
weight_kg: 70
});Features
- 🔐 Authentication: JWT token management with secure storage
- 👥 User Management: Get, update, and manage user profiles
- 📋 User Details: Complete user profile details management
- 🎭 Talent Profile: Comprehensive talent profile management
- 🛠️ Skills Management: Add, remove, and manage user skills
- 🎯 Abilities: Manage abilities with proficiency levels
- 🌍 Languages: Multi-language support with proficiency levels
- 🖼️ Portfolio: Media portfolio management (images/videos)
- 🎬 Project Management: Create, join, and manage film projects
- 👥 Team Management: Create and manage teams
- 💬 Communication: Real-time messaging and conversations
- 🔔 Push Notifications: iOS and Android push notification support
- 🔍 Search: Advanced search across users, projects, and teams
- 📁 File Upload: Upload files and media
- 📱 React Native Ready: Optimized for Expo and React Native
API Methods
User Management
getUsers(params?)- Get all users with filtersgetUserById(userId)- Get user by IDgetUserByIdDirect(userId)- Direct user endpointupdateUserProfile(updates)- Update current user profiledeleteUser()- Delete current user
User Details Management
getUserDetails(userId?)- Get user details (current user or by ID)createUserDetails(details)- Create user detailsupdateUserDetails(updates)- Update current user's detailsupdateUserDetailsById(userId, updates)- Update specific user's detailspatchUserDetails(updates)- Partial update of current user's detailsdeleteUserDetails(userId?)- Delete user details
Talent Profile Management
getTalentProfile()- Get current user's talent profileupdateTalentProfile(updates)- Update talent profilepatchTalentProfile(updates)- Partial update of talent profilegetAvailableHairColors()- Get all available hair colors for dropdownsgetAvailableSkinTones()- Get all available skin tones for dropdowns
Skills Management
getAvailableSkills()- Get all available skillsgetUserSkills()- Get user's current skillsaddUserSkill(skillId)- Add skill to user profileremoveUserSkill(skillId)- Remove skill from user profile
Abilities Management
getAvailableAbilities()- Get all available abilitiesgetUserAbilities()- Get user's current abilitiesaddUserAbility(abilityId, proficiency)- Add ability with proficiency (1-5)updateUserAbility(abilityId, proficiency)- Update ability proficiencyremoveUserAbility(abilityId)- Remove ability from user profile
Languages Management
getAvailableLanguages()- Get all available languagesgetUserLanguages()- Get user's current languagesaddUserLanguage(languageId, level)- Add language with proficiency levelremoveUserLanguage(languageId)- Remove language from user profile
Portfolio Management
getUserPortfolio()- Get user's portfolio itemsaddPortfolioItem(item)- Add image/video to portfolioupdatePortfolioItem(itemId, updates)- Update portfolio itemremovePortfolioItem(itemId)- Remove portfolio item
Project Management
getProjects(params?)- Get all projectsgetProjectById(projectId)- Get project by IDcreateProject(projectData)- Create new projectupdateProject(projectId, updates)- Update projectgetMyProjects(params?)- Get user's projects (supportsinclude_deletedparameter)getDeletedProjects(params?)- Get user's deleted projects onlydeleteProject(projectId)- Soft delete a projectrestoreProject(projectId)- Restore a soft-deleted projectjoinProject(projectId, role?)- Join a projectleaveProject(projectId)- Leave a project
Team Management
getTeams(params?)- Get all teamsgetTeamById(teamId)- Get team by IDcreateTeam(teamData)- Create new teamjoinTeam(teamData)- Join a teamleaveTeam(teamId)- Leave a team
Communication
getConversations(params?)- Get user conversationscreateConversation(participantIds, name?)- Create conversationgetMessages(conversationId, params?)- Get conversation messagessendMessage(conversationId, messageData)- Send message
Chat (Real-Time Chat System)
Use api.chat.* for the newer chat system (/api/chat/...). This supports sender/read hydration controls to keep responses small and avoid over-fetching.
chat.getMessages(conversationId, params?)- Get conversation messages (supportsinclude,sender_type,sender_user_fields,sender_company_fields)chat.sendMessage(conversationId, data)- Send a messagechat.getConversations(params?)- List conversations
Examples
// Profile-scoped conversation lists (avoid mixing personal + company chats)
const personalConversations = await api.chat.getConversations({ profile_type: 'user' });
const companyConversations = await api.chat.getConversations({ profile_type: 'company' });
const singleCompanyConversations = await api.chat.getConversations({
profile_type: 'company',
company_id: 'your-company-id'
});
// Personal messages only, no extra hydration (smallest payload)
const personal = await api.chat.getMessages(conversationId, {
sender_type: 'user',
include: 'none'
});
// Company messages (includes academy) with academy detection
const company = await api.chat.getMessages(conversationId, {
sender_type: 'company',
include: ['sender_company'],
sender_company_fields: ['id', 'name', 'logo_url', 'subcategory']
});
// Detect academy messages on the client
const academyMessages = (company.data?.data || []).filter(
m => m.sender_company?.subcategory === 'academy'
);Push Notifications
pushNotifications.registerDeviceToken(token, platform, deviceId?, appVersion?)- Register device token for push notificationspushNotifications.unregisterDeviceToken(token)- Unregister device tokenpushNotifications.getDeviceTokens()- Get user's registered device tokens
Example:
// Register device token after login
import * as Notifications from 'expo-notifications';
import { Platform } from 'react-native';
// Get push token (Expo)
const { data: token } = await Notifications.getExpoPushTokenAsync({
projectId: 'your-project-id'
});
// Register with backend
await api.pushNotifications.registerDeviceToken(
token,
Platform.OS === 'ios' ? 'ios' : 'android',
'device-id-123',
'1.0.0'
);
// Unregister on logout
await api.pushNotifications.unregisterDeviceToken(token);See CLIENT_PUSH_NOTIFICATION_INTEGRATION.md for complete integration guide.
Search
searchUsers(params)- Search userssearchProjects(params)- Search projectssearchTeams(params)- Search teamsglobalSearch(query, params?)- Global searchgetSearchSuggestions(query)- Get search suggestions
File Upload
uploadFile(file)- Upload file
Examples
Talent Profile Management
// Get talent profile
const talentProfile = await api.getTalentProfile();
console.log('Talent profile:', talentProfile.data);
// Update talent profile
const updatedProfile = await api.updateTalentProfile({
height_cm: 175,
weight_kg: 70,
eye_color: 'brown',
travel_ready: true,
union_member: false
});Skills Management
// Get available skills
const availableSkills = await api.getAvailableSkills();
console.log('Available skills:', availableSkills.data);
// Get user's current skills
const userSkills = await api.getUserSkills();
console.log('User skills:', userSkills.data);
// Add a skill to user profile
const skillToAdd = availableSkills.data[0];
const addedSkill = await api.addUserSkill(skillToAdd.id);
console.log('Added skill:', addedSkill.data);
// Remove a skill from user profile
await api.removeUserSkill(skillToAdd.id);Abilities Management
// Get available abilities
const availableAbilities = await api.getAvailableAbilities();
console.log('Available abilities:', availableAbilities.data);
// Add ability with proficiency level (1-5)
const abilityToAdd = availableAbilities.data[0];
const addedAbility = await api.addUserAbility(abilityToAdd.id, 4);
console.log('Added ability:', addedAbility.data);
// Update ability proficiency
await api.updateUserAbility(abilityToAdd.id, 5);Languages Management
// Get available languages
const availableLanguages = await api.getAvailableLanguages();
console.log('Available languages:', availableLanguages.data);
// Add language with proficiency level
const languageToAdd = availableLanguages.data[0];
const addedLanguage = await api.addUserLanguage(languageToAdd.id, 'native');
console.log('Added language:', addedLanguage.data);Portfolio Management
// Get user's portfolio
const portfolio = await api.getUserPortfolio();
console.log('Portfolio items:', portfolio.data);
// Add portfolio item
const newItem = await api.addPortfolioItem({
kind: 'image',
url: 'https://example.com/image.jpg',
caption: 'My headshot',
sort_order: 1
});
console.log('Added portfolio item:', newItem.data);
// Update portfolio item
await api.updatePortfolioItem(newItem.data.id, {
caption: 'Updated headshot caption',
sort_order: 2
});Account Deletion with Grace Period
// Request account deletion (requires password confirmation)
const deletionRequest = await api.requestAccountDeletion('your-password');
console.log('Deletion requested');
console.log('Expiration date:', deletionRequest.data?.expirationDate);
console.log('Days remaining:', deletionRequest.data?.daysRemaining);
// Check deletion status
const status = await api.getAccountDeletionStatus();
if (status.data?.isPending) {
console.log('Account deletion pending');
console.log('Days remaining:', status.data.daysRemaining);
}
// Restore account within grace period
if (status.data?.isPending && status.data.daysRemaining > 0) {
await api.restoreAccount();
console.log('Account restored successfully');
}Configuration
const api = new OneCrewApi(
'https://your-api-url.com', // Base URL
30000, // Timeout in milliseconds (optional)
3 // Number of retries (optional)
);Authentication
The client automatically handles JWT token storage and refresh:
// Login
const authResponse = await api.auth.login({
email: '[email protected]',
password: 'password'
});
// Check if user is authenticated
const isAuthenticated = await api.auth.isAuthenticated();
// Logout
await api.auth.logout();Google Sign-In (Supabase OAuth)
Google sign-in now uses Supabase OAuth. You must first authenticate with Supabase, then send the access token to the backend:
import { createClient } from '@supabase/supabase-js';
// Initialize Supabase client
const supabase = createClient(
'https://your-project.supabase.co',
'your-anon-key'
);
// Option 1: Using signInWithOAuth (redirect flow)
const { data, error } = await supabase.auth.signInWithOAuth({
provider: 'google',
options: {
redirectTo: 'yourapp://auth/callback'
}
});
// After OAuth completes, get the session
const { data: { session } } = await supabase.auth.getSession();
// Send Supabase access token to backend
if (session) {
const authResponse = await api.auth.signInWithGoogle(
session.access_token,
'crew', // category (required for new users)
'director' // primary_role (optional)
);
}
// Option 2: Using signInWithIdToken (if using Google Sign-In SDK)
const { data, error } = await supabase.auth.signInWithIdToken({
provider: 'google',
token: googleIdToken
});
if (data.session) {
await api.auth.signInWithGoogle(data.session.access_token, 'crew');
}Note: Make sure Google OAuth is configured in your Supabase Dashboard (Authentication > Providers > Google).
Apple Sign-In (Supabase OAuth)
Apple sign-in uses Supabase OAuth. You must first authenticate with Supabase, then send the access token to the backend:
import { createClient } from '@supabase/supabase-js';
// Initialize Supabase client
const supabase = createClient(
'https://your-project.supabase.co',
'your-anon-key'
);
// Option 1: Using signInWithOAuth (redirect flow)
const { data, error } = await supabase.auth.signInWithOAuth({
provider: 'apple',
options: {
redirectTo: 'yourapp://auth/callback'
}
});
// After OAuth completes, get the session
const { data: { session } } = await supabase.auth.getSession();
// Send Supabase access token to backend
if (session) {
const authResponse = await api.auth.signInWithApple(
session.access_token,
'crew', // category (required for new users)
'director' // primary_role (optional)
);
}
// Option 2: Using signInWithIdToken (if using native Apple Sign-In SDK)
const { data, error } = await supabase.auth.signInWithIdToken({
provider: 'apple',
token: appleIdToken,
nonce: rawNonce
});
if (data.session) {
await api.auth.signInWithApple(data.session.access_token, 'crew');
}Note: Make sure Apple OAuth is configured in your Supabase Dashboard (Authentication > Providers > Apple). You'll need an Apple Developer account and Service ID setup.
Error Handling
All methods return a consistent response format:
interface ApiResponse<T> {
success: boolean;
data?: T;
error?: string;
message?: string;
}
// Example usage
const response = await api.getUserById('user-id');
if (response.success) {
console.log('User data:', response.data);
} else {
console.error('Error:', response.error);
}TypeScript Support
Full TypeScript support with comprehensive type definitions for all API responses and request parameters.
License
MIT
Support
For support and questions, please contact the OneCrew team.
