From 22514e1c22777c54150c94e9c7146b4a8a02ece7 Mon Sep 17 00:00:00 2001 From: BruceWouaigne Date: Fri, 3 Jan 2025 11:06:22 +0100 Subject: [PATCH] Remove path usage so it works in the browser --- src/__tests__/linkup-client.test.ts | 14 +++++++++++++- src/__tests__/utils/version.utils.test.ts | 5 ----- src/linkup-client.ts | 3 +-- src/utils/version.utils.ts | 12 ------------ 4 files changed, 14 insertions(+), 20 deletions(-) delete mode 100644 src/__tests__/utils/version.utils.test.ts delete mode 100644 src/utils/version.utils.ts diff --git a/src/__tests__/linkup-client.test.ts b/src/__tests__/linkup-client.test.ts index 1667165..905c4cc 100644 --- a/src/__tests__/linkup-client.test.ts +++ b/src/__tests__/linkup-client.test.ts @@ -9,6 +9,8 @@ import { LinkupUnknownError, } from '../errors'; import { z } from 'zod'; +import { readFileSync } from 'fs'; +import { join } from 'path'; jest.mock('axios'); const maxios = axios as jest.Mocked; @@ -43,7 +45,7 @@ describe('LinkupClient', () => { baseURL: 'https://api.linkup.so/v1', headers: { Authorization: 'Bearer 1234', - 'User-Agent': 'Linkup-JS-SDK/1.0.1', + 'User-Agent': `Linkup-JS-SDK/${getVersionFromPackage()}`, }, }, ); @@ -221,3 +223,13 @@ describe('LinkupClient', () => { .catch((e) => expect(e).toBeInstanceOf(LinkupInvalidRequestError)); }); }); + +function getVersionFromPackage(): string { + try { + const packagePath = join(__dirname, '..', '..', 'package.json'); + const packageJson = JSON.parse(readFileSync(packagePath, 'utf8')); + return packageJson.version; + } catch { + throw new Error('Could not read package version'); + } +} diff --git a/src/__tests__/utils/version.utils.test.ts b/src/__tests__/utils/version.utils.test.ts deleted file mode 100644 index b665d47..0000000 --- a/src/__tests__/utils/version.utils.test.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { getVersionFromPackage } from '../../utils/version.utils'; - -it('should return package version', () => { - expect(getVersionFromPackage()).toEqual('1.0.1'); -}); diff --git a/src/linkup-client.ts b/src/linkup-client.ts index a4924af..b143a81 100644 --- a/src/linkup-client.ts +++ b/src/linkup-client.ts @@ -16,13 +16,12 @@ import { StructuredOutputSchema, LinkupSearchResponse, } from './types'; -import { getVersionFromPackage } from './utils/version.utils'; import zodToJsonSchema from 'zod-to-json-schema'; import { ZodObject, ZodRawShape } from 'zod'; import { isZodObject } from './utils/schema.utils'; export class LinkupClient { - private readonly USER_AGENT = `Linkup-JS-SDK/${getVersionFromPackage()}`; + private readonly USER_AGENT = 'Linkup-JS-SDK/1.0.1'; private readonly apiKey: string; private readonly baseUrl: string; diff --git a/src/utils/version.utils.ts b/src/utils/version.utils.ts deleted file mode 100644 index 6575f2d..0000000 --- a/src/utils/version.utils.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { readFileSync } from 'fs'; -import { join } from 'path'; - -export function getVersionFromPackage(): string { - try { - const packagePath = join(__dirname, '..', '..', 'package.json'); - const packageJson = JSON.parse(readFileSync(packagePath, 'utf8')); - return packageJson.version; - } catch { - throw new Error('Could not read package version'); - } -}