@petercatai/whisker-client 0.1.202504091947-dev → 0.1.202504100540

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.
Files changed (3) hide show
  1. package/dist/api.d.ts +66 -48
  2. package/dist/api.js +98 -45
  3. package/package.json +3 -3
package/dist/api.d.ts CHANGED
@@ -58,7 +58,7 @@ export interface IChunk {
58
58
  * Metadata
59
59
  * Arbitrary metadata associated with the content.
60
60
  */
61
- metadata?: object | null;
61
+ metadata?: Record<string, any> | null;
62
62
  /**
63
63
  * Gmt Create
64
64
  * creation time
@@ -130,7 +130,7 @@ export interface IGithubRepoCreate {
130
130
  * additional metadata, user can update it
131
131
  * @default {}
132
132
  */
133
- metadata?: object;
133
+ metadata?: Record<string, any>;
134
134
  /** source type */
135
135
  source_type: IKnowledgeSourceEnum;
136
136
  /**
@@ -206,7 +206,7 @@ export interface IImageCreate {
206
206
  * additional metadata, user can update it
207
207
  * @default {}
208
208
  */
209
- metadata?: object;
209
+ metadata?: Record<string, any>;
210
210
  /** source type */
211
211
  source_type: IKnowledgeSourceEnum;
212
212
  /**
@@ -255,7 +255,7 @@ export interface IJSONCreate {
255
255
  * additional metadata, user can update it
256
256
  * @default {}
257
257
  */
258
- metadata?: object;
258
+ metadata?: Record<string, any>;
259
259
  /** source type */
260
260
  source_type: IKnowledgeSourceEnum;
261
261
  /**
@@ -381,7 +381,7 @@ export interface IKnowledge {
381
381
  * Metadata
382
382
  * additional metadata, user can update it
383
383
  */
384
- metadata?: object | null;
384
+ metadata?: Record<string, any> | null;
385
385
  /**
386
386
  * Parent Id
387
387
  * parent knowledge id
@@ -472,7 +472,7 @@ export interface IKnowledgeCreate {
472
472
  * additional metadata, user can update it
473
473
  * @default {}
474
474
  */
475
- metadata?: object;
475
+ metadata?: Record<string, any>;
476
476
  /**
477
477
  * Parent Id
478
478
  * parent knowledge id
@@ -530,7 +530,7 @@ export interface IMarkdownCreate {
530
530
  * additional metadata, user can update it
531
531
  * @default {}
532
532
  */
533
- metadata?: object;
533
+ metadata?: Record<string, any>;
534
534
  /** source type */
535
535
  source_type: IKnowledgeSourceEnum;
536
536
  /**
@@ -626,7 +626,7 @@ export interface IPDFCreate {
626
626
  * additional metadata, user can update it
627
627
  * @default {}
628
628
  */
629
- metadata?: object;
629
+ metadata?: Record<string, any>;
630
630
  /** source type */
631
631
  source_type: IKnowledgeSourceEnum;
632
632
  /**
@@ -728,7 +728,7 @@ export interface IPageParamsChunk {
728
728
  * Eq Conditions
729
729
  * list of equality conditions, each as a dict with key and value
730
730
  */
731
- eq_conditions?: object | null;
731
+ eq_conditions?: Record<string, any> | null;
732
732
  }
733
733
  /** PageParams[Knowledge] */
