From a80a0c8f5cee55fe23e67347c60f67748751bd49 Mon Sep 17 00:00:00 2001 From: shivam-pareek Date: Mon, 30 Sep 2024 15:15:00 +0530 Subject: [PATCH] feat: add api-keys endpoint --- src/apis/apiKeys.ts | 93 +++++++++++++++++++++++++++++++++------------ 1 file changed, 69 insertions(+), 24 deletions(-) diff --git a/src/apis/apiKeys.ts b/src/apis/apiKeys.ts index 6d65558..cd3f4c6 100644 --- a/src/apis/apiKeys.ts +++ b/src/apis/apiKeys.ts @@ -4,45 +4,75 @@ import { APIPromise, RequestOptions } from "../baseClient"; import { createHeaders } from "./createHeaders"; export interface ApiKeysCreateParams { - name: string; - config: Record; - isDefault: number; - workspace_id:string; + type?: string; + "sub-type"?: string; + name?: string; + description?: string; + workspace_id?:string; + user_id?:string; + rate_limits?: Record[]; + usage_limits?: Record; + scopes: string[]; + defaults?: Record; } export interface ApiKeysRetrieveParams { - slug: string; + id?: string; } export interface ApiKeysUpdateParams { - slug?: string; + id?: string; name?: string; - config?: Record; - status?: string; + description?: string; + rate_limits?: Record[]; + usage_limits?: Record; + scopes?: string[]; + defaults?: Record; } export interface ApiKeysListParams { page_size?: number; current_page?: number; workspace_id?: string; } - +export interface ApiKeysDeleteParams { + id?: string; +} export interface ApiKeysCreateResponse extends APIResponseType { - success: boolean; - data: Record; + id?: string; + key?: string; + object?: string; } export interface ApiKeysRetrieveResponse extends APIResponseType { - success: boolean; - data: Record; + id?: string; + key?: string; + name?: string; + description?: string; + type?: string; + organisation_id?: string; + workspace_id?: string; + user_id?: string; + status?: string; + created_at?: Date; + last_updated_at?: Date; + creation_mode?: string; + rate_limits?: Record[]; + usage_limits?: Record; + reset_usage?:number; + scopes?: string[]; + defaults?: Record; + object?: string; } export interface ApiKeysListResponse extends APIResponseType { - sucess: boolean; - data: Record[]; + total?: number; + object?: string; + data?: Record[]; } export interface ApiKeysUpdateResponse extends APIResponseType { - success: boolean; - data: Record; + object?: string; + total?:number; + data?: Record[]; } -function toQueryParams(params?: ApiKeysListResponse): string { +function toQueryParams(params?: ApiKeysListParams): string { if (!params) { return ''; } @@ -63,10 +93,12 @@ export class ApiKeys extends ApiResource { opts?: RequestOptions ): APIPromise { const body = _body; + const type = body.type; + const subType = body["sub-type"]; if (params) { this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) } } - const response = this.post('/configs', { body, ...opts }); + const response = this.post(`/api-keys/${type}/${subType}`, { body, ...opts }); return response; } @@ -76,11 +108,11 @@ export class ApiKeys extends ApiResource { opts?: RequestOptions ): APIPromise { const body = _body; - const slug = body.slug; + const id = body.id; if (params) { this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) } } - const response = this.get(`/configs/${slug}`, { body, ...opts }); + const response = this.get(`/api-keys/${id}`, { body, ...opts }); return response; } @@ -90,11 +122,11 @@ export class ApiKeys extends ApiResource { opts?: RequestOptions ): APIPromise { const body = _body; - const slug = body.slug; + const id = body.id; if (params) { this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) } } - const response = this.put(`/configs/${slug}`, { body, ...opts }); + const response = this.put(`/api-keys/${id}`, { body, ...opts }); return response; } list( @@ -107,7 +139,20 @@ export class ApiKeys extends ApiResource { this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) } } const query = toQueryParams(body); - const response = this.get('/configs', { body, ...opts }); + const response = this.get(`/api-keys${query}`, { body, ...opts }); + return response; + } + delete( + _body: ApiKeysDeleteParams, + params?: ApiClientInterface, + opts?: RequestOptions + ):APIPromise{ + const body = _body; + const id=body.id; + if (params) { + this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) } + } + const response = this.deleteMethod(`/api-keys/${id}`, { body, ...opts }); return response; } }