UNPKG

@crescender/calendar

Version:

A comprehensive TypeScript calendar library with musician-specific capabilities, architected for client/server separation.

382 lines (377 loc) 10.2 kB
/** * @file Shared types and interfaces for the calendar library. * These types are safe to use in both client and server environments. */ /** * Base interface for a calendar. */ interface ICalendar { id: string; name: string; description?: string; type: string; } /** * Base interface for a venue or location. */ interface IVenue { id: string; name: string; address?: string; city?: string; state?: string; country?: string; website?: string; contactName?: string; contactEmail?: string; contactPhone?: string; notes?: string; } /** * Base interface for a contact (student, band member, promoter, etc.) */ interface IContact { id: string; name: string; email?: string; phone?: string; role?: string; notes?: string; } /** * Base interface for a calendar event. */ interface IEvent { id: string; summary: string; description?: string; start: Date; end: Date; recurrenceRule?: string; type: string; genre?: string; instrument?: string; difficulty?: string; repertoire?: string; setList?: string; equipmentNeeded?: string; dresscode?: string; soundcheckTime?: Date; loadInTime?: Date; paymentStatus?: string; paymentDueDate?: Date; studentLevel?: string; lessonFocus?: string; auditionPiece?: string; auditionRequirements?: string; practiceGoals?: string; rehearsalNotes?: string; status?: string; createdAt: Date; updatedAt: Date; calendarId: string; venueId?: string; primaryContactId?: string; } /** * Base interface for event income. */ interface IEventIncome { id: string; description: string; amount: number; currency: string; notes?: string; eventId: string; } /** * Base interface for event expenses. */ interface IEventExpense { id: string; description: string; amount: number; currency: string; receipt?: string; notes?: string; eventId: string; } /** * Sync token for change tracking. */ interface SyncToken { userId: string; lastSyncedAt: Date; } /** * Changes response for sync operations. */ interface Changes { updated: IEvent[]; deleted: string[]; } /** * Financial summary interface. */ interface FinancialSummary { totalIncome: number; totalExpenses: number; netProfit: number; eventCount: number; averageProfitPerEvent: number; } /** * @file Shared utility functions for the calendar library. * These utilities are safe to use in both client and server environments. */ /** * Formats a date in Australian format (dd/mmm/yyyy). * Uses UTC date to avoid timezone issues in tests. */ declare function formatDateAustralian(date: Date): string; /** * Calculates the duration between two dates in minutes. */ declare function getDurationMinutes(start: Date, end: Date): number; /** * Checks if two dates are on the same day. */ declare function isSameDay(date1: Date, date2: Date): boolean; /** * Gets the start of week (Monday) for a given date. */ declare function getStartOfWeek(date: Date): Date; /** * Gets the end of week (Sunday) for a given date. */ declare function getEndOfWeek(date: Date): Date; /** * Validates an email address. */ declare function isValidEmail(email: string): boolean; /** * Validates a phone number (basic validation). */ declare function isValidPhone(phone: string): boolean; /** * Generates a unique ID (simple implementation for client-side). * Note: For production, use a proper UUID library on the server. */ declare function generateTempId(): string; /** * @file Shared constants for the calendar library. * These constants are safe to use in both client and server environments. */ /** * Default currency for financial calculations. */ declare const DEFAULT_CURRENCY = "AUD"; /** * Maximum event duration in hours. */ declare const MAX_EVENT_DURATION_HOURS = 24; /** * Maximum number of recurrence occurrences. */ declare const MAX_RECURRENCE_OCCURRENCES = 365; /** * Default event duration in minutes. */ declare const DEFAULT_EVENT_DURATION_MINUTES = 60; /** * Maximum field lengths for validation. */ declare const MAX_LENGTHS: { readonly EVENT_TITLE: 200; readonly EVENT_DESCRIPTION: 1000; readonly CALENDAR_NAME: 100; readonly CALENDAR_DESCRIPTION: 500; readonly VENUE_NAME: 200; readonly VENUE_ADDRESS: 300; readonly VENUE_CITY: 100; readonly CONTACT_NAME: 200; readonly CONTACT_ROLE: 100; readonly NOTES: 1000; readonly INCOME_DESCRIPTION: 200; readonly EXPENSE_DESCRIPTION: 200; readonly RECEIPT_PATH: 500; }; /** * Date format patterns for different locales. */ declare const DATE_FORMATS: { readonly AUSTRALIAN: "DD/MM/YYYY"; readonly AMERICAN: "MM/DD/YYYY"; readonly ISO: "YYYY-MM-DD"; }; /** * Time format patterns. */ declare const TIME_FORMATS: { readonly TWELVE_HOUR: "12h"; readonly TWENTY_FOUR_HOUR: "24h"; }; /** * Default calendar view options. */ declare const CALENDAR_VIEWS: { readonly DAY: "day"; readonly WEEK: "week"; readonly MONTH: "month"; readonly LIST: "list"; }; /** * Default start of week (0 = Sunday, 1 = Monday, etc.) */ declare const DEFAULT_START_OF_WEEK = 1; /** * Australian states and territories. */ declare const AUSTRALIAN_STATES: { readonly NSW: "New South Wales"; readonly VIC: "Victoria"; readonly QLD: "Queensland"; readonly WA: "Western Australia"; readonly SA: "South Australia"; readonly TAS: "Tasmania"; readonly ACT: "Australian Capital Territory"; readonly NT: "Northern Territory"; }; /** * Common currency codes. */ declare const CURRENCIES: { readonly AUD: "Australian Dollar"; readonly USD: "US Dollar"; readonly EUR: "Euro"; readonly GBP: "British Pound"; readonly CAD: "Canadian Dollar"; readonly NZD: "New Zealand Dollar"; }; /** * Validation patterns. */ declare const VALIDATION_PATTERNS: { readonly EMAIL: RegExp; readonly PHONE_AU: RegExp; readonly CURRENCY_CODE: RegExp; readonly HEX_COLOR: RegExp; readonly URL: RegExp; }; /** * API configuration constants. */ declare const API_CONFIG: { readonly DEFAULT_PAGE_SIZE: 20; readonly MAX_PAGE_SIZE: 100; readonly REQUEST_TIMEOUT: 30000; readonly RETRY_ATTEMPTS: 3; }; /** * File upload constraints. */ declare const FILE_UPLOAD: { readonly MAX_SIZE_MB: 10; readonly ALLOWED_TYPES: readonly ["image/jpeg", "image/png", "image/gif", "application/pdf"]; readonly ALLOWED_EXTENSIONS: readonly [".jpg", ".jpeg", ".png", ".gif", ".pdf"]; }; /** * @file Shared enums for the calendar library. * These enums are safe to use in both client and server environments. */ /** * Event types for musician-specific functionality. */ declare const EVENT_TYPES: { readonly GIG: "gig"; readonly LESSON: "lesson"; readonly AUDITION: "audition"; readonly PRACTICE: "practice"; readonly REHEARSAL: "rehearsal"; readonly RECORDING: "recording"; readonly MEETING: "meeting"; }; type EventType = typeof EVENT_TYPES[keyof typeof EVENT_TYPES]; /** * Payment status options. */ declare const PAYMENT_STATUS: { readonly PENDING: "Pending"; readonly PAID: "Paid"; readonly OVERDUE: "Overdue"; readonly CANCELLED: "Cancelled"; }; type PaymentStatus = typeof PAYMENT_STATUS[keyof typeof PAYMENT_STATUS]; /** * Event status options. */ declare const EVENT_STATUS: { readonly CONFIRMED: "Confirmed"; readonly TENTATIVE: "Tentative"; readonly CANCELLED: "Cancelled"; readonly COMPLETED: "Completed"; }; type EventStatus = typeof EVENT_STATUS[keyof typeof EVENT_STATUS]; /** * Calendar types. */ declare const CALENDAR_TYPES: { readonly INDIVIDUAL: "individual"; readonly GROUP: "group"; readonly SHARED: "shared"; }; type CalendarType = typeof CALENDAR_TYPES[keyof typeof CALENDAR_TYPES]; /** * Student levels for lessons. */ declare const STUDENT_LEVELS: { readonly BEGINNER: "Beginner"; readonly INTERMEDIATE: "Intermediate"; readonly ADVANCED: "Advanced"; readonly PROFESSIONAL: "Professional"; }; type StudentLevel = typeof STUDENT_LEVELS[keyof typeof STUDENT_LEVELS]; /** * Difficulty levels for pieces/repertoire. */ declare const DIFFICULTY_LEVELS: { readonly EASY: "Easy"; readonly MEDIUM: "Medium"; readonly HARD: "Hard"; readonly EXPERT: "Expert"; }; type DifficultyLevel = typeof DIFFICULTY_LEVELS[keyof typeof DIFFICULTY_LEVELS]; /** * Common musical genres. */ declare const GENRES: { readonly CLASSICAL: "Classical"; readonly JAZZ: "Jazz"; readonly ROCK: "Rock"; readonly POP: "Pop"; readonly BLUES: "Blues"; readonly COUNTRY: "Country"; readonly FOLK: "Folk"; readonly ELECTRONIC: "Electronic"; readonly WORLD: "World Music"; readonly OTHER: "Other"; }; type Genre = typeof GENRES[keyof typeof GENRES]; /** * Common instruments. */ declare const INSTRUMENTS: { readonly PIANO: "Piano"; readonly GUITAR: "Guitar"; readonly VIOLIN: "Violin"; readonly DRUMS: "Drums"; readonly BASS: "Bass"; readonly SAXOPHONE: "Saxophone"; readonly TRUMPET: "Trumpet"; readonly FLUTE: "Flute"; readonly CELLO: "Cello"; readonly VOICE: "Voice"; readonly OTHER: "Other"; }; type Instrument = typeof INSTRUMENTS[keyof typeof INSTRUMENTS]; export { API_CONFIG, AUSTRALIAN_STATES, CALENDAR_TYPES, CALENDAR_VIEWS, CURRENCIES, type CalendarType, type Changes, DATE_FORMATS, DEFAULT_CURRENCY, DEFAULT_EVENT_DURATION_MINUTES, DEFAULT_START_OF_WEEK, DIFFICULTY_LEVELS, type DifficultyLevel, EVENT_STATUS, EVENT_TYPES, type EventStatus, type EventType, FILE_UPLOAD, type FinancialSummary, GENRES, type Genre, type ICalendar, type IContact, type IEvent, type IEventExpense, type IEventIncome, INSTRUMENTS, type IVenue, type Instrument, MAX_EVENT_DURATION_HOURS, MAX_LENGTHS, MAX_RECURRENCE_OCCURRENCES, PAYMENT_STATUS, type PaymentStatus, STUDENT_LEVELS, type StudentLevel, type SyncToken, TIME_FORMATS, VALIDATION_PATTERNS, formatDateAustralian, generateTempId, getDurationMinutes, getEndOfWeek, getStartOfWeek, isSameDay, isValidEmail, isValidPhone };