734
734
  export interface IPageParamsKnowledge {
@@ -762,7 +762,7 @@ export interface IPageParamsKnowledge {
762
762
  * Eq Conditions
763
763
  * list of equality conditions, each as a dict with key and value
764
764
  */
765
- eq_conditions?: object | null;
765
+ eq_conditions?: Record<string, any> | null;
766
766
  }
767
767
  /** PageParams[Task] */
768
768
  export interface IPageParamsTask {
@@ -796,7 +796,7 @@ export interface IPageParamsTask {
796
796
  * Eq Conditions
797
797
  * list of equality conditions, each as a dict with key and value
798
798
  */
799
- eq_conditions?: object | null;
799
+ eq_conditions?: Record<string, any> | null;
800
800
  }
801
801
  /** PageResponse[Chunk] */
802
802
  export interface IPageResponseChunk {
@@ -861,7 +861,7 @@ export interface IQACreate {
861
861
  * additional metadata, user can update it
862
862
  * @default {}
863
863
  */
864
- metadata?: object;
864
+ metadata?: Record<string, any>;
865
865
  /** source type */
866
866
  source_type: IKnowledgeSourceEnum;
867
867
  /**
@@ -1017,7 +1017,7 @@ export interface IRetrievalByKnowledgeRequest {
1017
1017
  * metadata filter
1018
1018
  * @default {}
1019
1019
  */
1020
- metadata_filter?: object;
1020
+ metadata_filter?: Record<string, any>;
1021
1021
  /**
1022
1022
  * Knowledge Id List
1023
1023
  * knowledge id list
@@ -1053,7 +1053,7 @@ export interface IRetrievalBySpaceRequest {
1053
1053
  * metadata filter
1054
1054
  * @default {}
1055
1055
  */
1056
- metadata_filter?: object;
1056
+ metadata_filter?: Record<string, any>;
1057
1057
  /**
1058
1058
  * Space Id List
1059
1059
  * space id list
@@ -1101,7 +1101,7 @@ export interface IRetrievalChunk {
1101
1101
  * Metadata
1102
1102
  * Arbitrary metadata associated with the content.
1103
1103
  */
1104
- metadata?: object | null;
1104
+ metadata?: Record<string, any> | null;
1105
1105
  /**
1106
1106
  * Gmt Create
1107
1107
  * creation time
@@ -1177,7 +1177,7 @@ export interface ITask {
1177
1177
  * Metadata
1178
1178
  * Metadata for the task
1179
1179
  */
1180
- metadata?: object | null;
1180
+ metadata?: Record<string, any> | null;
1181
1181
  /**
1182
1182
  * Error Message
1183
1183
  * Error message (only present if the task failed)
@@ -1299,7 +1299,7 @@ export interface ITextCreate {
1299
1299
  * additional metadata, user can update it
1300
1300
  * @default {}
1301
1301
  */
1302
- metadata?: object;
1302
+ metadata?: Record<string, any>;
1303
1303
  /** source type */
1304
1304
  source_type: IKnowledgeSourceEnum;
1305
1305
  /**
@@ -1366,13 +1366,13 @@ export interface ITextSplitConfig {
1366
1366
  * Whether to keep the separator and where to place it in each corresponding chunk (True='start')
1367
1367
  * @default false
1368
1368
  */
1369
- keep_separator?: boolean | "start" | "end" | null;
1369
+ keep_separator?: boolean | "start" | "end";
1370
1370
  /**
1371
1371
  * Strip Whitespace
1372
1372
  * If `True`, strips whitespace from the start and end of every document
1373
1373
  * @default false
1374
1374
  */
1375
- strip_whitespace?: boolean | null;
1375
+ strip_whitespace?: boolean;
1376
1376
  }
1377
1377
  /** ValidationError */
1378
1378
  export interface IValidationError {
@@ -1383,9 +1383,9 @@ export interface IValidationError {
1383
1383
  /** Error Type */
1384
1384
  type: string;
1385
1385
  }
1386
- import type { AxiosInstance, AxiosRequestConfig, ResponseType } from "axios";
1387
1386
  export type QueryParamsType = Record<string | number, any>;
1388
- export interface FullRequestParams extends Omit<AxiosRequestConfig, "data" | "params" | "url" | "responseType"> {
1387
+ export type ResponseFormat = keyof Omit<Body, "body" | "bodyUsed">;
1388
+ export interface FullRequestParams extends Omit<RequestInit, "body"> {
1389
1389
  /** set parameter to `true` for call `securityWorker` for this request */
1390
1390
  secure?: boolean;
1391
1391
  /** request path */
@@ -1395,16 +1395,26 @@ export interface FullRequestParams extends Omit<AxiosRequestConfig, "data" | "pa
1395
1395
  /** query params */
1396
1396
  query?: QueryParamsType;
1397
1397
  /** format of response (i.e. response.json() -> format: "json") */
1398
- format?: ResponseType;
1398
+ format?: ResponseFormat;
1399
1399
  /** request body */
1400
1400
  body?: unknown;
1401
+ /** base url */
1402
+ baseUrl?: string;
1403
+ /** request cancellation token */
1404
+ cancelToken?: CancelToken;
1401
1405
  }
1402
1406
  export type RequestParams = Omit<FullRequestParams, "body" | "method" | "query" | "path">;
1403
- export interface ApiConfig<SecurityDataType = unknown> extends Omit<AxiosRequestConfig, "data" | "cancelToken"> {
1404
- securityWorker?: (securityData: SecurityDataType | null) => Promise<AxiosRequestConfig | void> | AxiosRequestConfig | void;
1405
- secure?: boolean;
1406
- format?: ResponseType;
1407
+ export interface ApiConfig<SecurityDataType = unknown> {
1408
+ baseUrl?: string;
1409
+ baseApiParams?: Omit<RequestParams, "baseUrl" | "cancelToken" | "signal">;
1410
+ securityWorker?: (securityData: SecurityDataType | null) => Promise<RequestParams | void> | RequestParams | void;
1411
+ customFetch?: typeof fetch;
1412
+ }
1413
+ export interface HttpResponse<D extends unknown, E extends unknown = unknown> extends Response {
1414
+ data: D;
1415
+ error: E;
1407
1416
  }
1417
+ type CancelToken = Symbol | string | number;
1408
1418
  export declare enum ContentType {
1409
1419
  Json = "application/json",
1410
1420
  FormData = "multipart/form-data",
@@ -1412,17 +1422,24 @@ export declare enum ContentType {
1412
1422
  Text = "text/plain"
1413
1423
  }
1414
1424
  export declare class HttpClient<SecurityDataType = unknown> {
1415
- instance: AxiosInstance;
1425
+ baseUrl: string;
1416
1426
  private securityData;
1417
1427
  private securityWorker?;
1418
- private secure?;
1419
- private format?;
1420
- constructor({ securityWorker, secure, format, ...axiosConfig }?: ApiConfig<SecurityDataType>);
1428
+ private abortControllers;
1429
+ private customFetch;
1430
+ private baseApiParams;
1431
+ constructor(apiConfig?: ApiConfig<SecurityDataType>);
1421
1432
  setSecurityData: (data: SecurityDataType | null) => void;
1422
- protected mergeRequestParams(params1: AxiosRequestConfig, params2?: AxiosRequestConfig): AxiosRequestConfig;
1423
- protected stringifyFormItem(formItem: unknown): string;
1424
- protected createFormData(input: Record<string, unknown>): FormData;
1425
- request: <T = any, _E = any>({ secure, path, type, query, format, body, ...params }: FullRequestParams) => Promise<T>;
1433
+ protected encodeQueryParam(key: string, value: any): string;
1434
+ protected addQueryParam(query: QueryParamsType, key: string): string;
1435
+ protected addArrayQueryParam(query: QueryParamsType, key: string): any;
1436
+ protected toQueryString(rawQuery?: QueryParamsType): string;
1437
+ protected addQueryParams(rawQuery?: QueryParamsType): string;
1438
+ private contentFormatters;
1439
+ protected mergeRequestParams(params1: RequestParams, params2?: RequestParams): RequestParams;
1440
+ protected createAbortSignal: (cancelToken: CancelToken) => AbortSignal | undefined;
1441
+ abortRequest: (cancelToken: CancelToken) => void;
1442
+ request: <T = any, E = any>({ body, secure, path, type, query, format, baseUrl, cancelToken, ...params }: FullRequestParams) => Promise<HttpResponse<T, E>>;
1426
1443
  }
1427
1444
  /**
1428
1445
  * @title whisker rag server
@@ -1436,7 +1453,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
1436
1453
  * @summary Home Page
1437
1454
  * @request GET:/
1438
1455
  */
1439
- homePageGet: (params?: RequestParams) => Promise<any>;
1456
+ homePageGet: (params?: RequestParams) => Promise<HttpResponse<any, any>>;
1440
1457
  knowledge: {
1441
1458
  /**
1442
1459
  * @description Duplicate file_sha entries are prohibited. Any modifications to split_config or embedding model_name parameters must be performed using dedicated API endpoints."
@@ -1446,7 +1463,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
1446
1463
  * @summary Add Knowledge
1447
1464
  * @request POST:/api/knowledge/add
1448
1465
  */
1449
- addKnowledge: (data: (IKnowledgeCreate | ITextCreate | IImageCreate | IJSONCreate | IMarkdownCreate | IPDFCreate | IGithubRepoCreate | IQACreate)[], params?: RequestParams) => Promise<IResponseModelListKnowledge>;
1466
+ addKnowledge: (data: (IKnowledgeCreate | ITextCreate | IImageCreate | IJSONCreate | IMarkdownCreate | IPDFCreate | IGithubRepoCreate | IQACreate)[], params?: RequestParams) => Promise<HttpResponse<IResponseModelListKnowledge, void | IHTTPValidationError>>;
1450
1467
  /**
1451
1468
  * No description
1452
1469
  *
@@ -1455,7 +1472,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
1455
1472
  * @summary Get Knowledge List
1456
1473
  * @request POST:/api/knowledge/list
1457
1474
  */
1458
- getKnowledgeList: (data: IPageParamsKnowledge, params?: RequestParams) => Promise<IResponseModelPageResponseKnowledge>;
1475
+ getKnowledgeList: (data: IPageParamsKnowledge, params?: RequestParams) => Promise<HttpResponse<IResponseModelPageResponseKnowledge, void | IHTTPValidationError>>;
1459
1476
  /**
1460
1477
  * No description
1461
1478
  *
@@ -1467,7 +1484,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
1467
1484
  getKnowledgeById: (query: {
1468
1485
  /** Knowledge Id */
1469
1486
  knowledge_id: string;
1470
- }, params?: RequestParams) => Promise<IResponseModelKnowledge>;
1487
+ }, params?: RequestParams) => Promise<HttpResponse<IResponseModelKnowledge, void | IHTTPValidationError>>;
1471
1488
  /**
1472
1489
  * @description Deletes a knowledge entry by its ID.
1473
1490
  *
@@ -1479,7 +1496,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
1479
1496
  deleteKnowledge: (query: {
1480
1497
  /** Knowledge Id */
1481
1498
  knowledge_id: string;
1482
- }, params?: RequestParams) => Promise<IResponseModelNoneType>;
1499
+ }, params?: RequestParams) => Promise<HttpResponse<IResponseModelNoneType, void | IHTTPValidationError>>;
1483
1500
  };
