Skip to content

Commit

Permalink
#67 fixed typo
Browse files Browse the repository at this point in the history
  • Loading branch information
bennobuilder committed Aug 27, 2024
1 parent 5b83dcf commit 803a0e6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
10 changes: 8 additions & 2 deletions packages/eprel-client/src/create-eprel-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand All @@ -22,6 +23,7 @@ describe('createEPRELClient function tests', () => {
registrationNumber: '15414'
}
});
const product = await client.getProductByRegistrationNumber('15414');
expect(productResult.isOk()).toBeTruthy();
});

Expand All @@ -35,6 +37,7 @@ describe('createEPRELClient function tests', () => {
},
parseAs: 'json'
});
const productFiches = await client.getProductFiches('15414', { noRedirect: true });
expect(productFichesResult.isOk()).toBeTruthy();
});

Expand All @@ -48,6 +51,7 @@ describe('createEPRELClient function tests', () => {
},
parseAs: 'json'
});
const productLabels = await client.getProductLabels('15414', { noRedirect: true });
expect(productLabelsResult.isOk()).toBeTruthy();
});

Expand All @@ -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();
});
});

Expand Down
30 changes: 20 additions & 10 deletions packages/eprel-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,38 @@ declare module 'feature-fetch' {
registrationNumber: TRegistrationNumber
): Promise<components['schemas']['ModelDetails']>;

getProductFiche(
registrationNumber: TRegistrationNumber,
options?: {
getProductFiches<
GOptions extends {
noRedirect?: boolean;
language?: TLanguage;
}
): Promise<TFileAddress | Uint8Array>;

getProductLabel(
} = {}
>(
registrationNumber: TRegistrationNumber,
options?: {
options?: GOptions
): Promise<TReturnType<GOptions>>;

getProductLabels<
GOptions extends {
noRedirect?: boolean;
format?: TLabelFormat;
instance?: number;
supplier_label?: boolean;
type?: TLabelType;
}
): Promise<TFileAddress | Uint8Array>;
} = {}
>(
registrationNumber: TRegistrationNumber,
options?: GOptions
): Promise<TReturnType<GOptions>>;

getNestedLabel(registrationNumber: TRegistrationNumber): Promise<Uint8Array>;

exportProductGroupModels(productGroup: TProductGroup): Promise<Uint8Array>;
};
}
}

type TReturnType<GOptions> = GOptions extends { noRedirect?: boolean }
? GOptions['noRedirect'] extends true
? TFileAddress
: Uint8Array
: Uint8Array;
10 changes: 5 additions & 5 deletions packages/eprel-client/src/with-eprel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,26 +84,26 @@ export function withEPREL<GSelectedFeatureKeys extends TFeatureKeys[]>(
},

// 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: {
noRedirect?: boolean;
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: {
Expand All @@ -127,7 +127,7 @@ export function withEPREL<GSelectedFeatureKeys extends TFeatureKeys[]>(
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
Expand Down

0 comments on commit 803a0e6

Please sign in to comment.