Skip to content

Commit

Permalink
fix: Interfaces restructured and methods renamed from retrieve->get, …
Browse files Browse the repository at this point in the history
…retrieveAll->list
  • Loading branch information
shivam-pareek committed Oct 5, 2024
1 parent c5cbf2e commit db23710
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 76 deletions.
4 changes: 2 additions & 2 deletions src/apiResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ export class ApiResource {
protected client: Portkey;
protected post: Portkey["_post"]
protected put: Portkey["_put"]
protected get: Portkey["_get"]
protected getMethod: Portkey["_get"]
protected deleteMethod: Portkey["_delete"]

constructor(client: Portkey) {
this.client = client
this.post = client._post.bind(client)
this.put = client._put.bind(client)
this.get = client._get.bind(client)
this.getMethod = client._get.bind(client)
this.deleteMethod = client._delete.bind(client) // delete is a reserved word
}
}
159 changes: 85 additions & 74 deletions src/apis/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,11 @@ import { APIResponseType, ApiClientInterface } from "../_types/generalTypes";
import { APIPromise, RequestOptions } from "../baseClient";
import { createHeaders } from "./createHeaders";

export interface UsersRetrieveParams{
export interface UsersGetParams{
userId?: string;
}

export interface UsersRetrieveAllParams{
pageSize?: number;
currentPage?: number;
email?: string;
role?: "admin" | "member" | "owner" | any;
}

export interface UsersRetrieveResponse extends APIResponseType {
export interface UsersGetResponse extends APIResponseType {
object?: string,
id?: string,
first_name?: string,
Expand All @@ -26,10 +19,17 @@ export interface UsersRetrieveResponse extends APIResponseType {
workspace_ids?: string[]
}

export interface UsersRetrieveAllResponse extends APIResponseType {
export interface UsersListParams{
pageSize?: number;
currentPage?: number;
email?: string;
role?: "admin" | "member" | "owner" | any;
}

export interface UsersListResponse extends APIResponseType {
total?: number,
object?: string,
data?: UsersRetrieveResponse[]
data?: UsersGetResponse[]
}

export interface UsersUpdateParams{
Expand All @@ -49,11 +49,11 @@ export interface UserInviteResponse extends APIResponseType {
invite_link?: string,
}

export interface UserInviteRetrieveParams{
export interface UserInviteGetParams{
inviteId?: string,
}

export interface UserInviteRetrieveResponse extends APIResponseType {
export interface UserInviteGetResponse extends APIResponseType {
object?: string,
id?: string,
email?: string,
Expand All @@ -65,18 +65,18 @@ export interface UserInviteRetrieveResponse extends APIResponseType {
invited_by?: string
}

export interface UserInviteRetrieveAllParams{
export interface UserInviteListParams{
email?: string,
role?: "admin" | "member" | any,
status?: "pending" | "accepted" | "expired"| "cancelled"| any,
pageSize?: number,
currentPage?: number
}

export interface UserInviteRetrieveAllResponse extends APIResponseType {
export interface UserInviteListResponse extends APIResponseType {
object?: string,
total?: number,
data?: UserInviteRetrieveResponse[]
data?: UserInviteGetResponse[]
}

export interface UserInviteRemoveParams {
Expand All @@ -89,13 +89,6 @@ export interface WorkspacesCreateParams{
defaults?: Record<string, any>,
users?: string[],
}
export interface WorkspacesRetrieveParams {
workspaceId?: string;
}
export interface WorkspacesRetrieveAllParams {
page_size?: number;
current_page?: number;
}

export interface WorkspacesCreateResponse extends APIResponseType {
id?: string,
Expand All @@ -108,7 +101,12 @@ export interface WorkspacesCreateResponse extends APIResponseType {
users?: Record<string, string>[],
object?: string,
}
export interface WorkspacesRetrieveResponse extends APIResponseType {

export interface WorkspacesGetParams {
workspaceId?: string;
}

export interface WorkspacesGetResponse extends APIResponseType {
id?: string,
slug?: string,
name?: string,
Expand All @@ -118,11 +116,18 @@ export interface WorkspacesRetrieveResponse extends APIResponseType {
defaults?: Record<string, any> | null,
users?: Record<string, any>[],
}
export interface WorkspacesRetrieveAllResponse extends APIResponseType {

export interface WorkspacesListParams {
page_size?: number;
current_page?: number;
}

export interface WorkspacesListResponse extends APIResponseType {
total?: number,
object?: string,
data?: WorkspacesRetrieveResponse[]
data?: WorkspacesGetResponse[]
}

export interface WorkspacesUpdateParams{
workspaceId?: string,
name?: string,
Expand All @@ -145,24 +150,19 @@ export interface WorkspacesUpdateResponse extends APIResponseType {
export interface WorkspacesRemoveParams{
workspaceId?: string;
name?: string;

}

export interface WorkspaceMemberAddParams{
workspaceId?: string,
users?: { id: string, role: "member" | "admin" }[],
}
export interface WorkspaceMemberRetrieveParams{

export interface WorkspaceMemberGetParams{
workspaceId?: string,
userId?: string,
}
export interface WorkspaceMemberRetrieveAllParams {
workspaceId?: string,
page_size?: number,
current_page?: number,
email?: string,
role?: "admin" | "manager" | "member" | any,
}
export interface WorkspaceMemberRetrieveResponse extends APIResponseType {

export interface WorkspaceMemberGetResponse extends APIResponseType {
first_name?: string,
last_name?: string,
org_role?: string,
Expand All @@ -175,22 +175,33 @@ export interface WorkspaceMemberRetrieveResponse extends APIResponseType {
settings?: Record<string, any>| null,
object?: string,
}
export interface WorkspaceMemberRetrieveAllResponse extends APIResponseType {

export interface WorkspaceMemberListParams {
workspaceId?: string,
page_size?: number,
current_page?: number,
email?: string,
role?: "admin" | "manager" | "member" | any,
}

export interface WorkspaceMemberListResponse extends APIResponseType {
total?: number,
object?: string,
data?: WorkspaceMemberRetrieveResponse[]
data?: WorkspaceMemberGetResponse[]
}

export interface WorkspaceMemberRemoveParams{
workspaceId?: string,
userId?: string,
}

export interface WorkspaceMemberUpdateParams{
workspaceId?: string,
userId?: string,
role?: "admin" | "member" | any,
}
// Function to convert UsersRetrieveParams to query parameters
function toQueryParams(params?: (UsersRetrieveAllParams | UserInviteRetrieveAllParams | WorkspacesRetrieveParams | WorkspacesRetrieveAllParams | WorkspaceMemberRetrieveAllParams)): string {
// Function to convert UsersGetParams to query parameters
function toQueryParams(params?: (UsersListParams | UserInviteListParams | WorkspacesListParams | WorkspaceMemberListParams)): string {
if (!params) {
return '';
}
Expand Down Expand Up @@ -222,32 +233,32 @@ export class Users extends ApiResource {
this.invites = new Invites(client);
}

retrieve(
_body: UsersRetrieveParams,
get(
_body: UsersGetParams,
params?: ApiClientInterface,
opts?: RequestOptions
): APIPromise<UsersRetrieveResponse> {
): APIPromise<UsersGetResponse> {
const body = _body;
const userId = body.userId;

if (params) {
this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) }
}
const response = this.get<UsersRetrieveResponse>(`/admin/users/${userId}`, {...opts });
const response = this.getMethod<UsersGetResponse>(`/admin/users/${userId}`, {...opts });
return response;
}

retrieveAll(
_body: UsersRetrieveAllParams,
list(
_body: UsersListParams,
params?: ApiClientInterface,
opts?: RequestOptions
): APIPromise<UsersRetrieveAllResponse> {
): APIPromise<UsersListResponse> {
const body = _body;
if (params) {
this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) }
}
const query = toQueryParams(body);
const response = this.get<UsersRetrieveAllResponse>(`/admin/users${query}`, { ...opts });
const response = this.getMethod<UsersListResponse>(`/admin/users${query}`, { ...opts });
return response;
}

Expand All @@ -267,7 +278,7 @@ export class Users extends ApiResource {
}

remove(
_body: UsersRetrieveParams,
_body: UsersGetParams,
params?: ApiClientInterface,
opts?: RequestOptions
): APIPromise<any> {
Expand Down Expand Up @@ -299,30 +310,30 @@ export class Invites extends ApiResource {
return response;
}

retrieve(
_body: UserInviteRetrieveParams,
get(
_body: UserInviteGetParams,
params?: ApiClientInterface,
opts?: RequestOptions
): APIPromise<UserInviteRetrieveResponse> {
): APIPromise<UserInviteGetResponse> {
const inviteId = _body.inviteId;
if (params) {
this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) }
}
const response = this.get<UserInviteRetrieveResponse>(`/admin/users/invites/${inviteId}`, { ...opts });
const response = this.getMethod<UserInviteGetResponse>(`/admin/users/invites/${inviteId}`, { ...opts });
return response;
}

retrieveAll(
_body?: UserInviteRetrieveAllParams,
list(
_body?: UserInviteListParams,
params?: ApiClientInterface,
opts?: RequestOptions
): APIPromise<UserInviteRetrieveAllResponse> {
): APIPromise<UserInviteListResponse> {
const body = _body;
if (params) {
this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) }
}
const query = body ? toQueryParams(body) : '';
const response = this.get<UserInviteRetrieveAllResponse>(`/admin/users/invites${query}`, { ...opts });
const response = this.getMethod<UserInviteListResponse>(`/admin/users/invites${query}`, { ...opts });
return response;
}

Expand Down Expand Up @@ -360,32 +371,32 @@ export class Workspaces extends ApiResource {
const response = this.post<WorkspacesCreateResponse>('/admin/workspaces', { body, ...opts });
return response;
}
retrieve(
_body: WorkspacesRetrieveParams,
get(
_body: WorkspacesGetParams,
params?: ApiClientInterface,
opts?: RequestOptions
): APIPromise<WorkspacesRetrieveResponse> {
): APIPromise<WorkspacesGetResponse> {
const body = _body;
const workspaceId = body.workspaceId;

if (params) {
this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) }
}
const response = this.get<WorkspacesRetrieveResponse>(`/admin/workspaces/${workspaceId}`, { ...opts });
const response = this.getMethod<WorkspacesGetResponse>(`/admin/workspaces/${workspaceId}`, { ...opts });
return response;
}

retrieveAll(
_body: WorkspacesRetrieveAllParams,
list(
_body: WorkspacesListParams,
params?: ApiClientInterface,
opts?: RequestOptions
): APIPromise<WorkspacesRetrieveAllResponse> {
): APIPromise<WorkspacesListResponse> {
const body = _body;
if (params) {
this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) }
}
const query = toQueryParams(body);
const response = this.get<WorkspacesRetrieveAllResponse>(`/admin/workspaces${query}`, { ...opts });
const response = this.getMethod<WorkspacesListResponse>(`/admin/workspaces${query}`, { ...opts });
return response;
}

Expand Down Expand Up @@ -435,32 +446,32 @@ export class Member extends ApiResource {
return response;
}

retrieve(
_body: WorkspaceMemberRetrieveParams,
get(
_body: WorkspaceMemberGetParams,
params?: ApiClientInterface,
opts?: RequestOptions
): APIPromise<WorkspaceMemberRetrieveResponse> {
): APIPromise<WorkspaceMemberGetResponse> {
const workspaceId = _body.workspaceId;
const userId = _body.userId;
if (params) {
this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) }
}
const response = this.get<WorkspaceMemberRetrieveResponse>(`/admin/workspaces/${workspaceId}/users/${userId}`, { ...opts });
const response = this.getMethod<WorkspaceMemberGetResponse>(`/admin/workspaces/${workspaceId}/users/${userId}`, { ...opts });
return response;
}

retrieveAll(
_body: WorkspaceMemberRetrieveAllParams,
list(
_body: WorkspaceMemberListParams,
params?: ApiClientInterface,
opts?: RequestOptions
): APIPromise<WorkspaceMemberRetrieveAllResponse> {
): APIPromise<WorkspaceMemberListResponse> {
const body = _body;
const workspaceId = _body.workspaceId;
if (params) {
this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) }
}
const query = toQueryParams(body);
const response = this.get<WorkspaceMemberRetrieveAllResponse>(`/admin/workspaces/${workspaceId}/users${query}`, { ...opts });
const response = this.getMethod<WorkspaceMemberListResponse>(`/admin/workspaces/${workspaceId}/users${query}`, { ...opts });
return response;
}

Expand Down Expand Up @@ -493,4 +504,4 @@ export class Member extends ApiResource {
const response = this.put<any>(`/admin/workspaces/${workspaceId}/users/${userId}`, { body, ...opts });
return response;
}
}
}

0 comments on commit db23710

Please sign in to comment.