1484
1501
  retrieval: {
1485
1502
  /**
@@ -1490,7 +1507,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
1490
1507
  * @summary Retrieve Knowledge Content
1491
1508
  * @request POST:/api/retrieval/knowledge
1492
1509
  */
1493
- retrieveKnowledgeContent: (data: IRetrievalByKnowledgeRequest, params?: RequestParams) => Promise<IResponseModelListRetrievalChunk>;
1510
+ retrieveKnowledgeContent: (data: IRetrievalByKnowledgeRequest, params?: RequestParams) => Promise<HttpResponse<IResponseModelListRetrievalChunk, void | IHTTPValidationError>>;
1494
1511
  /**
1495
1512
  * @description Retrieve chunks within a space_id, for example, given a petercat bot_id, retrieve all chunks under that bot_id.
1496
1513
  *
@@ -1499,7 +1516,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
1499
1516
  * @summary Retrieve Space Content
1500
1517
  * @request POST:/api/retrieval/space
1501
1518
  */
1502
- retrieveSpaceContent: (data: IRetrievalBySpaceRequest, params?: RequestParams) => Promise<IResponseModelListRetrievalChunk>;
1519
+ retrieveSpaceContent: (data: IRetrievalBySpaceRequest, params?: RequestParams) => Promise<HttpResponse<IResponseModelListRetrievalChunk, void | IHTTPValidationError>>;
1503
1520
  };
