-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from builder-group/67-eprel-api
EPREL API Client
- Loading branch information
Showing
56 changed files
with
2,433 additions
and
528 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
'google-webfonts-client': patch | ||
'validation-adapters': patch | ||
'validation-adapter': patch | ||
'feature-logger': patch | ||
'@blgc/openapi-router': patch | ||
'feature-fetch': patch | ||
'feature-react': patch | ||
'feature-state': patch | ||
'xml-tokenizer': patch | ||
'eprel-client': patch | ||
'feature-form': patch | ||
'@blgc/config': patch | ||
'@blgc/utils': patch | ||
--- | ||
|
||
Updated vitest config to esm (enforced) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* @type {import('eslint').Linter.Config} | ||
*/ | ||
module.exports = { | ||
root: true, | ||
extends: [require.resolve('@blgc/config/eslint/library')], | ||
ignorePatterns: ['src/gen/*'] | ||
}; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<h1 align="center"> | ||
<img src="https://raw.githubusercontent.com/builder-group/monorepo/develop/packages/eprel-client/.github/banner.svg" alt="eprel-client banner"> | ||
</h1> | ||
|
||
<p align="left"> | ||
<a href="https://github.com/builder-group/monorepo/blob/develop/LICENSE"> | ||
<img src="https://img.shields.io/github/license/builder-group/monorepo.svg?label=license&style=flat&colorA=293140&colorB=FDE200" alt="GitHub License"/> | ||
</a> | ||
<a href="https://www.npmjs.com/package/eprel-client"> | ||
<img src="https://img.shields.io/bundlephobia/minzip/eprel-client.svg?label=minzipped%20size&style=flat&colorA=293140&colorB=FDE200" alt="NPM bundle minzipped size"/> | ||
</a> | ||
<a href="https://www.npmjs.com/package/eprel-client"> | ||
<img src="https://img.shields.io/npm/dt/eprel-client.svg?label=downloads&style=flat&colorA=293140&colorB=FDE200" alt="NPM total downloads"/> | ||
</a> | ||
<a href="https://discord.gg/w4xE3bSjhQ"> | ||
<img src="https://img.shields.io/discord/795291052897992724.svg?label=&logo=discord&logoColor=000000&color=293140&labelColor=FDE200" alt="Join Discord"/> | ||
</a> | ||
</p> | ||
|
||
> Status: Experimental | ||
`eprel-client` is a typesafe and straightforward fetch client for interacting with the European Product Registry for Energy Labelling (EPREL) API using [`feature-fetch`](https://github.com/builder-group/monorepo/tree/develop/packages/feature-fetch). | ||
|
||
- [EPREL API Docs](https://webgate.ec.europa.eu/fpfis/wikis/display/EPREL/EPREL+Public+site+-+API) | ||
|
||
## 📖 Usage | ||
|
||
### Create a EPREL Client | ||
|
||
Use `createEPRELClient()` to create a client with your API key. | ||
|
||
```ts | ||
import { createEPRELClient } from 'eprel-client'; | ||
|
||
const client = createEPRELClient({ | ||
apiKey: 'YOUR_API_KEY' | ||
}); | ||
``` | ||
|
||
### Fetch Available Product Groups | ||
|
||
Fetches the available product groups from the ERAP API. | ||
|
||
```ts | ||
const productGroups = await client.getProductGroups(); | ||
``` | ||
|
||
### Error Handling | ||
|
||
Errors can occur during API requests, and the client will return detailed error information. Possible error types include: | ||
|
||
- **`NetworkError`**: Indicates a failure in network communication, such as loss of connectivity | ||
- **`RequestError`**: Occurs when the server returns a response with a status code indicating an error (e.g., 4xx or 5xx) | ||
- **`FetchError`**: A general exception type that can encompass other error scenarios not covered by `NetworkError` or `RequestError`, for example when the response couldn't be parsed, .. | ||
|
||
```ts | ||
try { | ||
const productGroups = await client.getProductGroups(); | ||
} catch (error) { | ||
if (error instanceof NetworkError) { | ||
console.error('Network error:', error.message); | ||
} else if (error instanceof RequestError) { | ||
console.error('Request error:', error.message, 'Status:', error.status); | ||
} else if (error instanceof FetchError) { | ||
console.error('Service error:', error.message, 'Code:', error.code); | ||
} else { | ||
console.error('Unexpected error:', error); | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{ | ||
"name": "eprel-client", | ||
"description": "Typesafe and straightforward fetch client for interacting with the European Product Registry for Energy Labelling (EPREL) API using feature-fetch", | ||
"version": "0.0.2", | ||
"private": false, | ||
"scripts": { | ||
"build": "shx rm -rf dist && ../../scripts/cli.sh bundle", | ||
"start:dev": "tsc -w", | ||
"openapi:gen": "npx openapi-typescript ./resources/openapi_v1-0-58.yaml -o ./src/gen/v1.ts", | ||
"lint": "eslint --ext .js,.ts src/", | ||
"clean": "shx rm -rf dist && shx rm -rf node_modules && shx rm -rf .turbo", | ||
"install:clean": "pnpm run clean && pnpm install", | ||
"test": "vitest run", | ||
"update:latest": "pnpm update --latest", | ||
"publish:patch": "pnpm build && pnpm version patch && pnpm publish --no-git-checks --access=public", | ||
"size": "size-limit --why" | ||
}, | ||
"source": "./src/index.ts", | ||
"main": "./dist/cjs/index.js", | ||
"module": "./dist/esm/index.js", | ||
"types": "./dist/types/index.d.ts", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/builder-group/monorepo.git" | ||
}, | ||
"keywords": [], | ||
"author": "@bennobuilder", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/builder-group/monorepo/issues" | ||
}, | ||
"homepage": "https://builder.group/?source=package-json", | ||
"dependencies": { | ||
"feature-fetch": "workspace:*" | ||
}, | ||
"devDependencies": { | ||
"@blgc/config": "workspace:*", | ||
"@types/node": "^22.5.0", | ||
"dotenv": "^16.4.5", | ||
"openapi-typescript": "^7.3.0" | ||
}, | ||
"files": [ | ||
"dist", | ||
"README.md" | ||
], | ||
"size-limit": [ | ||
{ | ||
"path": "dist/esm/index.js" | ||
} | ||
] | ||
} |
Oops, something went wrong.