Skip to content

Commit

Permalink
Merge pull request #68 from builder-group/67-eprel-api
Browse files Browse the repository at this point in the history
EPREL API Client
  • Loading branch information
bennobuilder authored Aug 27, 2024
2 parents 5e10228 + 3af0165 commit e4efcb4
Show file tree
Hide file tree
Showing 56 changed files with 2,433 additions and 528 deletions.
17 changes: 17 additions & 0 deletions .changeset/modern-trains-perform.md
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)
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ A collection of open source libraries maintained by [builder.group](https://buil
| ---------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------- |
| [cli](https://github.com/builder-group/monorepo/blob/develop/packages/cli) | Straightforward CLI to bundle Typescript libraries with presets, powered by Rollup and Esbuild | [`@blgc/cli`](https://www.npmjs.com/package/@blgc/cli) |
| [config](https://github.com/builder-group/monorepo/blob/develop/packages/cli) | Collection of ESLint, Vite, and Typescript configurations | [`@blgc/config`](https://www.npmjs.com/package/@blgc/config) |
| [eprel-client](https://github.com/builder-group/monorepo/blob/develop/packages/eprel-client) | Typesafe and straightforward fetch client for interacting with the European Product Registry for Energy Labelling (EPREL) API using feature-fetch | [`eprel-client`](https://www.npmjs.com/package/eprel-client) |
| [feature-fetch](https://github.com/builder-group/monorepo/blob/develop/packages/feature-fetch) | Straightforward, typesafe, and feature-based fetch wrapper supporting OpenAPI types | [`feature-fetch`](https://www.npmjs.com/package/feature-fetch) |
| [feature-form](https://github.com/builder-group/monorepo/blob/develop/packages/feature-form) | Straightforward, typesafe, and feature-based form library | [`feature-form`](https://www.npmjs.com/package/feature-form) |
| [feature-logger](https://github.com/builder-group/monorepo/blob/develop/packages/feature-logger) | Straightforward, typesafe, and feature-based logging library | [`feature-logger`](https://www.npmjs.com/package/feature-logger) |
Expand Down
8 changes: 3 additions & 5 deletions packages/config/vite/node.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
const { defineConfig } = require('vitest/config');

// https://github.com/aleclarson/vite-tsconfig-paths/issues/75
const tsconfigPaths = require('vite-tsconfig-paths').default;
import tsconfigPaths from 'vite-tsconfig-paths';
import { defineConfig } from 'vitest/config';

const nodeConfig = defineConfig({
test: {
Expand All @@ -12,4 +10,4 @@ const nodeConfig = defineConfig({
plugins: [tsconfigPaths()]
});

module.exports = { nodeConfig };
export { nodeConfig };
8 changes: 8 additions & 0 deletions packages/eprel-client/.eslintrc.js
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/*']
};
6 changes: 6 additions & 0 deletions packages/eprel-client/.github/banner.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
70 changes: 70 additions & 0 deletions packages/eprel-client/README.md
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);
}
}
```
51 changes: 51 additions & 0 deletions packages/eprel-client/package.json
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"
}
]
}
Loading

0 comments on commit e4efcb4

Please sign in to comment.