1504
1521
  task: {
1505
1522
  /**
@@ -1510,7 +1527,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
1510
1527
  * @summary Restart Task
1511
1528
  * @request POST:/api/task/restart
1512
1529
  */
1513
- restartTask: (data: ITaskRestartRequest, params?: RequestParams) => Promise<IResponseModelListTask>;
1530
+ restartTask: (data: ITaskRestartRequest, params?: RequestParams) => Promise<HttpResponse<IResponseModelListTask, void | IHTTPValidationError>>;
1514
1531
  /**
1515
1532
  * No description
1516
1533
  *
@@ -1519,7 +1536,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
1519
1536
  * @summary Get Task List
1520
1537
  * @request POST:/api/task/list
1521
1538
  */
1522
- getTaskList: (data: IPageParamsTask, params?: RequestParams) => Promise<IResponseModelPageResponseTask>;
1539
+ getTaskList: (data: IPageParamsTask, params?: RequestParams) => Promise<HttpResponse<IResponseModelPageResponseTask, void | IHTTPValidationError>>;
1523
1540
  /**
1524
1541
  * No description
1525
1542
  *
@@ -1531,7 +1548,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
1531
1548
  getTaskDetail: (query: {
1532
1549
  /** Task Id */
1533
1550
  task_id: string;
1534
- }, params?: RequestParams) => Promise<IResponseModelTask>;
1551
+ }, params?: RequestParams) => Promise<HttpResponse<IResponseModelTask, void | IHTTPValidationError>>;
1535
1552
  };
