-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #122 from Portkey-AI/feat/apiKeys
Feat/api keys
- Loading branch information
Showing
4 changed files
with
155 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
import { ApiResource } from "../apiResource"; | ||
import { APIResponseType, ApiClientInterface } from "../_types/generalTypes"; | ||
import { APIPromise, RequestOptions } from "../baseClient"; | ||
import { createHeaders } from "./createHeaders"; | ||
import { toQueryParams } from "../utils"; | ||
|
||
export interface ApiKeysAddParams { | ||
type?: string; | ||
"sub-type"?: string; | ||
name?: string; | ||
description?: string; | ||
workspace_id?:string; | ||
user_id?:string; | ||
rate_limits?: Record<string, any>[]; | ||
usage_limits?: Record<string, any>; | ||
scopes: string[]; | ||
defaults?: Record<string, any>; | ||
} | ||
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, any>[]; | ||
usage_limits?: Record<string, any>; | ||
reset_usage?:number; | ||
scopes?: string[]; | ||
defaults?: Record<string, any>; | ||
object?: string; | ||
} | ||
export interface ApiKeysUpdateParams { | ||
id?: string; | ||
name?: string; | ||
description?: string; | ||
rate_limits?: Record<string, any>[]; | ||
usage_limits?: Record<string, any>; | ||
scopes?: string[]; | ||
defaults?: Record<string, any>; | ||
} | ||
export interface ApiKeysListParams { | ||
page_size?: number; | ||
current_page?: number; | ||
workspace_id?: string; | ||
} | ||
export interface ApiKeysListResponse extends APIResponseType { | ||
total?: number; | ||
object?: string; | ||
data?: Record<string, any>[]; | ||
} | ||
export interface ApiKeysDeleteParams { | ||
id?: string; | ||
} | ||
export class ApiKeys extends ApiResource { | ||
create( | ||
_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; | ||
} | ||
|
||
retrieve( | ||
_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<any> { | ||
const body = _body; | ||
const id = body.id; | ||
if (params) { | ||
this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) } | ||
} | ||
const response = this.put<any>(`/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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters