-
Notifications
You must be signed in to change notification settings - Fork 8
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
Feat/api keys #122
Changes from 7 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
ee663fb
initial commit
shivam-pareek 3b77d72
merge: userInvite
shivam-pareek a80a0c8
feat: add api-keys endpoint
shivam-pareek a5abb53
fix: get methods of api-keys have been fixed
shivam-pareek 3ec613e
merge: userInvite
shivam-pareek 5ad3ccf
fix: method names have been changed to get, add
shivam-pareek eb94985
fix: re-arranged the interfaces of ApiKeys
shivam-pareek f6a40f7
merge: userInvite
shivam-pareek 210fbd7
fix: "unknown" type changed to "any"
shivam-pareek 14519ec
merge: userInvite
shivam-pareek f39fe09
fix: utils.ts updated with toQueryParams
shivam-pareek 1d8b3fc
merge: userInvite
shivam-pareek 6057d30
fix: import statement fixed
shivam-pareek bd7912f
merge: userInvite
shivam-pareek d04c469
fix: ApiKeyUpdateResponse Interface has been removed
shivam-pareek 63fa01b
merge feat/userInvite
shivam-pareek d7f215c
fix: redundant constructor has been removed
shivam-pareek fd0fe40
Merge branch 'feat/userInvite' into feat/apiKeys
csgulati09 bd058f9
feat: rename signature
csgulati09 1d5452d
Merge branch 'main' into feat/apiKeys
csgulati09 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,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>; | ||
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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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