1536
1553
  chunk: {
1537
1554
  /**
@@ -1542,7 +1559,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
1542
1559
  * @summary Get Chunk List
1543
1560
  * @request POST:/api/chunk/list
1544
1561
  */
1545
- getChunkList: (data: IPageParamsChunk, params?: RequestParams) => Promise<IResponseModelPageResponseChunk>;
1562
+ getChunkList: (data: IPageParamsChunk, params?: RequestParams) => Promise<HttpResponse<IResponseModelPageResponseChunk, void | IHTTPValidationError>>;
1546
1563
  };
1547
1564
  tenant: {
1548
1565
  /**
@@ -1553,7 +1570,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
1553
1570
  * @summary Create Tenant
1554
1571
  * @request POST:/api/tenant/create
1555
1572
  */
1556
- createTenant: (data: ITenantCreate, params?: RequestParams) => Promise<IResponseModelTenant>;
1573
+ createTenant: (data: ITenantCreate, params?: RequestParams) => Promise<HttpResponse<IResponseModelTenant, void | IHTTPValidationError>>;
1557
1574
  /**
1558
1575
  * No description
1559
1576
  *
@@ -1562,7 +1579,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
1562
1579
  * @summary Get Tenant
1563
1580
  * @request GET:/api/tenant/me
1564
1581
  */
1565
- getTenant: (params?: RequestParams) => Promise<any>;
1582
+ getTenant: (params?: RequestParams) => Promise<HttpResponse<any, void | IHTTPValidationError>>;
1566
1583
  };
1567
1584
  healthChecker: {
1568
1585
  /**
@@ -1572,6 +1589,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
1572
1589
  * @summary Health Checker
1573
1590
  * @request GET:/api/health_checker
1574
1591
  */
1575
- healthCheckerApiHealthCheckerGet: (params?: RequestParams) => Promise<IResponseModel>;
1592
+ healthCheckerApiHealthCheckerGet: (params?: RequestParams) => Promise<HttpResponse<IResponseModel, any>>;
1576
1593
  };
1577
1594
  }
1595
+ export {};
package/dist/api.js CHANGED
@@ -21,9 +21,6 @@ var __rest = (this && this.__rest) || function (s, e) {
21
21
  }
22
22
  return t;
23
23
  };
24
- var __importDefault = (this && this.__importDefault) || function (mod) {
25
- return (mod && mod.__esModule) ? mod : { "default": mod };
26
- };
27
24
  Object.defineProperty(exports, "__esModule", { value: true });
28
25
  exports.Api = exports.HttpClient = exports.ContentType = exports.ITaskStatus = exports.IKnowledgeTypeEnum = exports.IKnowledgeSourceEnum = exports.IEmbeddingModelEnum = void 0;
29
26
  /** EmbeddingModelEnum */
@@ -69,7 +66,6 @@ var ITaskStatus;
69
66
  ITaskStatus["Canceled"] = "canceled";
70
67
  ITaskStatus["PendingRetry"] = "pending_retry";
71
68
  })(ITaskStatus || (exports.ITaskStatus = ITaskStatus = {}));
72
- const axios_1 = __importDefault(require("axios"));
73
69
  var ContentType;
74
70
  (function (ContentType) {
75
71
  ContentType["Json"] = "application/json";
@@ -78,60 +74,117 @@ var ContentType;
78
74
  ContentType["Text"] = "text/plain";
79
75
  })(ContentType || (exports.ContentType = ContentType = {}));
