From 3845c99295b678168ac93b91b9bf192108e70b65 Mon Sep 17 00:00:00 2001 From: Naman Anand Date: Wed, 3 Apr 2024 02:41:39 +0530 Subject: [PATCH] chore: Namananand/ins 3646 update documentation for the latest version (#70) Because - update documentation for the latest version This commit - update documentation for the latest version --- README.md | 22 ++++++------- src/connector/types.ts | 5 +-- src/mgmt/AuthClient.ts | 12 +++---- src/mgmt/mutation.ts | 9 ++--- src/mgmt/queries.ts | 23 +++++++++++-- src/mgmt/types.ts | 75 +++++++++++++++++++++++++++++++++++++++++- src/pipeline/types.ts | 2 +- src/types.ts | 59 ++++++++++++++++++++++++++++++--- 8 files changed, 176 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index dc48aa5..990ca0f 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/src/connector/types.ts b/src/connector/types.ts index 5e970f0..f4325e8 100644 --- a/src/connector/types.ts +++ b/src/connector/types.ts @@ -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" @@ -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; @@ -37,6 +37,7 @@ export type Connector = { create_time: string; update_time: string; visibility: ConnectorVisibility; + owner: Owner; }; export type ConnectorWithDefinition = Omit< diff --git a/src/mgmt/AuthClient.ts b/src/mgmt/AuthClient.ts index 4b5acf8..4154af8 100644 --- a/src/mgmt/AuthClient.ts +++ b/src/mgmt/AuthClient.ts @@ -9,7 +9,7 @@ import { import { checkUserIdExist, getApiTokenQuery, - getUserMeQuery, + getAuthenticatedUserQuery, getUserQuery, listApiTokensQuery, } from "./queries"; @@ -17,7 +17,7 @@ import { changePasswordMutation, createApiTokenMutation, deleteApiTokenMutation, - updateUserMutation, + updateAuthenticatedUserMutation, } from "./mutation"; import { authLoginAction, @@ -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 }) { @@ -84,8 +84,8 @@ class AuthClient { * MGMT Mutation * -----------------------------------------------------------------------*/ - async updateUserMutation({ payload }: { payload: Partial }) { - return updateUserMutation({ + async updateAuthenticatedUserMutation({ payload }: { payload: Partial }) { + return updateAuthenticatedUserMutation({ axiosInstance: this.axiosInstance, payload: payload, }); diff --git a/src/mgmt/mutation.ts b/src/mgmt/mutation.ts index 234189a..e8b2e3f 100644 --- a/src/mgmt/mutation.ts +++ b/src/mgmt/mutation.ts @@ -1,5 +1,6 @@ import { AxiosInstance } from "axios"; import { + AuthenticatedUser, ChangePasswordPayload, CreateApiTokenPayload, CreateApiTokenResponse, @@ -7,16 +8,16 @@ import { User, } from "./types"; -export async function updateUserMutation({ - axiosInstance, +export async function updateAuthenticatedUserMutation({ payload, + axiosInstance, }: { + payload: Partial; axiosInstance: AxiosInstance; - payload: Partial; }) { try { const { data } = await axiosInstance.patch( - "/users/me", + "/user", payload ); diff --git a/src/mgmt/queries.ts b/src/mgmt/queries.ts index cedfa07..885c331 100644 --- a/src/mgmt/queries.ts +++ b/src/mgmt/queries.ts @@ -3,6 +3,8 @@ import { ApiToken, CheckUserIdExistResponse, GetApiTokenResponse, + GetAuthenticatedResponse, + GetAuthenticatedUserSubscriptionsResponse, GetUserResponse, ListApiTokensResponse, ListUsersResponse, @@ -11,9 +13,9 @@ 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("/users/me"); + const { data } = await axiosInstance.get("/user"); return Promise.resolve(data.user); } catch (err) { @@ -21,6 +23,23 @@ export async function getUserMeQuery(axiosInstance: AxiosInstance) { } } +export async function getAuthenticatedUserSubscriptionsQuery({ + axiosInstance, +}: { + axiosInstance: AxiosInstance; +}) { + try { + const { data } = + await axiosInstance.get( + "/user/subscription" + ); + + return Promise.resolve(data.subscription); + } catch (err) { + return Promise.reject(err); + } +} + export async function getUserQuery({ userName, axiosInstance, diff --git a/src/mgmt/types.ts b/src/mgmt/types.ts index 7c781c5..66ddc7f 100644 --- a/src/mgmt/types.ts +++ b/src/mgmt/types.ts @@ -1,4 +1,5 @@ import { GeneralRecord } from "@instill-ai/toolkit"; +import { Nullable } from "../types"; export type User = { name: string; @@ -52,7 +53,7 @@ export type AuthLoginActionResponse = { }; export type UpdateUserResponse = { - user: User; + user: AuthenticatedUser; }; export type CreateApiTokenPayload = { @@ -69,6 +70,9 @@ export type ChangePasswordPayload = { new_password: string; }; +export type GetAuthenticatedResponse = { + user: AuthenticatedUser; +}; export type GetUserResponse = { user: User; }; @@ -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; +}; + +export type GetAuthenticatedUserSubscriptionsResponse = { + subscription: UserSubscription; +}; diff --git a/src/pipeline/types.ts b/src/pipeline/types.ts index 768993c..dc3fe1e 100644 --- a/src/pipeline/types.ts +++ b/src/pipeline/types.ts @@ -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< diff --git a/src/types.ts b/src/types.ts index 219e882..03c179e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -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; @@ -35,3 +32,57 @@ export type Visibility = | "VISIBILITY_PUBLIC"; export type Nullable = 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;