@harnessio/react-sto-core-client 0.2.0
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.
- package/README.md +39 -0
- package/dist/fetcher/index.d.ts +17 -0
- package/dist/fetcher/index.js +65 -0
- package/dist/sto-core/src/index.d.ts +6 -0
- package/dist/sto-core/src/index.js +10 -0
- package/dist/sto-core/src/services/helpers.d.ts +14 -0
- package/dist/sto-core/src/services/helpers.js +1 -0
- package/dist/sto-core/src/services/hooks/useReferenceIdentifiersGetByReferenceIdQuery.d.ts +27 -0
- package/dist/sto-core/src/services/hooks/useReferenceIdentifiersGetByReferenceIdQuery.js +14 -0
- package/dist/sto-core/src/services/index.d.ts +5 -0
- package/dist/sto-core/src/services/index.js +1 -0
- package/dist/sto-core/src/services/schemas/GetByReferenceIdResponseBody.d.ts +31 -0
- package/dist/sto-core/src/services/schemas/GetByReferenceIdResponseBody.js +4 -0
- package/dist/sto-core/src/services/schemas/NotFound.d.ts +15 -0
- package/dist/sto-core/src/services/schemas/NotFound.js +4 -0
- package/package.json +34 -0
package/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# React STO Service Client(WIP)
|
|
2
|
+
|
|
3
|
+
**OpenAPI -> OA**
|
|
4
|
+
|
|
5
|
+
**TypeScript -> TS**
|
|
6
|
+
|
|
7
|
+
**OpenAPI + TypeScript -> OATS**
|
|
8
|
+
|
|
9
|
+
This React API client will store a collection of Harness STO Service APIs and Interfaces contracts generated from Open API Spec using `OATS CLI` internally.
|
|
10
|
+
APIs are using hooks from `@tanstack/react-query`
|
|
11
|
+
|
|
12
|
+
## Steps To Generate API Client build as dist folder
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
yarn build
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## For NextGen UI adoption : STOCoreAPIClient should be initialized
|
|
19
|
+
|
|
20
|
+
Before using API Client, it must be initilaized with required `ClientCallbacks`.
|
|
21
|
+
|
|
22
|
+
Example:
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
new STOCoreAPIClient({
|
|
26
|
+
getHeaders: () => {
|
|
27
|
+
return { token: SessionToken.getToken(), 'Harness-Account': accountId }
|
|
28
|
+
}}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Versioning
|
|
32
|
+
|
|
33
|
+

|
|
34
|
+
|
|
35
|
+
Once development phase is completed, this repo will have changes and versioning driven by API spec only.
|
|
36
|
+
|
|
37
|
+
## License
|
|
38
|
+
|
|
39
|
+
[MIT](./LICENSE.md). Copyright(c) [Harness Inc](https://harness.io)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { IStringifyOptions } from 'qs';
|
|
2
|
+
export interface FetcherOptions<TQueryParams = never, TBody = never, THeaderParams = HeadersInit> extends Omit<RequestInit, 'body' | 'headers'> {
|
|
3
|
+
url: string;
|
|
4
|
+
queryParams?: TQueryParams extends never ? undefined : TQueryParams;
|
|
5
|
+
body?: TBody extends never ? undefined : TBody;
|
|
6
|
+
stringifyQueryParamsOptions?: IStringifyOptions;
|
|
7
|
+
headers?: THeaderParams;
|
|
8
|
+
}
|
|
9
|
+
export interface ClientCallbacks {
|
|
10
|
+
responseInterceptor?: (response: Response) => Response;
|
|
11
|
+
requestInterceptor?: (request: Request) => Request;
|
|
12
|
+
urlInterceptor?: (url: string) => string;
|
|
13
|
+
getRequestHeaders?: () => Record<string, any>;
|
|
14
|
+
}
|
|
15
|
+
export declare function setupClient(callbacks: ClientCallbacks): void;
|
|
16
|
+
export declare const updateClientHeaders: (headers: Record<string, any>) => void;
|
|
17
|
+
export declare function fetcher<TResponse = unknown, TQueryParams = never, TBody = never, THeaderParams = HeadersInit>(options: FetcherOptions<TQueryParams, TBody, THeaderParams>): Promise<TResponse>;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { __awaiter, __rest } from "tslib";
|
|
2
|
+
import { stringify } from 'qs';
|
|
3
|
+
const JSON_CONTENT_TYPES = ['application/json'];
|
|
4
|
+
let APIClientInitialized = false;
|
|
5
|
+
let fetcherCallbacks;
|
|
6
|
+
let customHeaders = {
|
|
7
|
+
'Content-Type': JSON_CONTENT_TYPES[0],
|
|
8
|
+
};
|
|
9
|
+
export function setupClient(callbacks) {
|
|
10
|
+
fetcherCallbacks = callbacks;
|
|
11
|
+
customHeaders = Object.assign(Object.assign({}, customHeaders), ((fetcherCallbacks === null || fetcherCallbacks === void 0 ? void 0 : fetcherCallbacks.getRequestHeaders) ? fetcherCallbacks === null || fetcherCallbacks === void 0 ? void 0 : fetcherCallbacks.getRequestHeaders() : {}));
|
|
12
|
+
APIClientInitialized = true;
|
|
13
|
+
}
|
|
14
|
+
export const updateClientHeaders = (headers) => {
|
|
15
|
+
customHeaders = Object.assign(Object.assign({}, customHeaders), headers);
|
|
16
|
+
};
|
|
17
|
+
export function fetcher(options) {
|
|
18
|
+
var _a, _b;
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
// If not initialized throw error even without making request
|
|
21
|
+
if (!APIClientInitialized) {
|
|
22
|
+
throw { reason: 'HarnessReactAPIClient has not been initialized' };
|
|
23
|
+
}
|
|
24
|
+
const { stringifyQueryParamsOptions, headers, body, url, queryParams = { account: customHeaders['Harness-Account'] } } = options, rest = __rest(options, ["stringifyQueryParamsOptions", "headers", "body", "url", "queryParams"]);
|
|
25
|
+
const token = customHeaders.token;
|
|
26
|
+
let finalUrl = url;
|
|
27
|
+
if (queryParams) {
|
|
28
|
+
finalUrl += stringify(queryParams, Object.assign(Object.assign({}, stringifyQueryParamsOptions), { addQueryPrefix: true }));
|
|
29
|
+
}
|
|
30
|
+
if (fetcherCallbacks === null || fetcherCallbacks === void 0 ? void 0 : fetcherCallbacks.urlInterceptor) {
|
|
31
|
+
finalUrl = (_a = fetcherCallbacks === null || fetcherCallbacks === void 0 ? void 0 : fetcherCallbacks.urlInterceptor) === null || _a === void 0 ? void 0 : _a.call(fetcherCallbacks, finalUrl);
|
|
32
|
+
}
|
|
33
|
+
let request = new Request(finalUrl, Object.assign({ headers: Object.assign(Object.assign({ Authorization: `Bearer ${token}` }, headers), customHeaders), body: body ? JSON.stringify(body) : undefined }, rest));
|
|
34
|
+
if (fetcherCallbacks === null || fetcherCallbacks === void 0 ? void 0 : fetcherCallbacks.requestInterceptor) {
|
|
35
|
+
request = fetcherCallbacks.requestInterceptor(request.clone());
|
|
36
|
+
}
|
|
37
|
+
let response = yield fetch(request);
|
|
38
|
+
if (fetcherCallbacks === null || fetcherCallbacks === void 0 ? void 0 : fetcherCallbacks.responseInterceptor) {
|
|
39
|
+
response = (_b = fetcherCallbacks === null || fetcherCallbacks === void 0 ? void 0 : fetcherCallbacks.responseInterceptor) === null || _b === void 0 ? void 0 : _b.call(fetcherCallbacks, response.clone());
|
|
40
|
+
}
|
|
41
|
+
const contentType = response.headers.get('Content-Type');
|
|
42
|
+
let total, pageSize, pageNumber, pageCount, pagination;
|
|
43
|
+
try {
|
|
44
|
+
total = response.headers.get('x-total-elements');
|
|
45
|
+
pageSize = response.headers.get('x-page-size');
|
|
46
|
+
pageNumber = response.headers.get('x-page-number');
|
|
47
|
+
pagination = total || pageSize || pageNumber;
|
|
48
|
+
if (pagination) {
|
|
49
|
+
total = Number(total);
|
|
50
|
+
pageSize = Number(pageSize);
|
|
51
|
+
pageCount = Math.ceil(total / pageSize);
|
|
52
|
+
pageNumber = Number(pageNumber);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
throw new Error('HarnessReactAPIClient: An error occurred while parsing pagination headers. ' + e);
|
|
57
|
+
}
|
|
58
|
+
const asJson = contentType && JSON_CONTENT_TYPES.some((h) => contentType.startsWith(h));
|
|
59
|
+
const data = yield (asJson ? response.json() : response.text());
|
|
60
|
+
if (response.ok) {
|
|
61
|
+
return Object.assign({ content: data }, (pagination ? { pagination: { total, pageCount, pageSize, pageNumber } } : {}));
|
|
62
|
+
}
|
|
63
|
+
throw data;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { setupClient, updateClientHeaders } from '../../fetcher';
|
|
2
|
+
export * from './services/index';
|
|
3
|
+
export class STOCoreAPIClient {
|
|
4
|
+
constructor(callbacks) {
|
|
5
|
+
setupClient(callbacks);
|
|
6
|
+
this.updateHeaders = (headers) => {
|
|
7
|
+
updateClientHeaders(headers);
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type GetPathParamsType<T> = T extends {
|
|
2
|
+
pathParams: infer R;
|
|
3
|
+
} ? R : never;
|
|
4
|
+
export interface ResponseWithPagination<T> {
|
|
5
|
+
content: T;
|
|
6
|
+
pagination?: {
|
|
7
|
+
total?: number;
|
|
8
|
+
pageSize?: number;
|
|
9
|
+
pageCount?: number;
|
|
10
|
+
pageNumber?: number;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export type WithOptional<TInput, Tkeys extends keyof TInput> = Omit<TInput, Tkeys> & Partial<Pick<TInput, Tkeys>>;
|
|
14
|
+
export type PickPartial<TInput, Tkeys extends keyof TInput> = Pick<Partial<TInput>, Tkeys>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { UseQueryOptions } from '@tanstack/react-query';
|
|
2
|
+
import type { GetByReferenceIdResponseBody } from '../schemas/GetByReferenceIdResponseBody';
|
|
3
|
+
import type { NotFound } from '../schemas/NotFound';
|
|
4
|
+
import type { ResponseWithPagination } from '../helpers';
|
|
5
|
+
import { FetcherOptions } from '../../../../fetcher/index.js';
|
|
6
|
+
export interface ReferenceIdentifiersGetByReferenceIdQueryPathParams {
|
|
7
|
+
/**
|
|
8
|
+
* @example "CWE-123"
|
|
9
|
+
*/
|
|
10
|
+
refId: string;
|
|
11
|
+
}
|
|
12
|
+
export interface ReferenceIdentifiersGetByReferenceIdQueryHeaderParams {
|
|
13
|
+
/**
|
|
14
|
+
* Harness personal or service access token
|
|
15
|
+
* @example "Atque quaerat aut."
|
|
16
|
+
*/
|
|
17
|
+
'X-Api-Key'?: string;
|
|
18
|
+
}
|
|
19
|
+
export type ReferenceIdentifiersGetByReferenceIdOkResponse = ResponseWithPagination<GetByReferenceIdResponseBody>;
|
|
20
|
+
export type ReferenceIdentifiersGetByReferenceIdErrorResponse = NotFound;
|
|
21
|
+
export interface ReferenceIdentifiersGetByReferenceIdProps extends ReferenceIdentifiersGetByReferenceIdQueryPathParams, Omit<FetcherOptions<unknown, unknown, ReferenceIdentifiersGetByReferenceIdQueryHeaderParams>, 'url'> {
|
|
22
|
+
}
|
|
23
|
+
export declare function referenceIdentifiersGetByReferenceId(props: ReferenceIdentifiersGetByReferenceIdProps): Promise<ReferenceIdentifiersGetByReferenceIdOkResponse>;
|
|
24
|
+
/**
|
|
25
|
+
* Reference Identifiers Lookup
|
|
26
|
+
*/
|
|
27
|
+
export declare function useReferenceIdentifiersGetByReferenceIdQuery(props: ReferenceIdentifiersGetByReferenceIdProps, options?: Omit<UseQueryOptions<ReferenceIdentifiersGetByReferenceIdOkResponse, ReferenceIdentifiersGetByReferenceIdErrorResponse>, 'queryKey' | 'queryFn'>): import("@tanstack/react-query").UseQueryResult<ReferenceIdentifiersGetByReferenceIdOkResponse, NotFound>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
// This code is autogenerated using @harnessio/oats-cli.
|
|
3
|
+
// Please do not modify this code directly.
|
|
4
|
+
import { useQuery } from '@tanstack/react-query';
|
|
5
|
+
import { fetcher } from '../../../../fetcher/index.js';
|
|
6
|
+
export function referenceIdentifiersGetByReferenceId(props) {
|
|
7
|
+
return fetcher(Object.assign({ url: `/api/v2/reference-identifiers/${props.refId}`, method: 'GET' }, props));
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Reference Identifiers Lookup
|
|
11
|
+
*/
|
|
12
|
+
export function useReferenceIdentifiersGetByReferenceIdQuery(props, options) {
|
|
13
|
+
return useQuery(['Reference Identifiers#getByReferenceId', props.refId], ({ signal }) => referenceIdentifiersGetByReferenceId(Object.assign(Object.assign({}, props), { signal })), options);
|
|
14
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { GetPathParamsType, ResponseWithPagination } from './helpers';
|
|
2
|
+
export type { ReferenceIdentifiersGetByReferenceIdErrorResponse, ReferenceIdentifiersGetByReferenceIdOkResponse, ReferenceIdentifiersGetByReferenceIdProps, ReferenceIdentifiersGetByReferenceIdQueryPathParams, } from './hooks/useReferenceIdentifiersGetByReferenceIdQuery';
|
|
3
|
+
export { referenceIdentifiersGetByReferenceId, useReferenceIdentifiersGetByReferenceIdQuery, } from './hooks/useReferenceIdentifiersGetByReferenceIdQuery';
|
|
4
|
+
export type { GetByReferenceIdResponseBody } from './schemas/GetByReferenceIdResponseBody';
|
|
5
|
+
export type { NotFound } from './schemas/NotFound';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { referenceIdentifiersGetByReferenceId, useReferenceIdentifiersGetByReferenceIdQuery, } from './hooks/useReferenceIdentifiersGetByReferenceIdQuery';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @example {"description":"Ut vitae doloremque.","extendedDescription":"Saepe atque est molestias.","remediationSteps":"Voluptas voluptatem reiciendis tenetur quia.","severity":8.5,"severityCode":"High"}
|
|
3
|
+
*/
|
|
4
|
+
export interface GetByReferenceIdResponseBody {
|
|
5
|
+
/**
|
|
6
|
+
* A short description of the identified issue.
|
|
7
|
+
* @example "Corporis consectetur aut quas veritatis."
|
|
8
|
+
*/
|
|
9
|
+
description?: string;
|
|
10
|
+
/**
|
|
11
|
+
* A more detailed explanation of the issue and its potential impact.
|
|
12
|
+
* @example "Totam voluptatem nihil earum."
|
|
13
|
+
*/
|
|
14
|
+
extendedDescription?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Steps the developer can take to address or mitigate the issue.
|
|
17
|
+
* @example "Quod itaque unde suscipit facere molestiae delectus."
|
|
18
|
+
*/
|
|
19
|
+
remediationSteps?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Numeric severity, from 0 (lowest) to 10 (highest)
|
|
22
|
+
* @format double
|
|
23
|
+
* @example 8.5
|
|
24
|
+
*/
|
|
25
|
+
severity?: number;
|
|
26
|
+
/**
|
|
27
|
+
* Severity code
|
|
28
|
+
* @example "High"
|
|
29
|
+
*/
|
|
30
|
+
severityCode?: string;
|
|
31
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@harnessio/react-sto-core-client",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Harness STO service APIs integrated with react hooks",
|
|
5
|
+
"author": "Harness Inc",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"source": "src/index.ts",
|
|
8
|
+
"main": "./dist/sto-core/src/index.js",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./dist/sto-core/src/index.js"
|
|
11
|
+
},
|
|
12
|
+
"types": "./dist/sto-core/src/index.d.ts",
|
|
13
|
+
"files": [
|
|
14
|
+
"dist/*"
|
|
15
|
+
],
|
|
16
|
+
"homepage": "https://github.com/harness/react-api-client",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/harness/react-api-client.git"
|
|
20
|
+
},
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/harness/react-api-client/issues"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"prebuild": "rimraf dist",
|
|
27
|
+
"build": "yarn generate && tsc",
|
|
28
|
+
"generate": "oats import --config='./oats.config.ts'",
|
|
29
|
+
"fmt": "prettier --write ./index.ts"
|
|
30
|
+
},
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": "^16"
|
|
33
|
+
}
|
|
34
|
+
}
|