80
76
  class HttpClient {
81
- constructor(_a = {}) {
82
- var { securityWorker, secure, format } = _a, axiosConfig = __rest(_a, ["securityWorker", "secure", "format"]);
77
+ constructor(apiConfig = {}) {
78
+ this.baseUrl = "";
83
79
  this.securityData = null;
80
+ this.abortControllers = new Map();
81
+ this.customFetch = (...fetchParams) => fetch(...fetchParams);
82
+ this.baseApiParams = {
83
+ credentials: "same-origin",
84
+ headers: {},
85
+ redirect: "follow",
86
+ referrerPolicy: "no-referrer",
87
+ };
84
88
  this.setSecurityData = (data) => {
85
89
  this.securityData = data;
86
90
  };
91
+ this.contentFormatters = {
92
+ [ContentType.Json]: (input) => input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
93
+ [ContentType.Text]: (input) => (input !== null && typeof input !== "string" ? JSON.stringify(input) : input),
94
+ [ContentType.FormData]: (input) => Object.keys(input || {}).reduce((formData, key) => {
95
+ const property = input[key];
96
+ formData.append(key, property instanceof Blob
97
+ ? property
98
+ : typeof property === "object" && property !== null
99
+ ? JSON.stringify(property)
100
+ : `${property}`);
101
+ return formData;
102
+ }, new FormData()),
103
+ [ContentType.UrlEncoded]: (input) => this.toQueryString(input),
104
+ };
105
+ this.createAbortSignal = (cancelToken) => {
106
+ if (this.abortControllers.has(cancelToken)) {
107
+ const abortController = this.abortControllers.get(cancelToken);
108
+ if (abortController) {
109
+ return abortController.signal;
110
+ }
111
+ return void 0;
112
+ }
113
+ const abortController = new AbortController();
114
+ this.abortControllers.set(cancelToken, abortController);
115
+ return abortController.signal;
116
+ };
117
+ this.abortRequest = (cancelToken) => {
118
+ const abortController = this.abortControllers.get(cancelToken);
119
+ if (abortController) {
120
+ abortController.abort();
121
+ this.abortControllers.delete(cancelToken);
122
+ }
123
+ };
87
124
  this.request = async (_a) => {
88
- var { secure, path, type, query, format, body } = _a, params = __rest(_a, ["secure", "path", "type", "query", "format", "body"]);
89
- const secureParams = ((typeof secure === "boolean" ? secure : this.secure) &&
125
+ var { body, secure, path, type, query, format, baseUrl, cancelToken } = _a, params = __rest(_a, ["body", "secure", "path", "type", "query", "format", "baseUrl", "cancelToken"]);
126
+ const secureParams = ((typeof secure === "boolean" ? secure : this.baseApiParams.secure) &&
90
127
  this.securityWorker &&
91
128
  (await this.securityWorker(this.securityData))) ||
92
129
  {};
93
130
  const requestParams = this.mergeRequestParams(params, secureParams);
94
- const responseFormat = format || this.format || undefined;
95
- if (type === ContentType.FormData && body && body !== null && typeof body === "object") {
96
- body = this.createFormData(body);
97
- }
98
- if (type === ContentType.Text && body && body !== null && typeof body !== "string") {
99
- body = JSON.stringify(body);
100
- }
101
- return this.instance
102
- .request(Object.assign(Object.assign({}, requestParams), { headers: Object.assign(Object.assign({}, (requestParams.headers || {})), (type ? { "Content-Type": type } : {})), params: query, responseType: responseFormat, data: body, url: path }))
103
- .then((response) => response.data);
131
+ const queryString = query && this.toQueryString(query);
132
+ const payloadFormatter = this.contentFormatters[type || ContentType.Json];
133
+ const responseFormat = format || requestParams.format;
134
+ return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, Object.assign(Object.assign({}, requestParams), { headers: Object.assign(Object.assign({}, (requestParams.headers || {})), (type && type !== ContentType.FormData ? { "Content-Type": type } : {})), signal: (cancelToken ? this.createAbortSignal(cancelToken) : requestParams.signal) || null, body: typeof body === "undefined" || body === null ? null : payloadFormatter(body) })).then(async (response) => {
135
+ const r = response.clone();
136
+ r.data = null;
137
+ r.error = null;
138
+ const data = !responseFormat
139
+ ? r
140
+ : await response[responseFormat]()
141
+ .then((data) => {
142
+ if (r.ok) {
143
+ r.data = data;
144
+ }
145
+ else {
146
+ r.error = data;
147
+ }
148
+ return r;
149
+ })
150
+ .catch((e) => {
151
+ r.error = e;
152
+ return r;
153
+ });
154
+ if (cancelToken) {
155
+ this.abortControllers.delete(cancelToken);
156
+ }
157
+ if (!response.ok)
158
+ throw data;
159
+ return data;
160
+ });
104
161
  };
105
- this.instance = axios_1.default.create(Object.assign(Object.assign({}, axiosConfig), { baseURL: axiosConfig.baseURL || "" }));
106
- this.secure = secure;
107
- this.format = format;
108
- this.securityWorker = securityWorker;
162
+ Object.assign(this, apiConfig);
109
163
  }
110
- mergeRequestParams(params1, params2) {
111
- const method = params1.method || (params2 && params2.method);
112
- return Object.assign(Object.assign(Object.assign(Object.assign({}, this.instance.defaults), params1), (params2 || {})), { headers: Object.assign(Object.assign(Object.assign({}, ((method && this.instance.defaults.headers[method.toLowerCase()]) || {})), (params1.headers || {})), ((params2 && params2.headers) || {})) });
164
+ encodeQueryParam(key, value) {
165
+ const encodedKey = encodeURIComponent(key);
166
+ return `${encodedKey}=${encodeURIComponent(typeof value === "number" ? value : `${value}`)}`;
113
167
  }
114
- stringifyFormItem(formItem) {
115
- if (typeof formItem === "object" && formItem !== null) {
116
- return JSON.stringify(formItem);
117
- }
118
- else {
119
- return `${formItem}`;
120
- }
168
+ addQueryParam(query, key) {
169
+ return this.encodeQueryParam(key, query[key]);
121
170
  }
122
- createFormData(input) {
123
- if (input instanceof FormData) {
124
- return input;
125
- }
126
- return Object.keys(input || {}).reduce((formData, key) => {
127
- const property = input[key];
128
- const propertyContent = property instanceof Array ? property : [property];
129
- for (const formItem of propertyContent) {
130
- const isFileType = formItem instanceof Blob || formItem instanceof File;
131
- formData.append(key, isFileType ? formItem : this.stringifyFormItem(formItem));
132
- }
133
- return formData;
134
- }, new FormData());
171
+ addArrayQueryParam(query, key) {
172
+ const value = query[key];
173
+ return value.map((v) => this.encodeQueryParam(key, v)).join("&");
174
+ }
175
+ toQueryString(rawQuery) {
176
+ const query = rawQuery || {};
177
+ const keys = Object.keys(query).filter((key) => "undefined" !== typeof query[key]);
178
+ return keys
179
+ .map((key) => (Array.isArray(query[key]) ? this.addArrayQueryParam(query, key) : this.addQueryParam(query, key)))
180
+ .join("&");
181
+ }
182
+ addQueryParams(rawQuery) {
183
+ const queryString = this.toQueryString(rawQuery);
184
+ return queryString ? `?${queryString}` : "";
185
+ }
186
+ mergeRequestParams(params1, params2) {
187
+ return Object.assign(Object.assign(Object.assign(Object.assign({}, this.baseApiParams), params1), (params2 || {})), { headers: Object.assign(Object.assign(Object.assign({}, (this.baseApiParams.headers || {})), (params1.headers || {})), ((params2 && params2.headers) || {})) });
135
188
  }
136
189
  }
137
190
  exports.HttpClient = HttpClient;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@petercatai/whisker-client",
3
- "version": "0.1.202504091947-dev",
4
- "description": "Generated API client (Preview)",
3
+ "version": "0.1.202504100540",
4
+ "description": "Generated API client (Production)",
5
5
  "main": "dist/api.js",
6
6
  "types": "dist/api.d.ts",
7
7
  "files": [
@@ -13,7 +13,7 @@
13
13
  },
14
14
  "publishConfig": {
15
15
  "access": "public",
16
- "tag": "dev"
16
+ "tag": "latest"
17
17
  },
18
18
  "devDependencies": {
19
19
  "@types/node": "^22.14.0",