@harnessio/react-ti-service-client 0.3.0 → 0.3.2

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.
@@ -1,4 +1,4 @@
1
- import { ClientCallbacks } from '../../fetcher';
1
+ import { ClientCallbacks } from '../../custom-fetcher';
2
2
  export * from './services/index';
3
3
  export declare class TIServiceAPIClient {
4
4
  updateHeaders: (headers: Record<string, any>) => void;
@@ -1,4 +1,4 @@
1
- import { setupClient, updateClientHeaders } from '../../fetcher';
1
+ import { setupClient, updateClientHeaders } from '../../custom-fetcher';
2
2
  export * from './services/index';
3
3
  export class TIServiceAPIClient {
4
4
  constructor(callbacks) {
@@ -1,4 +1,4 @@
1
1
  import type { ReportOutput } from '../schemas/ReportOutput';
2
2
  export interface PipelineExecutionReport extends ReportOutput {
3
- type?: 'dir' | 'file' | 'repo';
3
+ type?: 'directory' | 'file' | 'repository';
4
4
  }
@@ -1,3 +1 @@
1
- export interface SearchResults {
2
- files: string[];
3
- }
1
+ export type SearchResults = string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@harnessio/react-ti-service-client",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "Harness React TI service client - TI APIs integrated with react hooks",
5
5
  "author": "Harness Inc",
6
6
  "license": "MIT",
@@ -1,17 +0,0 @@
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>;
@@ -1,65 +0,0 @@
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(Object.assign({}, (token ? { 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
- }