Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
shivam-pareek committed Sep 26, 2024
1 parent c762db2 commit ee663fb
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 2 deletions.
113 changes: 113 additions & 0 deletions src/apis/apiKeys.ts
Original file line number Diff line number Diff line change
@@ -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<string, unknown>;
isDefault: number;
workspace_id:string;
}

export interface ApiKeysRetrieveParams {
slug: string;
}

export interface ApiKeysUpdateParams {
slug?: string;
name?: string;
config?: Record<string, unknown>;
status?: string;
}
export interface ApiKeysListParams {
page_size?: number;
current_page?: number;
workspace_id?: string;
}

export interface ApiKeysCreateResponse extends APIResponseType {
success: boolean;
data: Record<string, unknown>;
}
export interface ApiKeysRetrieveResponse extends APIResponseType {
success: boolean;
data: Record<string, unknown>;
}
export interface ApiKeysListResponse extends APIResponseType {
sucess: boolean;
data: Record<string, unknown>[];
}
export interface ApiKeysUpdateResponse extends APIResponseType {
success: boolean;
data: Record<string, unknown>;
}
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<ApiKeysCreateResponse> {
const body = _body;
if (params) {
this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) }
}
const response = this.post<ApiKeysCreateResponse>('/configs', { body, ...opts });
return response;
}

retrieve(
_body: ApiKeysRetrieveParams,
params?: ApiClientInterface,
opts?: RequestOptions
): APIPromise<ApiKeysRetrieveResponse> {
const body = _body;
const slug = body.slug;
if (params) {
this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) }
}
const response = this.get<ApiKeysRetrieveResponse>(`/configs/${slug}`, { body, ...opts });
return response;
}

update(
_body: ApiKeysUpdateParams,
params?: ApiClientInterface,
opts?: RequestOptions
): APIPromise<ApiKeysUpdateResponse> {
const body = _body;
const slug = body.slug;
if (params) {
this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) }
}
const response = this.put<ApiKeysUpdateResponse>(`/configs/${slug}`, { body, ...opts });
return response;
}
list(
_body: ApiKeysListParams,
params?: ApiClientInterface,
opts?: RequestOptions
):APIPromise<ApiKeysListResponse>{
const body = _body;
if (params) {
this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) }
}
const query = toQueryParams(body);
const response = this.get<ApiKeysListResponse>('/configs', { body, ...opts });
return response;
}
}
3 changes: 2 additions & 1 deletion src/apis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ export { Moderations } from "./moderations"
export { Audio } from "./audio"
export { VectorStores } from "./vectorStores"
export { BetaChat } from "./betaChat"
export { Uploads } from "./uploads"
export { Uploads } from "./uploads"
export { ApiKeys } from "./apiKeys"
2 changes: 1 addition & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,14 @@ 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),
vectorStores: new API.VectorStores(this),
chat: new API.BetaChat(this),
};


post = (
url: string,
_body: PostBodyParams,
Expand Down

0 comments on commit ee663fb

Please sign in to comment.