@epilot/entity-client 3.0.10 → 3.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,19 @@
1
+ import { getClient } from './client';
2
+
3
+ describe('client', () => {
4
+ describe('getClient', () => {
5
+ it('should inititalise and return client', async () => {
6
+ const client = getClient();
7
+
8
+ expect(client.api.initialized).toBe(true);
9
+ });
10
+
11
+ it('should have operations', async () => {
12
+ const client = getClient();
13
+
14
+ const operations = client.api.getOperations();
15
+
16
+ expect(operations.length).toBeGreaterThan(0);
17
+ });
18
+ });
19
+ });
package/src/client.ts ADDED
@@ -0,0 +1,21 @@
1
+ import CorrelationIds from '@dazn/lambda-powertools-correlation-ids';
2
+ import OpenAPIClientAxios from 'openapi-client-axios';
3
+
4
+ import definition from './definition';
5
+ import { Client } from './openapi';
6
+
7
+ export const getClient = () => {
8
+ const api = new OpenAPIClientAxios({ definition, quick: true });
9
+ const apiClient = api.initSync<Client>();
10
+ apiClient.interceptors.request.use((config) => {
11
+ const correlationHeaders = CorrelationIds.get() || {};
12
+ config.headers = {
13
+ ...(config.headers || {}),
14
+ ...correlationHeaders,
15
+ };
16
+
17
+ return config;
18
+ });
19
+
20
+ return apiClient;
21
+ };
@@ -0,0 +1,5 @@
1
+ import type { Document } from 'openapi-client-axios';
2
+
3
+ import definition from './openapi.json';
4
+
5
+ export default definition as Document;
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from './client';
2
+ export * from './schema-model';
3
+ export type { Client, Components, Paths, PathsDictionary, OperationMethods } from './openapi';
4
+ export type { OpenAPIClient, OpenAPIClientAxios, Document } from 'openapi-client-axios';