From 803a0e6bddc334349fb2a3e205e0a4e9bac2a716 Mon Sep 17 00:00:00 2001 From: Benno <57860196+bennoinbeta@users.noreply.github.com> Date: Tue, 27 Aug 2024 18:04:11 +0200 Subject: [PATCH] #67 fixed typo --- .../src/create-eprel-client.test.ts | 10 +++++-- packages/eprel-client/src/index.ts | 30 ++++++++++++------- packages/eprel-client/src/with-eprel.ts | 10 +++---- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/packages/eprel-client/src/create-eprel-client.test.ts b/packages/eprel-client/src/create-eprel-client.test.ts index 4188a089..13f34bf6 100644 --- a/packages/eprel-client/src/create-eprel-client.test.ts +++ b/packages/eprel-client/src/create-eprel-client.test.ts @@ -13,6 +13,7 @@ describe('createEPRELClient function tests', () => { it('should retrieve product groups successfully', async () => { const productsResult = await client.get('/product-groups'); + const productGroups = await client.getProductGroups(); expect(productsResult.isOk()).toBeTruthy(); }); @@ -22,6 +23,7 @@ describe('createEPRELClient function tests', () => { registrationNumber: '15414' } }); + const product = await client.getProductByRegistrationNumber('15414'); expect(productResult.isOk()).toBeTruthy(); }); @@ -35,6 +37,7 @@ describe('createEPRELClient function tests', () => { }, parseAs: 'json' }); + const productFiches = await client.getProductFiches('15414', { noRedirect: true }); expect(productFichesResult.isOk()).toBeTruthy(); }); @@ -48,6 +51,7 @@ describe('createEPRELClient function tests', () => { }, parseAs: 'json' }); + const productLabels = await client.getProductLabels('15414', { noRedirect: true }); expect(productLabelsResult.isOk()).toBeTruthy(); }); @@ -61,17 +65,19 @@ describe('createEPRELClient function tests', () => { parseAs: 'blob' } ); + const productNestedLabel = await client.getNestedLabel('15414'); expect(productNestedLabelResult.isOk()).toBeTruthy(); }); it('should retrieve products in a product group successfully', async () => { - const productsInProductGroup = await client.get('/products/{productGroup}', { + const productsInProductGroupResult = await client.get('/products/{productGroup}', { pathParams: { productGroup: 'airconditioners' }, queryParams: {} }); - expect(productsInProductGroup.isOk()).toBeTruthy(); + const productsIngroup = await client.getModelsInProductGroup('airconditioners'); + expect(productsInProductGroupResult.isOk()).toBeTruthy(); }); }); diff --git a/packages/eprel-client/src/index.ts b/packages/eprel-client/src/index.ts index c93617f7..ab4fdfe9 100644 --- a/packages/eprel-client/src/index.ts +++ b/packages/eprel-client/src/index.ts @@ -34,24 +34,28 @@ declare module 'feature-fetch' { registrationNumber: TRegistrationNumber ): Promise; - getProductFiche( - registrationNumber: TRegistrationNumber, - options?: { + getProductFiches< + GOptions extends { noRedirect?: boolean; language?: TLanguage; - } - ): Promise; - - getProductLabel( + } = {} + >( registrationNumber: TRegistrationNumber, - options?: { + options?: GOptions + ): Promise>; + + getProductLabels< + GOptions extends { noRedirect?: boolean; format?: TLabelFormat; instance?: number; supplier_label?: boolean; type?: TLabelType; - } - ): Promise; + } = {} + >( + registrationNumber: TRegistrationNumber, + options?: GOptions + ): Promise>; getNestedLabel(registrationNumber: TRegistrationNumber): Promise; @@ -59,3 +63,9 @@ declare module 'feature-fetch' { }; } } + +type TReturnType = GOptions extends { noRedirect?: boolean } + ? GOptions['noRedirect'] extends true + ? TFileAddress + : Uint8Array + : Uint8Array; diff --git a/packages/eprel-client/src/with-eprel.ts b/packages/eprel-client/src/with-eprel.ts index 76dfbb86..d1d5b8ce 100644 --- a/packages/eprel-client/src/with-eprel.ts +++ b/packages/eprel-client/src/with-eprel.ts @@ -84,7 +84,7 @@ export function withEPREL( }, // https://webgate.ec.europa.eu/fpfis/wikis/pages/viewpage.action?pageId=1847100857 - async getProductFiche( + async getProductFiches( this: TFetchClient<['base', 'openapi', 'eprel'], paths>, registrationNumber: TRegistrationNumber, options: { @@ -92,18 +92,18 @@ export function withEPREL( language?: TLanguage; } = {} ) { - const { noRedirect, language } = options; + const { noRedirect = false, language } = options; const result = await this.get('/product/{registrationNumber}/fiches', { pathParams: { registrationNumber }, queryParams: { noRedirect, language }, parseAs: noRedirect ? 'json' : 'arrayBuffer' }); const data = result.unwrap().data; - return data instanceof ArrayBuffer ? new Uint8Array(data) : (data as TFileAddress); + return data instanceof ArrayBuffer ? (new Uint8Array(data) as any) : (data as TFileAddress); }, // https://webgate.ec.europa.eu/fpfis/wikis/pages/viewpage.action?pageId=1847100858 - async getProductLabel( + async getProductLabels( this: TFetchClient<['base', 'openapi', 'eprel'], paths>, registrationNumber: TRegistrationNumber, options: { @@ -127,7 +127,7 @@ export function withEPREL( parseAs: noRedirect ? 'json' : 'arrayBuffer' }); const data = result.unwrap().data; - return data instanceof ArrayBuffer ? new Uint8Array(data) : (data as TFileAddress); + return data instanceof ArrayBuffer ? (new Uint8Array(data) as any) : (data as TFileAddress); }, // https://webgate.ec.europa.eu/fpfis/wikis/pages/viewpage.action?pageId=1847100859