All files / src/common/api userApi.ts

48.59% Statements 277/570
81.53% Branches 53/65
50% Functions 11/22
48.59% Lines 277/570

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 7771x 1x 1x                                                         1x     1x   1x 5x 5x 5x 5x 5x 5x   5x 3x 1x 1x 2x 2x   2x 5x 5x     1x 2x 2x   1x 1x 1x 1x 1x   2x             1x 2x 2x     1x         1x         5x 5x   5x 1x 1x 5x 1x 1x     3x 5x 1x 1x     2x 2x 2x 2x 2x   5x 1x 1x                                                                 5x 5x     1x           4x 4x   4x 2x 2x 1x 1x     1x 1x 1x 1x 1x 1x   1x 1x 1x 2x   2x 2x 2x   2x 4x 4x 4x   2x 2x 2x 2x 2x 2x   4x 1x 4x 4x     1x 2x 2x   2x 1x 2x 2x     1x                                       1x                                                                                                                                                                 1x                                                                                         1x                                                                                                         1x                               1x                                                         1x                     1x 4x   4x 4x 4x 4x 4x   4x 4x 4x 4x   4x 4x 4x 4x 4x 4x 4x 4x 4x   4x 4x 4x 4x     1x                                         1x 3x 3x 3x 3x   3x 3x 1x 1x     2x 3x 1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 1x   3x 1x 3x 3x     1x 2x 2x   2x 1x 1x 1x   2x 2x 2x 2x 2x 2x 2x 2x 2x   2x 2x 2x 2x     1x           1x 1x 1x   1x 1x 1x 1x     1x 1x 1x 1x     1x 1x 1x 1x     1x 1x 1x 1x     1x 1x 1x 1x     1x   1x 1x 1x 1x 1x 1x 1x 1x 1x     1x 2x 2x 2x 2x   2x 1x 1x   1x 1x 1x 1x 1x   2x 1x 1x   2x 1x 1x   1x   2x 1x 2x 2x     1x                                                             1x           1x 1x 1x   1x                               1x 1x 1x 1x 1x 1x 1x 1x 1x     1x                                       1x     1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x  
import { generateEmailAliasFromEmail } from '../utils/emailAlias';
import { logger } from '../utils/logger';
import {
  handleSupabaseError,
  requireAuth,
  supabase,
  withPerformanceLogging,
} from './supabaseClient';
 
interface UserProfile {
  id: string;
  email: string;
  email_alias?: string;
  full_name?: string;
  avatar_url?: string;
  created_at: string;
  updated_at: string;
}
 
interface EmailAliasResult {
  email: string;
  error?: string;
}
 
interface UpdateUserParams {
  full_name?: string;
  avatar_url?: string;
  email_alias?: string;
}
 
// Initialize logger
const log = logger;
 
