Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions clients/data-management-client/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Changelog

All notable changes to this project will be documented in this file.

## 0.1.0
- Initial scaffold of `@epilot/data-management-client`
- Added OpenAPI generation scripts (including local path)
- Added build/test configuration and client stubs


42 changes: 42 additions & 0 deletions clients/data-management-client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# @epilot/data-management-client

[![CI](https://github.com/epilot-dev/sdk-js/workflows/CI/badge.svg)](https://github.com/epilot-dev/sdk-js/actions?query=workflow%3ACI)
[![npm version](https://img.shields.io/npm/v/@epilot/data-management-client.svg)](https://www.npmjs.com/package/@epilot/data-management-client)
[![bundle size](https://img.shields.io/bundlephobia/minzip/@epilot/data-management-client?label=gzip%20bundle)](https://bundlephobia.com/package/@epilot/data-management-client)
[![License](http://img.shields.io/:license-mit-blue.svg)](https://github.com/epilot-dev/sdk-js/blob/main/LICENSE)

Client library for epilot Data Management API

Uses [`openapi-client-axios`](https://github.com/openapistack/openapi-client-axios)

## Installation

```bash
npm install --save @epilot/data-management-client
```

## Usage

```typescript
import { getClient } from '@epilot/data-management-client';

const dataManagementClient = getClient();
// Example:
// const res = await dataManagementClient.someOperation();
```

## Generate from OpenAPI

Use the local OpenAPI source:

```bash
pnpm --filter @epilot/data-management-client run openapi:local && pnpm --filter @epilot/data-management-client run typegen
```

Or (if available) fetch from docs:

```bash
pnpm --filter @epilot/data-management-client run openapi && pnpm --filter @epilot/data-management-client run typegen
```


16 changes: 16 additions & 0 deletions clients/data-management-client/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { Config } from '@jest/types';

const config: Config.InitialOptions = {
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: ['**/?(*.)+(spec|test).ts?(x)'],
testPathIgnorePatterns: ['node_modules'],
coveragePathIgnorePatterns: ['__tests__', 'node_modules'],
verbose: true,
silent: true,
moduleNameMapper: {
'^axios$': require.resolve('axios'),
},
};

export default config;
76 changes: 76 additions & 0 deletions clients/data-management-client/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"name": "@epilot/data-management-client",
"version": "1.2.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe set it to 0.0.1

"description": "JavaScript client library for epilot's Data Management API",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"author": "epilot GmbH",
"license": "MIT",
"private": false,
"repository": {
"type": "git",
"url": "git+https://github.com/epilot-dev/sdk-js.git",
"directory": "clients/data-management-client"
},
"bugs": {
"url": "https://github.com/epilot-dev/sdk-js/issues"
},
"homepage": "https://github.com/epilot-dev/sdk-js/tree/main/clients/data-management-client#readme",
"keywords": [
"epilot",
"sdk",
"data-management"
],
"scripts": {
"test": "jest",
"typescript": "tsc",
"bundle-definition": "webpack",
"openapi": "node ../../scripts/update-openapi.js https://docs.api.epilot.io/data-management.yaml",
"openapi:local": "node ../../scripts/update-openapi.js /Users/manikandansubramanian/Workspace/data-management-api/lambda/ApiHandlerFunction/openapi.yml",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/Users/manikandansubramanian/Workspace/ oopsiee...

"typegen": "openapi typegen src/openapi.json --client -b '/* eslint-disable */' > src/openapi.d.ts",
"build": "tsc && npm run build:patch && npm run bundle-definition",
"build:patch": "sed -i'' -e '/^__exportStar.*openapi.*$/d' dist/index.js",
"build:watch": "npm run build && tsc -w",
"release-alpha": "npm version prerelease --preid alpha",
"lint": "pnpm exec eslint src"
},
"files": [
"*.js",
"*.d.ts",
"**/*.json",
"**/*.js",
"**/*.d.ts",
"!*.test.*",
"!**/*.test.*",
"!node_modules",
"!src",
"!src/**",
"!*.config.js"
],
"peerDependencies": {
"axios": "^1.0.0 || >=0.25.0 <1.0.0"
},
"dependencies": {
"@dazn/lambda-powertools-correlation-ids": "^1.28.1",
"buffer": "^6.0.3",
"https-browserify": "^1.0.0",
"openapi-client-axios": "^7.8.0",
"stream-http": "^3.2.0",
"url": "^0.11.0",
"util": "^0.12.3"
},
"devDependencies": {
"@types/jest": "^26.0.20",
"axios": "^1.11.0",
"copy-webpack-plugin": "^7.0.0",
"jest": "^29.6.2",
"json-loader": "^0.5.7",
"openapicmd": "^2.7.0",
"ts-jest": "^29.4.1",
"ts-loader": "^8.0.14",
"ts-node": "^10.9.2",
"typescript": "^4.1.3",
"webpack": "^5.101.0",
"webpack-cli": "^4.10.0"
}
}
30 changes: 30 additions & 0 deletions clients/data-management-client/src/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import CorrelationIds from '@dazn/lambda-powertools-correlation-ids';
import OpenAPIClientAxios from 'openapi-client-axios';

import definition from './definition';
import { Client } from './openapi';

let client: Client;
export const getClient = () => {
if (!client) {
client = createClient();
}

return client;
};

export const createClient = () => {
const api = new OpenAPIClientAxios({
definition,
quick: true,
});

const apiClient = api.initSync<Client>();

apiClient.defaults.headers.common = {
...(apiClient.defaults.headers.common ?? {}),
...(CorrelationIds.get() || {}),
};

return apiClient;
};
5 changes: 5 additions & 0 deletions clients/data-management-client/src/definition.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { Document } from 'openapi-client-axios';

import definition from './openapi-runtime.json';

export default definition as unknown as Document;
4 changes: 4 additions & 0 deletions clients/data-management-client/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export type { Document, OpenAPIClient, OpenAPIClientAxios } from 'openapi-client-axios';

export * from './client';
export * from './openapi';
34 changes: 34 additions & 0 deletions clients/data-management-client/src/openapi-runtime.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"openapi": "3.0.3",
"info": {
"title": "",
"version": ""
},
"paths": {
"/data-management/v1/{entity_schema}/query": {
"post": {
"operationId": "queryEntitiesBySavedView",
"parameters": [
{
"name": "entity_schema",
"in": "path",
"required": true
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {}
}
},
"responses": {}
}
}
},
"components": {},
"servers": [
{
"url": "https://data-management.sls.epilot.io"
}
]
}
105 changes: 105 additions & 0 deletions clients/data-management-client/src/openapi.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/* eslint-disable */

import type {
OpenAPIClient,
Parameters,
UnknownParamsObject,
OperationResponse,
AxiosRequestConfig,
} from 'openapi-client-axios';

declare namespace Components {
namespace Schemas {
export interface DataManagementFilter {
type: DataManagementFilterType;
related_entity_schemas?: string[];
workflow_statuses?: string[];
entity_statuses?: string[];
lookback_period_months?: number;
}
export type DataManagementFilterType = "entity_workflows_only_in_closed_or_cancelled_status" | "no_related_entities" | "related_entities_all_in_closed_or_cancelled_status" | "related_entities_any_in_closed_or_cancelled_status" | "no_email_communication_since";
}
}
declare namespace Paths {
namespace QueryEntitiesBySavedView {
namespace Parameters {
export type EntitySchema = string;
}
export interface PathParameters {
entity_schema: Parameters.EntitySchema;
}
export interface RequestBody {
/**
* ID of the saved view to use for querying entities
*/
saved_view_id: string;
/**
* Pagination start offset
*/
from?: number;
/**
* Page size (maximum number of entities to return)
*/
size?: number;
/**
* Whether to include soft-deleted entities in the result
*/
includeDeleted?: boolean;
/**
* Whether to hydrate entities with full data instead of returning only indexed / projection fields.
*
*/
hydrate?: boolean;
/**
* Optional list of fields to include in each entity.
*
*/
fields?: string[];
filters?: Components.Schemas.DataManagementFilter;
}
namespace Responses {
export interface $200 {
entities?: {
[name: string]: any;
}[];
}
}
}
}


export interface OperationMethods {
/**
* queryEntitiesBySavedView - Query entities using a saved view with additional data filters
*
* Executes a query against the specified entity schema using the saved view definition, optionally combined with additional filters. Returns the entities matching the composed query.
*
*/
'queryEntitiesBySavedView'(
parameters?: Parameters<Paths.QueryEntitiesBySavedView.PathParameters> | null,
data?: Paths.QueryEntitiesBySavedView.RequestBody,
config?: AxiosRequestConfig
): OperationResponse<Paths.QueryEntitiesBySavedView.Responses.$200>
}

export interface PathsDictionary {
['/data-management/v1/{entity_schema}/query']: {
/**
* queryEntitiesBySavedView - Query entities using a saved view with additional data filters
*
* Executes a query against the specified entity schema using the saved view definition, optionally combined with additional filters. Returns the entities matching the composed query.
*
*/
'post'(
parameters?: Parameters<Paths.QueryEntitiesBySavedView.PathParameters> | null,
data?: Paths.QueryEntitiesBySavedView.RequestBody,
config?: AxiosRequestConfig
): OperationResponse<Paths.QueryEntitiesBySavedView.Responses.$200>
}
}

export type Client = OpenAPIClient<OperationMethods, PathsDictionary>


export type DataManagementFilter = Components.Schemas.DataManagementFilter;
export type DataManagementFilterType = Components.Schemas.DataManagementFilterType;
Loading
Loading