From db9ce5a0c80edf29adc5b73364c87659a87afeac Mon Sep 17 00:00:00 2001 From: jaaaaavier Date: Mon, 9 Feb 2026 14:48:59 +0100 Subject: [PATCH] Revert "[_]: feat/upgrade SDK version when fetching the user location" --- package.json | 2 +- src/app/core/factory/sdk/index.test.ts | 34 -------------------------- src/app/core/factory/sdk/index.ts | 8 ------ src/utils/userLocation.test.ts | 33 ++++++++++++++----------- src/utils/userLocation.ts | 7 +++--- yarn.lock | 8 +++--- 6 files changed, 27 insertions(+), 65 deletions(-) diff --git a/package.json b/package.json index cb53e70ca1..0e4b288e9d 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "@iconscout/react-unicons": "^1.1.6", "@internxt/css-config": "1.1.0", "@internxt/lib": "1.4.1", - "@internxt/sdk": "=1.12.4", + "@internxt/sdk": "=1.12.0", "@internxt/ui": "0.1.1", "@phosphor-icons/react": "^2.1.7", "@popperjs/core": "^2.11.6", diff --git a/src/app/core/factory/sdk/index.test.ts b/src/app/core/factory/sdk/index.test.ts index f4cc870df2..020018c136 100644 --- a/src/app/core/factory/sdk/index.test.ts +++ b/src/app/core/factory/sdk/index.test.ts @@ -7,11 +7,9 @@ import { STORAGE_KEYS } from 'services/storage-keys'; import { Share, Users } from '@internxt/sdk/dist/drive'; import packageJson from '../../../../../package.json'; import { Auth } from '@internxt/sdk/dist/auth'; -import { Location } from '@internxt/sdk'; const MOCKED_NEW_API = 'https://api.internxt.com'; const MOCKED_PAYMENTS = 'https://payments.internxt.com'; -const MOCKED_LOCATION = 'https://location.internxt.com'; vi.mock('@internxt/sdk/dist/drive', () => ({ Users: { @@ -28,18 +26,11 @@ vi.mock('@internxt/sdk/dist/auth', () => ({ }, })); -vi.mock('@internxt/sdk', () => ({ - Location: { - client: vi.fn(), - }, -})); - vi.mock('services/env.service', () => ({ default: { getVariable: vi.fn((key: string) => { if (key === 'newApi') return MOCKED_NEW_API; if (key === 'payments') return MOCKED_PAYMENTS; - if (key === 'location') return MOCKED_LOCATION; return ''; }), }, @@ -347,30 +338,5 @@ describe('SdkFactory', () => { ); }); }); - - describe('Creating the location client', () => { - test('When the Location client is created, then it uses the location API URL and default app details', () => { - const mockToken = 'test-token'; - const mockWorkspace = Workspace.Individuals; - - vi.spyOn(mockLocalStorage, 'getWorkspace').mockReturnValue(mockWorkspace); - vi.spyOn(mockLocalStorage, 'get').mockImplementation((key: string) => { - if (key === 'xNewToken') return mockToken; - return null; - }); - - const instance = SdkFactory.getNewApiInstance(); - instance.createLocationClient(); - - expect(Location.client).toHaveBeenCalledWith( - MOCKED_LOCATION, - { - clientName: packageJson.name, - clientVersion: packageJson.version, - }, - expect.any(Object), - ); - }); - }); }); }); diff --git a/src/app/core/factory/sdk/index.ts b/src/app/core/factory/sdk/index.ts index 59216df33e..fffb2569d8 100644 --- a/src/app/core/factory/sdk/index.ts +++ b/src/app/core/factory/sdk/index.ts @@ -10,7 +10,6 @@ import { Workspace } from '../../types'; import { Checkout } from '@internxt/sdk/dist/payments'; import envService from 'services/env.service'; import { STORAGE_KEYS } from 'services/storage-keys'; -import { Location } from '@internxt/sdk'; export class SdkFactory { private static sdk: { @@ -114,13 +113,6 @@ export class SdkFactory { return Backups.client(apiUrl, appDetails, apiSecurity); } - public createLocationClient(): Location { - const apiUrl = envService.getVariable('location'); - const appDetails = SdkFactory.getAppDetails(); - const apiSecurity = this.getNewApiSecurity(); - return Location.client(apiUrl, appDetails, apiSecurity); - } - /** Helpers **/ private getNewApiSecurity(unauthorizedCallback?: () => void): ApiSecurity { diff --git a/src/utils/userLocation.test.ts b/src/utils/userLocation.test.ts index 1882a1fde9..4a9682c0ed 100644 --- a/src/utils/userLocation.test.ts +++ b/src/utils/userLocation.test.ts @@ -1,10 +1,21 @@ -import { describe, it, expect, vi, beforeEach } from 'vitest'; +// tests/userLocation.test.ts +import { describe, it, expect, vi, beforeEach, Mock } from 'vitest'; +import * as sdk from '@internxt/sdk'; import { userLocation } from './userLocation'; -import { SdkFactory } from 'app/core/factory/sdk'; -vi.mock('app/core/factory/sdk', () => ({ - SdkFactory: { - getNewApiInstance: vi.fn(), +vi.mock('@internxt/sdk', async () => { + const actual = await vi.importActual('@internxt/sdk'); + return { + ...actual, + getUserLocation: vi.fn(), + }; +}); + +vi.mock('../../config', () => ({ + envConfig: { + api: { + location: 'https://mocked-location-api.com', + }, }, })); @@ -14,21 +25,15 @@ describe('User location function', () => { location: 'ES', }; - const mockGetUserLocation = vi.fn(); - const mockCreateLocationClient = vi.fn(); - beforeEach(() => { vi.clearAllMocks(); - mockGetUserLocation.mockResolvedValue(mockedLocation); - mockCreateLocationClient.mockReturnValue({ getUserLocation: mockGetUserLocation }); - vi.mocked(SdkFactory.getNewApiInstance).mockReturnValue({ - createLocationClient: mockCreateLocationClient, - } as unknown as SdkFactory); + vi.resetModules(); + (sdk.getUserLocation as Mock).mockResolvedValue(mockedLocation); }); it('When the user location is requested, then the IP and country are returned', async () => { const result = await userLocation(); - expect(result).toStrictEqual(mockedLocation); + expect(result).toEqual(mockedLocation); }); }); diff --git a/src/utils/userLocation.ts b/src/utils/userLocation.ts index eaf35f6bcc..24d3d0e6cd 100644 --- a/src/utils/userLocation.ts +++ b/src/utils/userLocation.ts @@ -1,7 +1,6 @@ -import { UserLocation } from '@internxt/sdk'; -import { SdkFactory } from 'app/core/factory/sdk'; +import { getUserLocation, UserLocation } from '@internxt/sdk'; +import envService from 'services/env.service'; export const userLocation = (): Promise => { - const client = SdkFactory.getNewApiInstance().createLocationClient(); - return client.getUserLocation(); + return getUserLocation(envService.getVariable('location')); }; diff --git a/yarn.lock b/yarn.lock index 92db71b54b..fd3714a8da 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1906,10 +1906,10 @@ version "1.0.2" resolved "https://codeload.github.com/internxt/prettier-config/tar.gz/9fa74e9a2805e1538b50c3809324f1c9d0f3e4f9" -"@internxt/sdk@=1.12.4": - version "1.12.4" - resolved "https://registry.yarnpkg.com/@internxt/sdk/-/sdk-1.12.4.tgz#5874d5b2705919a27f4e621e8179443e5bbdc43f" - integrity sha512-amADmUpOubu2wnbGq+DZqgK03JCKJcLuijiigY29SwBSrdknTlAqAetQSpbl/RXnBpeqnTTZtYXMJPYB14qbHw== +"@internxt/sdk@=1.12.0": + version "1.12.0" + resolved "https://registry.yarnpkg.com/@internxt/sdk/-/sdk-1.12.0.tgz#cf9c2f0ca8864a688e4c161f470e171997bff7bb" + integrity sha512-QrjH2yJP7MjxAVvkOe6quqX7RYzC6e3M0XcXralJEFybDpimJBJbvRTPUe7+9XRQ6gHdmYi1u3ySDVoZyZpkug== dependencies: axios "1.13.2" uuid "11.1.0"