// User API Service
export const userApi = {
  // Get user by ID
  async getById(id: string): Promise<UserProfile | null> {
    return withPerformanceLogging('user.getById', async () => {
      const { data, error } = await supabase
        .from('users')
        .select('id, email, full_name, created_at, updated_at')
        .eq('id', id)
        .single();
 
      if (error) {
        if (error.code === 'PGRST116') {
          return null; // Not found
        }
        handleSupabaseError(error);
      }
 
      return data;
    });
  },
 
  // Get current user profile
  async getCurrentUser(): Promise<UserProfile | null> {
    return withPerformanceLogging('user.getCurrentUser', async () => {
      const user = await requireAuth();
 
      const { data, error } = await supabase
        .from('users')
        .select('id, email, full_name, created_at, updated_at')
        .eq('id', user.id)
        .single();
 
      if (error) {
        if (error.code === 'PGRST116') {
          return null; // Not found
        }
        handleSupabaseError(error);
      }
 
      return data;
    });
  },
 
  // Get current user profile (alias)
  async getProfile(): Promise<UserProfile | null> {
    return this.getCurrentUser();
  },
 
  // Create a new user
  async create(params: {
    email: string;
    name: string;
    avatar_url?: string;
    preferences?: any;
  }): Promise<UserProfile> {
    return withPerformanceLogging('user.create', async () => {
      // Validate required fields
      if (!params.email) {
        throw new Error('Email is required');
      }
      if (!params.name) {
        throw new Error('Name is required');
      }
 
      // Validate email format
      const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
      if (!emailRegex.test(params.email)) {
        throw new Error('Invalid email format');
      }
 
      // Check for duplicate email
      const { data: existingUser } = await supabase
        .from('users')
        .select('id')
        .eq('email', params.email)
        .maybeSingle();
 
      if (existingUser) {
        throw new Error('User with this email already exists');
      }
 
      // Create user with default preferences
      const defaultPreferences = {
        theme: 'light',
        notifications: {
          email: true,
          push: false,
          newsletter_digest: true,
        },
        reading: {
          auto_mark_read: false,
          reading_speed: 200,
          preferred_view: 'list',
        },
        ...params.preferences,
      };
 
      const { data, error } = await supabase
        .from('users')
        .insert({
          email: params.email,
          full_name: params.name,
          avatar_url: params.avatar_url,
          preferences: defaultPreferences,
          created_at: new Date().toISOString(),
          updated_at: new Date().toISOString(),
        })
        .select()
        .single();
 
      if (error) handleSupabaseError(error);
      return data;
    });
  },
 
  // Update user
  async update(params: {
    id: string;
    name?: string;
    email?: string;
    avatar_url?: string;
    preferences?: any;
  }): Promise<UserProfile> {
    return withPerformanceLogging('user.update', async () => {
      // Validate email format if provided
      if (params.email) {
        const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
        if (!emailRegex.test(params.email)) {
          throw new Error('Invalid email format');
        }
 
        // Check for duplicate email
        const { data: existingUser } = await supabase
          .from('users')
          .select('id')
          .eq('email', params.email)
          .neq('id', params.id)
          .maybeSingle();
 
        if (existingUser) {
          throw new Error('User with this email already exists');
        }
      }
 
      const updateData: any = {
        updated_at: new Date().toISOString(),
      };
 
      if (params.name !== undefined) updateData.full_name = params.name;
      if (params.email !== undefined) updateData.email = params.email;
      if (params.avatar_url !== undefined) updateData.avatar_url = params.avatar_url;
      if (params.preferences !== undefined) updateData.preferences = params.preferences;
 
      const { data, error } = await supabase
        .from('users')
        .update(updateData)
        .eq('id', params.id)
        .select()
        .single();
 
      if (error) handleSupabaseError(error);
      return data;
    });
  },
 
  // Delete user
  async delete(id: string): Promise<boolean> {
    return withPerformanceLogging('user.delete', async () => {
      const { error } = await supabase.from('users').delete().eq('id', id);
 
      if (error) handleSupabaseError(error);
      return true;
    });
  },
 
  // Update user profile
  async updateProfile(updates: UpdateUserParams): Promise<UserProfile> {
    return withPerformanceLogging('user.updateProfile', async () => {
      const user = await requireAuth();
 
      const { data, error } = await supabase
        .from('users')
        .update({
          ...updates,
          updated_at: new Date().toISOString(),
        })
        .eq('id', user.id)
        .select()
        .single();
 
      if (error) handleSupabaseError(error);
      return data;
    });
  },
 
  // Generate a unique email alias for a user
  async generateEmailAlias(email: string): Promise<EmailAliasResult> {
    return withPerformanceLogging('user.generateEmailAlias', async () => {
      const user = await requireAuth();
      let emailAlias = generateEmailAliasFromEmail(email);
      let isUnique = false;
      let attempts = 0;
      const maxAttempts = 5;
 
      try {
        // Try to find a unique email alias
        while (!isUnique && attempts < maxAttempts) {
          try {
            // Check if the alias already exists
            const { data: existingUser } = await supabase
              .from('user_profiles')
              .select('id')
              .eq('email_alias', emailAlias)
              .single();
 
            if (!existingUser) {
              // Alias is available
              isUnique = true;
            } else {
              // Generate a new alias with random numbers
              attempts++;
              const randomSuffix = Math.floor(1000 + Math.random() * 9000); // 4-digit random number
              const baseAlias = emailAlias.split('@')[0];
              emailAlias = `${baseAlias}${randomSuffix}@${emailAlias.split('@')[1]}`;
 
              log.info('Email alias already exists, trying with suffix', {
                component: 'UserApi',
                metadata: {
                  userId: user.id,
                  originalAlias: generateEmailAliasFromEmail(email),
                  newAlias: emailAlias,
                  attempt: attempts
                }
              });
            }
          } catch (_error) {
            // If there's an error checking the alias, assume it's available
            isUnique = true;
          }
        }
 
        // Save to the database
        const { error } = await supabase
          .from('users')
          .update({ email_alias: emailAlias })
          .eq('id', user.id);
 
        if (error) {
          log.error(
            'Error saving email alias',
            {
              component: 'UserApi',
              action: 'save_email_alias',
              metadata: { userId: user.id },
            },
            error
          );
          return { email: '', error: 'Failed to save email alias' };
        }
 
        return { email: emailAlias };
      } catch (error) {
        log.error(
          'Error generating email alias',
          {
            component: 'UserApi',
            action: 'generate_email_alias',
            metadata: { email },
          },
          error instanceof Error ? error : new Error(String(error))
        );
        return { email: '', error: 'Failed to generate email alias' };
      }
    });
  },
 
  // Get or create an email alias for the current user
  async getEmailAlias(): Promise<string> {
    return withPerformanceLogging('user.getEmailAlias', async () => {
      const user = await requireAuth();
 
      try {
        // First check if user already has an email alias
        const { data: userData } = await supabase
          .from('users')
          .select('email_alias')
          .eq('id', user.id)
          .single();
 
        // If we got the user data and they have an alias, return it
        if (userData?.email_alias) {
          return userData.email_alias;
        }
 
        // If no alias exists, generate a new one
        if (!user.email) {
          throw new Error('User email not found');
        }
 
        const { email, error: genError } = await this.generateEmailAlias(user.email);
 
        if (genError || !email) {
          throw new Error(genError || 'Failed to generate email alias');
        }
 
        return email;
      } catch (error) {
        log.error(
          'Error in getEmailAlias',
          {
            component: 'UserApi',
            action: 'get_email_alias',
            metadata: { userId: user.id },
          },
          error instanceof Error ? error : new Error(String(error))
        );
        throw error;
      }
    });
  },
 
  // Update a user's email alias
  async updateEmailAlias(newAlias: string): Promise<EmailAliasResult> {
    return withPerformanceLogging('user.updateEmailAlias', async () => {
      const user = await requireAuth();
 
      try {
        // Check if the alias is already taken
        const { data } = await supabase
          .from('users')
          .select('id')
          .eq('email_alias', newAlias)
          .neq('id', user.id)
          .maybeSingle();
 
        if (data) {
          return { email: '', error: 'This email alias is already taken' };
        }
 
        // Update the user's email alias
        const { error: updateError } = await supabase
          .from('users')
          .update({ email_alias: newAlias })
          .eq('id', user.id);
 
        if (updateError) {
          log.error(
            'Error updating user with email alias',
            {
              component: 'UserApi',
              action: 'update_email_alias',
              metadata: { userId: user.id, newAlias },
            },
            updateError
          );
          return { email: '', error: 'Error saving email alias' };
        }
 
        return { email: newAlias };
      } catch (error) {
        log.error(
          'Error in updateEmailAlias',
          {
            component: 'UserApi',
            action: 'update_email_alias',
            metadata: { userId: user.id, newAlias },
          },
          error instanceof Error ? error : new Error(String(error))
        );
        return { email: '', error: 'Internal server error' };
      }
    });
  },
 
  // Check if email alias is available
  async isEmailAliasAvailable(alias: string): Promise<boolean> {
    return withPerformanceLogging('user.isEmailAliasAvailable', async () => {
      const user = await requireAuth();
 
      const { data } = await supabase
        .from('users')
        .select('id')
        .eq('email_alias', alias)
        .neq('id', user.id)
        .maybeSingle();
 
      return !data; // Available if no data found
    });
  },
 
  // Delete user account and all associated data
  async deleteAccount(): Promise<boolean> {
    return withPerformanceLogging('user.deleteAccount', async () => {
      const user = await requireAuth();
 
      // Note: This should cascade delete related data based on your database constraints
      const { error } = await supabase.from('users').delete().eq('id', user.id);
 
      if (error) handleSupabaseError(error);
 
      // Also delete from auth
      const { error: authError } = await supabase.auth.admin.deleteUser(user.id);
      if (authError) {
        log.error(
          'Error deleting user from auth',
          {
            component: 'UserApi',
            action: 'delete_user',
            metadata: { userId: user.id },
          },
          authError
        );
        // Continue anyway as the user data is deleted
      }
 
      return true;
    });
  },
 
  // Get user statistics (alias for current user)
  async getStats(): Promise<{
    newslettersCount: number;
    tagsCount: number;
    sourcesCount: number;
    readingQueueCount: number;
    joinedAt: string;
  }> {
    return this.getUserStats();
  },
 
  // Update user preferences (new signature for tests)
  async updatePreferences(userId: string, preferences: Record<string, unknown>): Promise<any> {
    return withPerformanceLogging('user.updatePreferences', async () => {
      // Get existing user to merge preferences
      const { data: existingUser } = await supabase
        .from('users')
        .select('preferences')
        .eq('id', userId)
        .single();
 
      const mergedPreferences = {
        ...existingUser?.preferences,
        ...preferences,
      };
 
      const { data, error } = await supabase
        .from('users')
        .update({
          preferences: mergedPreferences,
          updated_at: new Date().toISOString(),
        })
        .eq('id', userId)
        .select()
        .single();
 
      if (error) handleSupabaseError(error);
      return data;
    });
  },
 
  // Update user preferences (original method)
  async updateUserPreferences(preferences: Record<string, unknown>): Promise<boolean> {
    return withPerformanceLogging('user.updateUserPreferences', async () => {
      const user = await requireAuth();
 
      const { error } = await supabase.from('user_preferences').upsert(
        {
          user_id: user.id,
          preferences,
          updated_at: new Date().toISOString(),
        },
        {
          onConflict: 'user_id',
        }
      );
 
      if (error) handleSupabaseError(error);
      return true;
    });
  },
 
  // Update user subscription
  async updateSubscription(
    userId: string,
    subscription: { plan: string; status: string }
  ): Promise<any> {
    return withPerformanceLogging('user.updateSubscription', async () => {
      // Validate subscription plan
      const validPlans = ['free', 'premium', 'enterprise'];
      if (!validPlans.includes(subscription.plan)) {
        throw new Error('Invalid subscription plan');
      }
 
      // Validate subscription status
      const validStatuses = ['active', 'inactive', 'cancelled', 'expired'];
      if (!validStatuses.includes(subscription.status)) {
        throw new Error('Invalid subscription status');
      }
 
      const { data, error } = await supabase
        .from('users')
        .update({
          subscription,
          updated_at: new Date().toISOString(),
        })
        .eq('id', userId)
        .select()
        .single();
 
      if (error) handleSupabaseError(error);
      return data;
    });
  },
 
  // Update last login timestamp
  async updateLastLogin(userId?: string): Promise<any> {
    return withPerformanceLogging('user.updateLastLogin', async () => {
      let targetUserId = userId;
 
      if (!targetUserId) {
        const user = await requireAuth();
        targetUserId = user.id;
      }
 
      const { data, error } = await supabase
        .from('users')
        .update({
          last_login_at: new Date().toISOString(),
          updated_at: new Date().toISOString(),
        })
        .eq('id', targetUserId)
        .select()
        .single();
 
      if (error) handleSupabaseError(error);
      return data;
    });
  },
 
  // Get user statistics
  async getUserStats(userId?: string): Promise<{
    newslettersCount: number;
    tagsCount: number;
    sourcesCount: number;
    readingQueueCount: number;
    joinedAt: string;
  }> {
    return withPerformanceLogging('user.getUserStats', async () => {
      let targetUserId = userId;
 
      if (!targetUserId) {
        const user = await requireAuth();
        targetUserId = user.id;
      }
 
      // Get newsletters count
      const { count: newslettersCount } = await supabase
        .from('newsletters')
        .select('id', { count: 'exact', head: true })
        .eq('user_id', targetUserId);
 
      // Get tags count
      const { count: tagsCount } = await supabase
        .from('tags')
        .select('id', { count: 'exact', head: true })
        .eq('user_id', targetUserId);
 
      // Get sources count
      const { count: sourcesCount } = await supabase
        .from('newsletter_sources')
        .select('id', { count: 'exact', head: true })
        .eq('user_id', targetUserId);
 
      // Get reading queue count
      const { count: readingQueueCount } = await supabase
        .from('reading_queue')
        .select('id', { count: 'exact', head: true })
        .eq('user_id', targetUserId);
 
      // Get user profile for join date
      const userProfile = await this.getById(targetUserId);
 
      return {
        newslettersCount: newslettersCount || 0,
        tagsCount: tagsCount || 0,
        sourcesCount: sourcesCount || 0,
        readingQueueCount: readingQueueCount || 0,
        joinedAt: userProfile?.created_at || new Date().toISOString(),
      };
    });
  },
 
  // Search users
  async searchUsers(
    query: string,
    options?: { limit?: number; offset?: number }
  ): Promise<UserProfile[]> {
    return withPerformanceLogging('user.searchUsers', async () => {
      // Validate search query length
      if (query.length < 2) {
        throw new Error('Search query must be at least 2 characters long');
      }
 
      let searchQuery = supabase
        .from('users')
        .select('id, email, full_name, created_at, updated_at')
        .or(`full_name.ilike.%${query}%,email.ilike.%${query}%`)
        .order('full_name');
 
      if (options?.limit) {
        searchQuery = searchQuery.limit(options.limit);
      }
 
      if (options?.offset) {
        searchQuery = searchQuery.range(options.offset, options.offset + (options.limit || 10) - 1);
      }
 
      const { data, error } = await searchQuery;
 
      if (error) handleSupabaseError(error);
      return data || [];
    });
  },
 
  // Bulk update users
  async bulkUpdate(
    updates: Array<{ id: string;[key: string]: any }>
  ): Promise<{ successCount: number; failures: Array<{ id: string; error: string }> }> {
    return withPerformanceLogging('user.bulkUpdate', async () => {
      // Validate bulk update input
      if (!Array.isArray(updates) || updates.length === 0) {
        throw new Error('Updates array is required and cannot be empty');
      }
 
      const results = {
        successCount: 0,
        failures: [] as Array<{ id: string; error: string }>,
      };
 
      for (const update of updates) {
        try {
          await this.update(update);
          results.successCount++;
        } catch (error) {
          results.failures.push({
            id: update.id,
            error: error instanceof Error ? error.message : 'Unknown error',
          });
        }
      }
 
      return results;
    });
  },
 
  // Export user data
  async exportUserData(userId: string): Promise<{
    user: UserProfile;
    newsletters: any[];
    tags: any[];
    sources: any[];
    readingQueue: any[];
  }> {
    return withPerformanceLogging('user.exportUserData', async () => {
      try {
        // Get user profile
        const user = await this.getById(userId);
        if (!user) {
          throw new Error('User not found');
        }
 
        // Get all user data with optimized queries (explicit columns and limits)
        const [newsletters, tags, sources, readingQueue] = await Promise.all([
          supabase.from('newsletters').select('id, title, content, summary, image_url, newsletter_source_id, word_count, estimated_read_time, is_read, is_liked, is_archived, received_at, created_at, updated_at, user_id').eq('user_id', userId).limit(10000),
          supabase.from('tags').select('id, name, color, created_at, updated_at, user_id').eq('user_id', userId).limit(1000),
          supabase.from('newsletter_sources').select('id, name, from, is_archived, created_at, updated_at, user_id').eq('user_id', userId).limit(1000),
          supabase.from('reading_queue').select('id, user_id, newsletter_id, position, priority, notes, added_at, updated_at').eq('user_id', userId).limit(1000),
        ]);
 
        return {
          user,
          newsletters: newsletters.data || [],
          tags: tags.data || [],
          sources: sources.data || [],
          readingQueue: readingQueue.data || [],
        };
      } catch (_) {
        throw new Error('Failed to export user data');
      }
    });
  },
 
  // Get user preferences
  async getPreferences(): Promise<Record<string, unknown> | null> {
    return withPerformanceLogging('user.getPreferences', async () => {
      const user = await requireAuth();
 
      const { data, error } = await supabase
        .from('user_preferences')
        .select('preferences')
        .eq('user_id', user.id)
        .single();
 
      if (error) {
        if (error.code === 'PGRST116') {
          return null; // No preferences found
        }
        handleSupabaseError(error);
      }
 
      return data?.preferences || null;
    });
  },
};
 
// Export individual functions for backward compatibility
export const {
  getById,
  getCurrentUser,
  getProfile: getUserProfile,
  create,
  update,
  delete: deleteUser,
  updateProfile: updateUserProfile,
  generateEmailAlias,
  getEmailAlias: getUserEmailAlias,
  updateEmailAlias,
  isEmailAliasAvailable,
  deleteAccount: deleteUserAccount,
  getStats,
  getUserStats,
  updatePreferences,
  updateUserPreferences,
  getPreferences: getUserPreferences,
  updateSubscription,
  updateLastLogin,
  searchUsers,
  bulkUpdate,
  exportUserData,
} = userApi;
 
export default userApi;