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

chore: Namananand/ins 3646 update documentation for the latest version #70

Merged
Show file tree
Hide file tree
Changes from all 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
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,17 +359,17 @@ client.AuthClient.createApiTokenMutation({

```

| function | params |
| :--------------------- | :---------------------: |
| getUserQuery | userName |
| getUserMeQuery | |
| checkUserIdExist | id |
| getApiTokenQuery | tokenName |
| listApiTokensQuery | pageSize, nextPageToken |
| updateUserMutation | payload |
| createApiTokenMutation | payload |
| deleteApiTokenMutation | tokenName |
| checkNamespace | id |
| function | params |
| :--------------------- | :---------------------: |
| getUserQuery | userName |
| getAuthenticatedUserQuery | |
| checkUserIdExist | id |
| getApiTokenQuery | tokenName |
| listApiTokensQuery | pageSize, nextPageToken |
| updateAuthenticatedUserMutation | payload |
| createApiTokenMutation | payload |
| deleteApiTokenMutation | tokenName |
| checkNamespace | id |

## Contribution Guidelines:

Expand Down
5 changes: 3 additions & 2 deletions src/connector/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

import { AirbyteFieldValues } from "@instill-ai/toolkit";
import { Spec } from "../types";
import { Owner, Spec } from "../types";

export type ConnectorState =
| "STATE_CONNECTED"
Expand All @@ -19,7 +19,7 @@ export type ConnectorType =
| "CONNECTOR_TYPE_OPERATOR"
| "CONNECTOR_TYPE_DATA"
| "CONNECTOR_TYPE_AI"
| "CONNECTOR_TYPE_BLOCKCHAIN";
| "CONNECTOR_TYPE_APPLICATION";

export type Connector = {
name: string;
Expand All @@ -37,6 +37,7 @@ export type Connector = {
create_time: string;
update_time: string;
visibility: ConnectorVisibility;
owner: Owner;
};

export type ConnectorWithDefinition = Omit<
Expand Down
12 changes: 6 additions & 6 deletions src/mgmt/AuthClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import {
import {
checkUserIdExist,
getApiTokenQuery,
getUserMeQuery,
getAuthenticatedUserQuery,
getUserQuery,
listApiTokensQuery,
} from "./queries";
import {
changePasswordMutation,
createApiTokenMutation,
deleteApiTokenMutation,
updateUserMutation,
updateAuthenticatedUserMutation,
} from "./mutation";
import {
authLoginAction,
Expand All @@ -44,8 +44,8 @@ class AuthClient {
* MGMT Queries
* -----------------------------------------------------------------------*/

async getUserMeQuery() {
return getUserMeQuery(this.axiosInstance);
async getAuthenticatedUserQuery() {
return getAuthenticatedUserQuery(this.axiosInstance);
}

async getUserQuery({ userName }: { userName: string }) {
Expand Down Expand Up @@ -84,8 +84,8 @@ class AuthClient {
* MGMT Mutation
* -----------------------------------------------------------------------*/

async updateUserMutation({ payload }: { payload: Partial<User> }) {
return updateUserMutation({
async updateAuthenticatedUserMutation({ payload }: { payload: Partial<User> }) {
return updateAuthenticatedUserMutation({
axiosInstance: this.axiosInstance,
payload: payload,
});
Expand Down
9 changes: 5 additions & 4 deletions src/mgmt/mutation.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import { AxiosInstance } from "axios";
import {
AuthenticatedUser,
ChangePasswordPayload,
CreateApiTokenPayload,
CreateApiTokenResponse,
UpdateUserResponse,
User,
} from "./types";

export async function updateUserMutation({
axiosInstance,
export async function updateAuthenticatedUserMutation({
payload,
axiosInstance,
}: {
payload: Partial<AuthenticatedUser>;
axiosInstance: AxiosInstance;
payload: Partial<User>;
}) {
try {
const { data } = await axiosInstance.patch<UpdateUserResponse>(
"/users/me",
"/user",
payload
);

Expand Down
23 changes: 21 additions & 2 deletions src/mgmt/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import {
ApiToken,
CheckUserIdExistResponse,
GetApiTokenResponse,
GetAuthenticatedResponse,
GetAuthenticatedUserSubscriptionsResponse,
GetUserResponse,
ListApiTokensResponse,
ListUsersResponse,
Expand All @@ -11,16 +13,33 @@ import {
import { getQueryString } from "../helper";
import { Nullable } from "../types";

export async function getUserMeQuery(axiosInstance: AxiosInstance) {
export async function getAuthenticatedUserQuery(axiosInstance: AxiosInstance) {
try {
const { data } = await axiosInstance.get<GetUserResponse>("/users/me");
const { data } = await axiosInstance.get<GetAuthenticatedResponse>("/user");

return Promise.resolve(data.user);
} catch (err) {
return Promise.reject(err);
}
}

export async function getAuthenticatedUserSubscriptionsQuery({
axiosInstance,
}: {
axiosInstance: AxiosInstance;
}) {
try {
const { data } =
await axiosInstance.get<GetAuthenticatedUserSubscriptionsResponse>(
"/user/subscription"
);

return Promise.resolve(data.subscription);
} catch (err) {
return Promise.reject(err);
}
}

export async function getUserQuery({
userName,
axiosInstance,
Expand Down
75 changes: 74 additions & 1 deletion src/mgmt/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { GeneralRecord } from "@instill-ai/toolkit";
import { Nullable } from "../types";

export type User = {
name: string;
Expand Down Expand Up @@ -52,7 +53,7 @@ export type AuthLoginActionResponse = {
};

export type UpdateUserResponse = {
user: User;
user: AuthenticatedUser;
};

export type CreateApiTokenPayload = {
Expand All @@ -69,6 +70,9 @@ export type ChangePasswordPayload = {
new_password: string;
};

export type GetAuthenticatedResponse = {
user: AuthenticatedUser;
};
export type GetUserResponse = {
user: User;
};
Expand Down Expand Up @@ -96,3 +100,72 @@ export type ListUsersResponse = {
export type CheckNamespaceResponse = {
type: NamespaceType;
};

export type UserProfile = {
display_name?: string;
bio?: string;
public_email?: string;
company_name?: string;
avatar?: string;
social_profiles_links?: {
webiste?: string;
x?: string;
github?: string;
};
};

export type OnboardingStatus =
| "ONBOARDING_STATUS_UNSPECIFIED"
| "ONBOARDING_STATUS_IN_PROGRESS"
| "ONBOARDING_STATUS_COMPLETED";

export type AuthenticatedUser = {
name: string;
uid: string;
id: string;
create_time: string;
update_time: string;
customer_id: string;
email: string;
newsletter_subscription: boolean;
role: string;
onboarding_status: OnboardingStatus;
cookie_token?: string;
profile?: UserProfile;
};

export type StripeSubscriptionStatus =
| "STATUS_UNSPECIFIED"
| "STATUS_INCOMPLETE"
| "STATUS_INCOMPLETE_EXPIRED"
| "STATUS_TRIALING"
| "STATUS_ACTIVE"
| "STATUS_PAST_DUE"
| "STATUS_CANCELED"
| "STATUS_UNPAID"
| "STATUS_PAUSED";

export type StripeSubscriptionDetail = {
product_name: string;
id: string;
item_id: string;
price: number;
canceled_at?: number;
trial_end?: number;
status: StripeSubscriptionStatus;
description: string;
};

export type UserSubscriptionPlan =
| "PLAN_UNSPECIFIED"
| "PLAN_FREEMIUM"
| "PLAN_PRO";

export type UserSubscription = {
plan: UserSubscriptionPlan;
detail: Nullable<StripeSubscriptionDetail>;
};

export type GetAuthenticatedUserSubscriptionsResponse = {
subscription: UserSubscription;
};
2 changes: 1 addition & 1 deletion src/pipeline/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export type PipelineComponentType =
| "COMPONENT_TYPE_UNSPECIFIED"
| "COMPONENT_TYPE_CONNECTOR_AI"
| "COMPONENT_TYPE_CONNECTOR_DATA"
| "COMPONENT_TYPE_CONNECTOR_BLOCKCHAIN"
| "COMPONENT_TYPE_CONNECTOR_APPLICATION"
| "COMPONENT_TYPE_OPERATOR";

export type PipelineReleasesWatchState = Record<
Expand Down
59 changes: 55 additions & 4 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ export type Violation = {
subject: string;
};

export type ResourceState =
| ModelState
| PipelineReleaseState
| ConnectorState;
export type ResourceState = ModelState | PipelineReleaseState | ConnectorState;

export type Spec = {
resource_specification: JSONSchema7;
Expand All @@ -35,3 +32,57 @@ export type Visibility =
| "VISIBILITY_PUBLIC";

export type Nullable<T> = T | null;

export type OrganizationProfile = {
display_name?: string;
bio?: string;
public_email?: string;
avatar?: string;
social_profiles_links?: {
webiste?: string;
x?: string;
github?: string;
};
};

export type Organization = {
name: string;
uid: string;
id: string;
create_time: string;
update_time: string;
owner: User;
profile?: OrganizationProfile;
};

export type UserProfile = {
display_name?: string;
bio?: string;
public_email?: string;
company_name?: string;
avatar?: string;
social_profiles_links?: {
webiste?: string;
x?: string;
github?: string;
};
};

export type User = {
name: string;
uid: string;
id: string;
create_time: string;
update_time: string;
profile?: UserProfile;
};

export type UserOwner = {
user: User;
};

export type OrganizationOwner = {
organization: Organization;
};

export type Owner = UserOwner | OrganizationOwner;
Loading