diff --git a/src/apis/apiKeys.ts b/src/apis/apiKeys.ts new file mode 100644 index 0000000..6d65558 --- /dev/null +++ b/src/apis/apiKeys.ts @@ -0,0 +1,113 @@ +import { ApiResource } from "../apiResource"; +import { APIResponseType, ApiClientInterface } from "../_types/generalTypes"; +import { APIPromise, RequestOptions } from "../baseClient"; +import { createHeaders } from "./createHeaders"; + +export interface ApiKeysCreateParams { + name: string; + config: Record; + isDefault: number; + workspace_id:string; +} + +export interface ApiKeysRetrieveParams { + slug: string; +} + +export interface ApiKeysUpdateParams { + slug?: string; + name?: string; + config?: Record; + status?: string; +} +export interface ApiKeysListParams { + page_size?: number; + current_page?: number; + workspace_id?: string; +} + +export interface ApiKeysCreateResponse extends APIResponseType { + success: boolean; + data: Record; +} +export interface ApiKeysRetrieveResponse extends APIResponseType { + success: boolean; + data: Record; +} +export interface ApiKeysListResponse extends APIResponseType { + sucess: boolean; + data: Record[]; +} +export interface ApiKeysUpdateResponse extends APIResponseType { + success: boolean; + data: Record; +} +function toQueryParams(params?: ApiKeysListResponse): string { + if (!params) { + return ''; + } + const queryParams = Object.entries(params) + .filter(([, value]) => value !== undefined && value !== null) + .map(([key, value]) => `${key}=${value}`) + .join('&'); + + return queryParams ? `?${queryParams}` : ''; +} +export class ApiKeys extends ApiResource { + constructor(client: any) { + super(client); + } + create( + _body: ApiKeysCreateParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const body = _body; + if (params) { + this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) } + } + const response = this.post('/configs', { body, ...opts }); + return response; + } + + retrieve( + _body: ApiKeysRetrieveParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const body = _body; + const slug = body.slug; + if (params) { + this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) } + } + const response = this.get(`/configs/${slug}`, { body, ...opts }); + return response; + } + + update( + _body: ApiKeysUpdateParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const body = _body; + const slug = body.slug; + if (params) { + this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) } + } + const response = this.put(`/configs/${slug}`, { body, ...opts }); + return response; + } + list( + _body: ApiKeysListParams, + params?: ApiClientInterface, + opts?: RequestOptions + ):APIPromise{ + const body = _body; + if (params) { + this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) } + } + const query = toQueryParams(body); + const response = this.get('/configs', { body, ...opts }); + return response; + } +} diff --git a/src/apis/index.ts b/src/apis/index.ts index a127a15..5200607 100644 --- a/src/apis/index.ts +++ b/src/apis/index.ts @@ -17,4 +17,5 @@ export { Moderations } from "./moderations" export { Audio } from "./audio" export { VectorStores } from "./vectorStores" export { BetaChat } from "./betaChat" -export { Uploads } from "./uploads" \ No newline at end of file +export { Uploads } from "./uploads" +export { ApiKeys } from "./apiKeys" \ No newline at end of file diff --git a/src/client.ts b/src/client.ts index e490e4d..c66d6b5 100644 --- a/src/client.ts +++ b/src/client.ts @@ -144,6 +144,7 @@ export class Portkey extends ApiClient { audio = new API.Audio(this); uploads = new API.Uploads(this); admin = new API.Admin(this); + apiKeys = new API.ApiKeys(this); beta = { assistants: new API.Assistants(this), threads: new API.Threads(this), @@ -151,7 +152,6 @@ export class Portkey extends ApiClient { chat: new API.BetaChat(this), }; - post = ( url: string, _body: PostBodyParams,