@redhat-cloud-services/javascript-clients-shared
Advanced tools
Comparing version 1.2.6 to 1.2.7
@@ -5,2 +5,4 @@ # Changelog | ||
## [1.2.7](https://github.com/RedHatInsights/javascript-clients/compare/@redhat-cloud-services/javascript-clients-shared-1.2.6...@redhat-cloud-services/javascript-clients-shared-1.2.7) (2024-12-09) | ||
## [1.2.6](https://github.com/RedHatInsights/javascript-clients/compare/@redhat-cloud-services/javascript-clients-shared-1.2.5...@redhat-cloud-services/javascript-clients-shared-1.2.6) (2024-11-18) | ||
@@ -7,0 +9,0 @@ |
{ | ||
"name": "@redhat-cloud-services/javascript-clients-shared", | ||
"version": "1.2.6", | ||
"version": "1.2.7", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
@@ -1,10 +0,8 @@ | ||
@redhat-cloud-services/javascript-clients-shared / [Exports](modules.md) | ||
# Javascript client for the shared API | ||
If you want to use [RedHatInsights/shared](https://github.com/RedHatInsights/shared) you shouldn't use get requests directly, but rather use this client to integrate with this service. | ||
# Shared Javascript utilities and functions for javascript-clients | ||
This package contains some common configurations and functions needed for clients using the new [javascript-clients](https://github.com/RedHatInsights/javascript-clients) generator. | ||
## Install | ||
NPM | ||
```bash | ||
npm install --save @redhat-cloud-services/javascript-clients-shared | ||
npm install --save @redhat-cloud-services/shared-client | ||
``` | ||
@@ -14,3 +12,3 @@ | ||
```bash | ||
yarn add @redhat-cloud-services/javascript-clients-shared | ||
yarn add @redhat-cloud-services/shared-client | ||
``` | ||
@@ -21,19 +19,57 @@ | ||
To correctly bootstrap this API you should use this config (no need to define it multiple times, just one config and reimport it anywhere you want to use it). | ||
This package comes with a client in its `api.ts` already defined with every call available. | ||
```JS | ||
// api.js | ||
import APIFactory from '@redhat-cloud-services/javascript-clients-shared'; | ||
`import sharedClient from '@redhat-cloud-services/javascript-clients-shared/utils'; | ||
sharedClient.someEndpoint(); | ||
``` | ||
To bootstrap this API manually, you should create your own client via the `APIFactory` defined in the `@redhat-cloud-services/javascript-clients-shared` package. See below for an example: | ||
```JS | ||
import APIFactory from '@redhat-cloud-services/javascript-clients-shared/utils'; | ||
import exampleEndpoint from '@redhat-cloud-services/shared-client/ExampleEndpoint'; | ||
// BASE_PATH should be set in your constants file | ||
const someApi = APIFactory(BASE_PATH, undefined, { createEndpoint, enableEndpoint }); | ||
export someApi; | ||
const sharedApi = APIFactory(BASE_PATH, undefined, { exampleEndpoint }); | ||
export sharedApi; | ||
``` | ||
If you want to add some interceptors you can use axios build in interceptors | ||
```JS | ||
import axios from 'axios'; | ||
import APIFactory from '@redhat-cloud-services/javascript-clients-shared/utils'; | ||
import exampleEndpoint from '@redhat-cloud-services/shared-client/ExampleEndpoint'; | ||
const instance = axios.create(); | ||
// Request interceptor | ||
instance.interceptors.request.use((request) => { | ||
// some logic to do with request | ||
}); | ||
// Response interceptor | ||
instance.interceptors.response.use((response) => { | ||
// some logic to do with request | ||
}); | ||
// Error interceptor | ||
instance.interceptors.response.use(null, (error) => { | ||
// some logic to do with error | ||
}); | ||
// BASE_PATH should be set in your constants file | ||
const sharedApi = APIFactory(BASE_PATH, instance, { exampleEndpoint }); | ||
export sharedApi; | ||
``` | ||
## Generating | ||
Ensure you have the javascript-clients generator built first with `npm run build:generator`. Then, run `nx run @redhat-cloud-services/shared-client:generate` to generate the package. | ||
## Building | ||
Run `nx build @redhat-cloud-services/javascript-clients-shared` to build the library. | ||
Run `nx run @redhat-cloud-services/shared-client:build` to build the package. This creates the `dist` for publishing. | ||
## Running unit tests | ||
Run `nx test @redhat-cloud-services/javascript-clients-shared` to execute the unit tests via [Jest](https://jestjs.io). | ||
Run `nx run @redhat-cloud-services/shared-client:test` to execute the unit tests via [Jest](https://jestjs.io). | ||
@@ -40,0 +76,0 @@ ## API documentation |
64476
77