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

refactor(web): api definitions #1185

Merged
merged 1 commit into from
May 29, 2023
Merged
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
1 change: 1 addition & 0 deletions web/src/apis/typing.d.ts
Original file line number Diff line number Diff line change
@@ -38,6 +38,7 @@ export type TCurrentBundle = {
export type TBundle = {
_id: string;
regionId: string;
message?: string;
name: string;
displayName: string;
spec: TSpec;
10 changes: 4 additions & 6 deletions web/src/apis/v1/accounts.ts
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ import useGlobalStore from "@/pages/globalStore";
* Get account info
*/
export async function AccountControllerFindOne(
params: Paths.AccountControllerFindOne.BodyParameters | any,
params: Paths.AccountControllerFindOne.BodyParameters,
): Promise<{
error: string;
data: Definitions.Account;
@@ -34,7 +34,7 @@ export async function AccountControllerFindOne(
* Get charge order
*/
export async function AccountControllerGetChargeOrder(
params: Paths.AccountControllerGetChargeOrder.BodyParameters | any,
params: Paths.AccountControllerGetChargeOrder.BodyParameters,
): Promise<{
error: string;
data: Definitions.AccountChargeOrder;
@@ -53,9 +53,7 @@ export async function AccountControllerGetChargeOrder(
/**
* Create charge order
*/
export async function AccountControllerCharge(
params: Definitions.CreateChargeOrderDto | any,
): Promise<{
export async function AccountControllerCharge(params: Definitions.CreateChargeOrderDto): Promise<{
error: string;
data: Definitions.CreateChargeOrderOutDto;
}> {
@@ -74,7 +72,7 @@ export async function AccountControllerCharge(
*
*/
export async function AccountControllerWechatNotify(
params: Paths.AccountControllerWechatNotify.BodyParameters | any,
params: Paths.AccountControllerWechatNotify.BodyParameters,
): Promise<{
error: string;
data: Paths.AccountControllerWechatNotify.Responses;
35 changes: 34 additions & 1 deletion web/src/apis/v1/api-auto.d.ts
Original file line number Diff line number Diff line change
@@ -24,11 +24,11 @@ declare namespace Definitions {
memory?: number;
databaseCapacity?: number;
storageCapacity?: number;
isTrialTier?: boolean;
name?: string;
state?: string;
regionId?: string;
runtimeId?: string;
isTrialTier?: boolean;
};

export type ApplicationWithRelations = {
@@ -77,6 +77,7 @@ declare namespace Definitions {
memory?: number;
databaseCapacity?: number;
storageCapacity?: number;
isTrialTier?: boolean;
};

export type ApplicationBundle = {
@@ -123,15 +124,44 @@ declare namespace Definitions {
name?: string;
};

export type DatabasePolicyWithRules = {
_id?: string;
appid?: string;
name?: string;
injector?: string;
createdAt?: string;
updatedAt?: string;
rules?: Definitions.DatabasePolicyRule[];
};

export type UpdatePolicyDto = {
injector?: string;
};

export type DatabasePolicy = {
_id?: string;
appid?: string;
name?: string;
injector?: string;
createdAt?: string;
updatedAt?: string;
};

export type CreatePolicyRuleDto = {
collectionName?: string;
value?: string;
};

export type DatabasePolicyRule = {
_id?: string;
appid?: string;
policyName?: string;
collectionName?: string;
value?: {};
createdAt?: string;
updatedAt?: string;
};

export type UpdatePolicyRuleDto = {
value?: string;
};
@@ -199,6 +229,7 @@ declare namespace Definitions {
phone?: string /* phone */;
code?: string /* verify code */;
type?: string /* type */;
inviteCode?: string /* invite code */;
};

export type PasswdSigninDto = {
@@ -227,6 +258,7 @@ declare namespace Definitions {
code?: string;
username?: string /* username */;
password?: string /* password, 8-64 characters */;
inviteCode?: string /* invite code */;
};

export type BindPhoneDto = {
@@ -273,6 +305,7 @@ declare namespace Definitions {
memory?: number;
databaseCapacity?: number;
storageCapacity?: number;
isTrialTier?: boolean;
};

export type CalculatePriceResultDto = {
14 changes: 7 additions & 7 deletions web/src/apis/v1/applications.ts
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ import useGlobalStore from "@/pages/globalStore";
* Create application
*/
export async function ApplicationControllerCreate(
params: Definitions.CreateApplicationDto | any,
params: Definitions.CreateApplicationDto,
): Promise<{
error: string;
data: Definitions.ApplicationWithRelations;
@@ -34,7 +34,7 @@ export async function ApplicationControllerCreate(
* Get user application list
*/
export async function ApplicationControllerFindAll(
params: Paths.ApplicationControllerFindAll.BodyParameters | any,
params: Paths.ApplicationControllerFindAll.BodyParameters,
): Promise<{
error: string;
data: Paths.ApplicationControllerFindAll.Responses;
@@ -54,7 +54,7 @@ export async function ApplicationControllerFindAll(
* Get an application by appid
*/
export async function ApplicationControllerFindOne(
params: Paths.ApplicationControllerFindOne.BodyParameters | any,
params: Paths.ApplicationControllerFindOne.BodyParameters,
): Promise<{
error: string;
data: Paths.ApplicationControllerFindOne.Responses;
@@ -74,7 +74,7 @@ export async function ApplicationControllerFindOne(
* Delete an application
*/
export async function ApplicationControllerDelete(
params: Paths.ApplicationControllerDelete.BodyParameters | any,
params: Paths.ApplicationControllerDelete.BodyParameters,
): Promise<{
error: string;
data: Definitions.Application;
@@ -94,7 +94,7 @@ export async function ApplicationControllerDelete(
* Update application name
*/
export async function ApplicationControllerUpdateName(
params: Definitions.UpdateApplicationNameDto | any,
params: Definitions.UpdateApplicationNameDto,
): Promise<{
error: string;
data: Definitions.Application;
@@ -114,7 +114,7 @@ export async function ApplicationControllerUpdateName(
* Update application state
*/
export async function ApplicationControllerUpdateState(
params: Definitions.UpdateApplicationStateDto | any,
params: Definitions.UpdateApplicationStateDto,
): Promise<{
error: string;
data: Definitions.Application;
@@ -134,7 +134,7 @@ export async function ApplicationControllerUpdateState(
* Update application bundle
*/
export async function ApplicationControllerUpdateBundle(
params: Definitions.UpdateApplicationBundleDto | any,
params: Definitions.UpdateApplicationBundleDto,
): Promise<{
error: string;
data: Definitions.ApplicationBundle;
116 changes: 50 additions & 66 deletions web/src/apis/v1/apps.ts

Large diffs are not rendered by default.

28 changes: 9 additions & 19 deletions web/src/apis/v1/auth.ts
Original file line number Diff line number Diff line change
@@ -13,9 +13,7 @@ import useGlobalStore from "@/pages/globalStore";
/**
* Signup by user-password
*/
export async function UserPasswordControllerSignup(
params: Definitions.PasswdSignupDto | any,
): Promise<{
export async function UserPasswordControllerSignup(params: Definitions.PasswdSignupDto): Promise<{
error: string;
data: Paths.UserPasswordControllerSignup.Responses;
}> {
@@ -33,9 +31,7 @@ export async function UserPasswordControllerSignup(
/**
* Signin by user-password
*/
export async function UserPasswordControllerSignin(
params: Definitions.PasswdSigninDto | any,
): Promise<{
export async function UserPasswordControllerSignin(params: Definitions.PasswdSigninDto): Promise<{
error: string;
data: Paths.UserPasswordControllerSignin.Responses;
}> {
@@ -53,9 +49,7 @@ export async function UserPasswordControllerSignin(
/**
* Reset password
*/
export async function UserPasswordControllerReset(
params: Definitions.PasswdResetDto | any,
): Promise<{
export async function UserPasswordControllerReset(params: Definitions.PasswdResetDto): Promise<{
error: string;
data: Paths.UserPasswordControllerReset.Responses;
}> {
@@ -73,9 +67,7 @@ export async function UserPasswordControllerReset(
/**
* Check if user-password is set
*/
export async function UserPasswordControllerCheck(
params: Definitions.PasswdCheckDto | any,
): Promise<{
export async function UserPasswordControllerCheck(params: Definitions.PasswdCheckDto): Promise<{
error: string;
data: Paths.UserPasswordControllerCheck.Responses;
}> {
@@ -93,7 +85,7 @@ export async function UserPasswordControllerCheck(
/**
* Send phone verify code
*/
export async function PhoneControllerSendCode(params: Definitions.SendPhoneCodeDto | any): Promise<{
export async function PhoneControllerSendCode(params: Definitions.SendPhoneCodeDto): Promise<{
error: string;
data: Paths.PhoneControllerSendCode.Responses;
}> {
@@ -111,7 +103,7 @@ export async function PhoneControllerSendCode(params: Definitions.SendPhoneCodeD
/**
* Signin by phone and verify code
*/
export async function PhoneControllerSignin(params: Definitions.PhoneSigninDto | any): Promise<{
export async function PhoneControllerSignin(params: Definitions.PhoneSigninDto): Promise<{
error: string;
data: Paths.PhoneControllerSignin.Responses;
}> {
@@ -130,7 +122,7 @@ export async function PhoneControllerSignin(params: Definitions.PhoneSigninDto |
* Auth providers
*/
export async function AuthenticationControllerGetProviders(
params: Paths.AuthenticationControllerGetProviders.BodyParameters | any,
params: Paths.AuthenticationControllerGetProviders.BodyParameters,
): Promise<{
error: string;
data: Paths.AuthenticationControllerGetProviders.Responses;
@@ -149,9 +141,7 @@ export async function AuthenticationControllerGetProviders(
/**
* Bind username
*/
export async function AuthenticationControllerBindPhone(
params: Definitions.BindPhoneDto | any,
): Promise<{
export async function AuthenticationControllerBindPhone(params: Definitions.BindPhoneDto): Promise<{
error: string;
data: Paths.AuthenticationControllerBindPhone.Responses;
}> {
@@ -170,7 +160,7 @@ export async function AuthenticationControllerBindPhone(
* Bind username
*/
export async function AuthenticationControllerBindUsername(
params: Definitions.BindUsernameDto | any,
params: Definitions.BindUsernameDto,
): Promise<{
error: string;
data: Paths.AuthenticationControllerBindUsername.Responses;
2 changes: 1 addition & 1 deletion web/src/apis/v1/pat2token.ts
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ import useGlobalStore from "@/pages/globalStore";
/**
* Get user token by PAT
*/
export async function AuthControllerPat2token(params: Definitions.Pat2TokenDto | any): Promise<{
export async function AuthControllerPat2token(params: Definitions.Pat2TokenDto): Promise<{
error: string;
data: Paths.AuthControllerPat2token.Responses;
}> {
6 changes: 3 additions & 3 deletions web/src/apis/v1/pats.ts
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ import useGlobalStore from "@/pages/globalStore";
/**
* Create a PAT
*/
export async function PatControllerCreate(params: Definitions.CreatePATDto | any): Promise<{
export async function PatControllerCreate(params: Definitions.CreatePATDto): Promise<{
error: string;
data: Paths.PatControllerCreate.Responses;
}> {
@@ -32,7 +32,7 @@ export async function PatControllerCreate(params: Definitions.CreatePATDto | any
* List PATs
*/
export async function PatControllerFindAll(
params: Paths.PatControllerFindAll.BodyParameters | any,
params: Paths.PatControllerFindAll.BodyParameters,
): Promise<{
error: string;
data: Paths.PatControllerFindAll.Responses;
@@ -52,7 +52,7 @@ export async function PatControllerFindAll(
* Delete a PAT
*/
export async function PatControllerRemove(
params: Paths.PatControllerRemove.BodyParameters | any,
params: Paths.PatControllerRemove.BodyParameters,
): Promise<{
error: string;
data: Paths.PatControllerRemove.Responses;
2 changes: 1 addition & 1 deletion web/src/apis/v1/profile.ts
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ import useGlobalStore from "@/pages/globalStore";
* Get current user profile
*/
export async function AuthControllerGetProfile(
params: Paths.AuthControllerGetProfile.BodyParameters | any,
params: Paths.AuthControllerGetProfile.BodyParameters,
): Promise<{
error: string;
data: Definitions.UserWithProfile;
2 changes: 1 addition & 1 deletion web/src/apis/v1/regions.ts
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ import useGlobalStore from "@/pages/globalStore";
* Get region list
*/
export async function RegionControllerGetRegions(
params: Paths.RegionControllerGetRegions.BodyParameters | any,
params: Paths.RegionControllerGetRegions.BodyParameters,
): Promise<{
error: string;
data: Paths.RegionControllerGetRegions.Responses;
8 changes: 4 additions & 4 deletions web/src/apis/v1/resources.ts
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ import useGlobalStore from "@/pages/globalStore";
* Calculate pricing
*/
export async function ResourceControllerCalculatePrice(
params: Definitions.CalculatePriceDto | any,
params: Definitions.CalculatePriceDto,
): Promise<{
error: string;
data: Definitions.CalculatePriceResultDto;
@@ -34,7 +34,7 @@ export async function ResourceControllerCalculatePrice(
* Get resource option list
*/
export async function ResourceControllerGetResourceOptions(
params: Paths.ResourceControllerGetResourceOptions.BodyParameters | any,
params: Paths.ResourceControllerGetResourceOptions.BodyParameters,
): Promise<{
error: string;
data: Paths.ResourceControllerGetResourceOptions.Responses;
@@ -54,7 +54,7 @@ export async function ResourceControllerGetResourceOptions(
* Get resource option list by region id
*/
export async function ResourceControllerGetResourceOptionsByRegionId(
params: Paths.ResourceControllerGetResourceOptionsByRegionId.BodyParameters | any,
params: Paths.ResourceControllerGetResourceOptionsByRegionId.BodyParameters,
): Promise<{
error: string;
data: Paths.ResourceControllerGetResourceOptionsByRegionId.Responses;
@@ -74,7 +74,7 @@ export async function ResourceControllerGetResourceOptionsByRegionId(
* Get resource template list
*/
export async function ResourceControllerGetResourceBundles(
params: Paths.ResourceControllerGetResourceBundles.BodyParameters | any,
params: Paths.ResourceControllerGetResourceBundles.BodyParameters,
): Promise<{
error: string;
data: Paths.ResourceControllerGetResourceBundles.Responses;
2 changes: 1 addition & 1 deletion web/src/apis/v1/runtimes.ts
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ import useGlobalStore from "@/pages/globalStore";
* Get application runtime list
*/
export async function AppControllerGetRuntimes(
params: Paths.AppControllerGetRuntimes.BodyParameters | any,
params: Paths.AppControllerGetRuntimes.BodyParameters,
): Promise<{
error: string;
data: Paths.AppControllerGetRuntimes.Responses;
4 changes: 2 additions & 2 deletions web/src/apis/v1/settings.ts
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ import useGlobalStore from "@/pages/globalStore";
* Get site settings
*/
export async function SettingControllerGetSettings(
params: Paths.SettingControllerGetSettings.BodyParameters | any,
params: Paths.SettingControllerGetSettings.BodyParameters,
): Promise<{
error: string;
data: Paths.SettingControllerGetSettings.Responses;
@@ -34,7 +34,7 @@ export async function SettingControllerGetSettings(
* Get one site setting by key
*/
export async function SettingControllerGetSettingByKey(
params: Paths.SettingControllerGetSettingByKey.BodyParameters | any,
params: Paths.SettingControllerGetSettingByKey.BodyParameters,
): Promise<{
error: string;
data: Paths.SettingControllerGetSettingByKey.Responses;
4 changes: 2 additions & 2 deletions web/src/pages/app/database/service.ts
Original file line number Diff line number Diff line change
@@ -201,7 +201,7 @@ export const useCreatePolicyMutation = () => {
const queryClient = useQueryClient();
const store = useDBMStore();
return useMutation(
(values: any) => {
(values: Definitions.CreatePolicyDto) => {
return PolicyControllerCreate(values);
},
{
@@ -240,7 +240,7 @@ export const useDeletePolicyMutation = () => {
const queryClient = useQueryClient();
const store = useDBMStore();
return useMutation(
(values: any) => {
(values) => {
return PolicyControllerRemove({ name: values });
},
{
15 changes: 9 additions & 6 deletions web/src/pages/app/setting/AppEnvList/service.ts
Original file line number Diff line number Diff line change
@@ -33,13 +33,16 @@ export const useEnvironmentQuery = (callback?: (data: any) => void) => {

export const useAddEnvironmentMutation = (callback?: () => void) => {
const queryClient = useQueryClient();
return useMutation((params: TEnvironment[]) => EnvironmentVariableControllerAdd(params), {
onSuccess: async () => {
useGlobalStore.getState().showSuccess("update environment success");
await queryClient.invalidateQueries(queryKeys.useEnvironmentQuery);
callback && callback();
return useMutation(
(params: Definitions.CreateEnvironmentDto) => EnvironmentVariableControllerAdd(params),
{
onSuccess: async () => {
useGlobalStore.getState().showSuccess("update environment success");
await queryClient.invalidateQueries(queryKeys.useEnvironmentQuery);
callback && callback();
},
},
});
);
};

export const useDelEnvironmentMutation = (callback?: () => void) => {
1 change: 0 additions & 1 deletion web/src/pages/globalStore.ts
Original file line number Diff line number Diff line change
@@ -80,7 +80,6 @@ const useGlobalStore = create<State>()(
return;
}
const restartRes = await ApplicationControllerUpdateState({
appid: app.appid,
state: newState,
});
if (!restartRes.error) {
47 changes: 8 additions & 39 deletions web/src/pages/home/mods/CreateAppModal/index.tsx
Original file line number Diff line number Diff line change
@@ -380,44 +380,6 @@ const CreateAppModal = (props: {
{spec.label}
</Button>
))}
{/* {item.specs.length > 0 ? (
<Slider
min={0}
max={item.specs.length - 1}
step={1}
onChange={(v) => {
setBundle({
...bundle,
[item.type]: item.specs[v].value,
});
}}
value={item.specs.findIndex(
(spec: any) => spec.value === bundle[item.type],
)}
>
{item.specs.map((spec: any, i: number) => (
<SliderMark
key={spec.value}
value={i}
mt={3}
fontSize={"sm"}
>
<Box
className="-ml-[50px] w-[100px] scale-90 text-center"
cursor={"pointer "}
>
{spec.label}
</Box>
</SliderMark>
))}
<SliderTrack>
<SliderFilledTrack bg="primary.500" />
</SliderTrack>
<SliderThumb bg={"primary.700"} />
</Slider>
) : (
<span className="text-2xl font-semibold">{item.price}</span>
)} */}
</div>
) : null;
},
@@ -433,6 +395,13 @@ const CreateAppModal = (props: {
</div>
<FormErrorMessage>{errors?.bundleId?.message}</FormErrorMessage>
</FormControl>
{activeBundle?.message && (
<div
dangerouslySetInnerHTML={{
__html: activeBundle?.message,
}}
></div>
)}

{/* <FormControl isInvalid={!!errors?.runtimeId}>
<FormLabel htmlFor="runtimeId">{t("HomePanel.RuntimeName")}</FormLabel>
@@ -454,7 +423,7 @@ const CreateAppModal = (props: {
</ModalBody>

<ModalFooter h={20}>
{type === "edit" ? null : totalPrice <= 0 ? (
{type === "edit" ? null : totalPrice <= 0 && isLoading ? (
<div className="mr-2">
<span className="ml-6 text-xl font-semibold text-red-500">{t("Price.Free")}</span>
</div>