Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/api keys #122

Merged
merged 20 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 157 additions & 0 deletions src/apis/apiKeys.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
import { ApiResource } from "../apiResource";
import { APIResponseType, ApiClientInterface } from "../_types/generalTypes";
import { APIPromise, RequestOptions } from "../baseClient";
import { createHeaders } from "./createHeaders";

export interface ApiKeysAddParams {
type?: string;
"sub-type"?: string;
name?: string;
description?: string;
workspace_id?:string;
user_id?:string;
rate_limits?: Record<string, unknown>[];
usage_limits?: Record<string, unknown>;
scopes: string[];
defaults?: Record<string, unknown>;
}
export interface ApiKeysAddResponse extends APIResponseType {
id?: string;
key?: string;
object?: string;
}
export interface ApiKeysGetParams {
id?: string;
}
export interface ApiKeysGetResponse extends APIResponseType {
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<string, unknown>[];
usage_limits?: Record<string, unknown>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Record of the type string, any or it has to be unknown?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also check for the same in the other interfaces as well

reset_usage?:number;
scopes?: string[];
defaults?: Record<string, unknown>;
object?: string;
}
export interface ApiKeysUpdateParams {
id?: string;
name?: string;
description?: string;
rate_limits?: Record<string, unknown>[];
usage_limits?: Record<string, unknown>;
scopes?: string[];
defaults?: Record<string, unknown>;
}
export interface ApiKeysUpdateResponse extends APIResponseType {
object?: string;
total?:number;
data?: Record<string, unknown>[];
}
export interface ApiKeysListParams {
page_size?: number;
current_page?: number;
workspace_id?: string;
}
export interface ApiKeysListResponse extends APIResponseType {
total?: number;
object?: string;
data?: Record<string, unknown>[];
}
export interface ApiKeysDeleteParams {
id?: string;
}

function toQueryParams(params?: ApiKeysListParams): string {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract this function of utils.ts

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);
}
add(
_body: ApiKeysAddParams,
params?: ApiClientInterface,
opts?: RequestOptions
): APIPromise<ApiKeysAddResponse> {
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<ApiKeysAddResponse>(`/api-keys/${type}/${subType}`, { body, ...opts });
return response;
}

get(
_body: ApiKeysGetParams,
params?: ApiClientInterface,
opts?: RequestOptions
): APIPromise<ApiKeysGetResponse> {
const body = _body;
const id = body.id;
if (params) {
this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) }
}
const response = this.getMethod<ApiKeysGetResponse>(`/api-keys/${id}`, { ...opts });
return response;
}

update(
_body: ApiKeysUpdateParams,
params?: ApiClientInterface,
opts?: RequestOptions
): APIPromise<ApiKeysUpdateResponse> {
const body = _body;
const id = body.id;
if (params) {
this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) }
}
const response = this.put<ApiKeysUpdateResponse>(`/api-keys/${id}`, { 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.getMethod<ApiKeysListResponse>(`/api-keys${query}`, {...opts });
return response;
}
delete(
_body: ApiKeysDeleteParams,
params?: ApiClientInterface,
opts?: RequestOptions
):APIPromise<any>{
const body = _body;
const id=body.id;
if (params) {
this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) }
}
const response = this.deleteMethod<any>(`/api-keys/${id}`, { 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 @@ -148,14 +148,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
Loading