Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
VITE_PAYMENTS_API_URL=
VITE_MAIL_API_URL=
VITE_DRIVE_API_URL=
VITE_MAGIC_IV=
VITE_MAGIC_SALT=
Expand Down
53 changes: 39 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"dependencies": {
"@internxt/css-config": "^1.1.0",
"@internxt/lib": "^1.4.1",
"@internxt/sdk": "^1.15.1",
"@internxt/sdk": "^1.15.7",
"@internxt/ui": "^0.1.11",
"@phosphor-icons/react": "^2.1.10",
"@reduxjs/toolkit": "^2.11.2",
Expand Down
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sonar.projectName=mail-web
sonar.sources=src
sonar.tests=src
sonar.test.inclusions=src/**/*.test.ts,src/**/*.test.tsx
sonar.coverage.exclusions=src/**/*.tsx,**/*.errors.ts,types/**,src/test-utils/**,**/constants.ts
sonar.coverage.exclusions=src/**/*.tsx,src/errors/**,**/*.errors.ts,types/**,src/test-utils/**,**/constants.ts
sonar.javascript.lcov.reportPaths=coverage/lcov.info
sonar.exclusions=**/*.json,**/assets/**,**/*.css,test-utils/**
sonar.cpd.exclusions=**/*.json,**/assets/**,**/*.css
6 changes: 4 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { routes } from './routes';
import { NavigationService } from './services/navigation';
import { Activity, useEffect } from 'react';
import { useAppDispatch } from './store/hooks';
import { initializeUserThunk } from './store/slices/user/thunks';
import { initializeUserThunk, refreshAvatarThunk } from './store/slices/user/thunks';
import { Toaster } from 'react-hot-toast';
import { ActionDialog, useActionDialog } from './context/dialog-manager';
import { ComposeMessageDialog } from './components/compose-message';
Expand All @@ -19,7 +19,9 @@ function App() {
const isComposeMessageDialogOpen = isDialogOpen(ActionDialog.ComposeMessage);

useEffect(() => {
dispatch(initializeUserThunk());
dispatch(initializeUserThunk())
.unwrap()
.then(() => dispatch(refreshAvatarThunk()));
}, []);

return (
Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions src/errors/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from './config';
export * from './navigation';
export * from './oauth';
export * from './storage';
export * from './shared';
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,15 @@ export class AuthTimeoutError extends Error {

export class OpenAuthPopupError extends Error {
constructor() {
super(
'Failed to open authentication popup. Please check your popup blocker settings.',
);
super('Failed to open authentication popup. Please check your popup blocker settings.');

Object.setPrototypeOf(this, OpenAuthPopupError.prototype);
}
}

export class WebAuthProcessingError extends Error {
constructor(cause?: Error) {
super(
`Web authentication processing failed: ${cause instanceof Error ? cause.message : 'Unknown error'}`,
);
super(`Web authentication processing failed: ${cause instanceof Error ? cause.message : 'Unknown error'}`);

Object.setPrototypeOf(this, WebAuthProcessingError.prototype);
}
Expand Down
7 changes: 7 additions & 0 deletions src/errors/shared/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export class UserNotFoundError extends Error {
constructor() {
super('User not found');

Object.setPrototypeOf(this, UserNotFoundError.prototype);
}
}
File renamed without changes.
12 changes: 6 additions & 6 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { ThemeProvider } from './context/theme/ThemeProvider.tsx';
import { LiveChatLoaderProvider } from 'react-live-chat-loader';
import { ConfigService } from './services/config/index.ts';

store.dispatch(userActions.initialize());
store.dispatch(userActions.hydrate());

createRoot(document.getElementById('root')!).render(
<StrictMode>
Expand All @@ -21,11 +21,11 @@ createRoot(document.getElementById('root')!).render(
>
<ThemeProvider>
<TranslationProvider>
<DialogManagerProvider>
<Provider store={store}>
<App />
</Provider>
</DialogManagerProvider>
<DialogManagerProvider>
<Provider store={store}>
<App />
</Provider>
</DialogManagerProvider>
</TranslationProvider>
</ThemeProvider>
</LiveChatLoaderProvider>
Expand Down
2 changes: 1 addition & 1 deletion src/services/config/config.service.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, vi, beforeEach, test, afterEach } from 'vitest';
import { VariableNotFoundError } from './config.errors';
import { VariableNotFoundError } from '@/errors';
import notificationsService, { ToastType } from '../notifications';

import { ConfigService } from '.';
Expand Down
2 changes: 1 addition & 1 deletion src/services/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Translate } from '@/i18n';
import notificationsService, { ToastType } from '../notifications';
import { VariableNotFoundError } from './config.errors';
import { VariableNotFoundError } from '@/errors';
import {
APP_VERSION_MATCHERS,
PLATFORM_MATCHERS,
Expand Down
2 changes: 1 addition & 1 deletion src/services/navigation/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getRouteConfig, getViewByPath, type AppView } from '@/routes/paths';
import type { NavigateFunction, RouterNavigateOptions } from 'react-router-dom';
import { NavigationNotInitializedError } from './navigation.errors';
import { NavigationNotInitializedError } from '@/errors';

export class NavigationService {
static readonly instance = new NavigationService();
Expand Down
2 changes: 1 addition & 1 deletion src/services/navigation/navigation.service.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { describe, expect, test, vi, beforeEach } from 'vitest';
import { NavigationService } from './index';
import { NavigationNotInitializedError } from './navigation.errors';
import { NavigationNotInitializedError } from '@/errors';
import { AppView } from '@/routes/paths';
import type { NavigateFunction } from 'react-router-dom';

Expand Down
2 changes: 1 addition & 1 deletion src/services/oauth/oauth.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { OauthService } from './oauth.service';
import { UserService } from '../user/user.service';
import { LocalStorageService } from '../local-storage';
import { WEB_AUTH_CONFIG, WEB_AUTH_MESSAGE_TYPES, type WebAuthMessage, type WebAuthParams } from '@/types/oauth';
import { AuthCancelledByUserError, MissingAuthParamsToken, WebAuthProcessingError } from './errors/oauth.errors';
import { AuthCancelledByUserError, MissingAuthParamsToken, WebAuthProcessingError } from '@/errors';
import { getMockedUser } from '@/test-utils/fixtures';

vi.mock('../config', () => ({
Expand Down
2 changes: 1 addition & 1 deletion src/services/oauth/oauth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
MissingAuthParamsToken,
OpenAuthPopupError,
WebAuthProcessingError,
} from './errors/oauth.errors';
} from '@/errors';
import type { UserSettings } from '@internxt/sdk/dist/shared/types/userSettings';
import { LocalStorageService } from '../local-storage';

Expand Down
27 changes: 20 additions & 7 deletions src/services/sdk/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Auth, Drive } from '@internxt/sdk';
import { Auth, Drive, Mail } from '@internxt/sdk';
import type { ApiSecurity, AppDetails } from '@internxt/sdk/dist/shared';
import packageJson from '../../../package.json';
import { ConfigService } from '../config';
Expand Down Expand Up @@ -58,33 +58,46 @@ export class SdkManager {
});
const appDetails = SdkManager.getAppDetails();

return Auth.client(this.apiUrl, appDetails, apiSecurity);
return Auth.client(this.driveApiUrl, appDetails, apiSecurity);
}

getUsers(): Drive.Users {
const apiSecurity = this.getNewTokenApiSecurity();
const appDetails = SdkManager.getAppDetails();

return Drive.Users.client(this.apiUrl, appDetails, apiSecurity);
return Drive.Users.client(this.driveApiUrl, appDetails, apiSecurity);
}

getStorage(): Drive.Storage {
const apiSecurity = this.getNewTokenApiSecurity();
const appDetails = SdkManager.getAppDetails();

return Drive.Storage.client(this.apiUrl, appDetails, apiSecurity);
return Drive.Storage.client(this.driveApiUrl, appDetails, apiSecurity);
}

getPayments(): Drive.Payments {
const paymentsApi = ConfigService.instance.getVariable('PAYMENTS_API_URL');
const apiSecurity = this.getNewTokenApiSecurity();
const appDetails = SdkManager.getAppDetails();

return Drive.Payments.client(this.paymentsApiUrl, appDetails, apiSecurity);
}

getMail(): Mail {
const apiSecurity = this.getNewTokenApiSecurity();
const appDetails = SdkManager.getAppDetails();

return Drive.Payments.client(paymentsApi, appDetails, apiSecurity);
return Mail.client(this.mailApiUrl, appDetails, apiSecurity);
}

get apiUrl(): string {
get driveApiUrl(): string {
return ConfigService.instance.getVariable('DRIVE_API_URL');
}

get mailApiUrl(): string {
return ConfigService.instance.getVariable('MAIL_API_URL');
}

get paymentsApiUrl(): string {
return ConfigService.instance.getVariable('PAYMENTS_API_URL');
}
}
39 changes: 39 additions & 0 deletions src/services/sdk/mail/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import type { EmailListResponse, ListEmailsQuery, MailboxResponse, UpdateEmailRequest } from '@internxt/sdk';
import { SdkManager } from '..';

export class MailService {
public static readonly instance: MailService = new MailService();

get client() {
return SdkManager.instance.getMail();
}

/**
* Returns a list of all mailboxes and their properties.
*
* @returns A promise that resolves with an array of MailboxResponse objects.
*/
async getMailboxesInfo(): Promise<MailboxResponse[]> {
return this.client.getMailboxes();
}

/**
* Returns a list of emails in the given folder.
*
* @param {ListEmailsQuery} query - The query parameters
* @returns A promise that resolves with an EmailListResponse object
*/
async listFolder(query?: ListEmailsQuery): Promise<EmailListResponse> {
return this.client.listEmails(query);
}

/**
* Updates the status of a specific email.
* @param {string} emailId - The ID of the email to update
* @param {UpdateEmailRequest} status - The new status of the email
* @returns A promise that resolves when the update operation is complete
*/
async updateEmailStatus(emailId: string, status: UpdateEmailRequest): Promise<void> {
return this.client.updateEmail(emailId, status);
}
}
Loading
Loading