mirror of
https://github.com/makeplane/plane.git
synced 2025-12-16 11:57:56 +01:00
feat: implementing zod schema in services pacakges
This commit is contained in:
@@ -1,15 +1,18 @@
|
||||
# Module imports
|
||||
from plane.license.models import Instance
|
||||
from plane.app.serializers import BaseSerializer
|
||||
from plane.app.serializers import UserAdminLiteSerializer
|
||||
|
||||
|
||||
class InstanceSerializer(BaseSerializer):
|
||||
primary_owner_details = UserAdminLiteSerializer(
|
||||
source="primary_owner", read_only=True
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = Instance
|
||||
fields = "__all__"
|
||||
read_only_fields = ["id", "email", "last_checked_at", "is_setup_done"]
|
||||
exclude = [
|
||||
"created_by",
|
||||
"deleted_at",
|
||||
"created_at",
|
||||
"last_checked_at",
|
||||
"updated_at",
|
||||
"updated_by",
|
||||
]
|
||||
|
||||
1
packages/services/src/ai/extended.ts
Normal file
1
packages/services/src/ai/extended.ts
Normal file
@@ -0,0 +1 @@
|
||||
export {};
|
||||
@@ -1 +1,2 @@
|
||||
export * from "./ai.service";
|
||||
export * from "./core";
|
||||
export * from "./extended";
|
||||
|
||||
1
packages/services/src/auth/admin.ts
Normal file
1
packages/services/src/auth/admin.ts
Normal file
@@ -0,0 +1 @@
|
||||
export {};
|
||||
@@ -1,2 +1,3 @@
|
||||
export * from "./auth.service";
|
||||
export * from "./sites-auth.service";
|
||||
export * from "./admin";
|
||||
export * from "./sites";
|
||||
export * from "./web";
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { API_BASE_URL } from "@plane/constants";
|
||||
// types
|
||||
import { IEmailCheckData, IEmailCheckResponse } from "@plane/types";
|
||||
// services
|
||||
import { APIService } from "../api.service";
|
||||
// types
|
||||
import { EmailCheckResponseSchema, TEmailCheckResponse, TEmailCheckData } from "./types";
|
||||
|
||||
/**
|
||||
* Service class for handling authentication-related operations for Plane space application
|
||||
@@ -11,10 +11,6 @@ import { APIService } from "../api.service";
|
||||
* @remarks This service is only available for plane sites
|
||||
*/
|
||||
export class SitesAuthService extends APIService {
|
||||
/**
|
||||
* Creates an instance of SitesAuthService
|
||||
* Initializes with the base API URL
|
||||
*/
|
||||
constructor(BASE_URL?: string) {
|
||||
super(BASE_URL || API_BASE_URL);
|
||||
}
|
||||
@@ -25,9 +21,9 @@ export class SitesAuthService extends APIService {
|
||||
* @returns {Promise<IEmailCheckResponse>} Response indicating email status
|
||||
* @throws {Error} Throws response data if the request fails
|
||||
*/
|
||||
async emailCheck(data: IEmailCheckData): Promise<IEmailCheckResponse> {
|
||||
async emailCheck(data: TEmailCheckData): Promise<TEmailCheckResponse> {
|
||||
return this.post("/auth/spaces/email-check/", data, { headers: {} })
|
||||
.then((response) => response?.data)
|
||||
.then((response) => EmailCheckResponseSchema.parse(response?.data))
|
||||
.catch((error) => {
|
||||
throw error?.response?.data;
|
||||
});
|
||||
14
packages/services/src/auth/types.ts
Normal file
14
packages/services/src/auth/types.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import * as z from "zod";
|
||||
|
||||
export const EmailCheckResponseSchema = z.object({
|
||||
email: z.string().email(),
|
||||
status: z.enum(["MAGIC_CODE", "CREDENTIAL"]),
|
||||
existing: z.boolean(),
|
||||
is_password_autoset: z.boolean(),
|
||||
});
|
||||
|
||||
export type TEmailCheckResponse = z.infer<typeof EmailCheckResponseSchema>;
|
||||
|
||||
export type TEmailCheckData = {
|
||||
email: string;
|
||||
};
|
||||
@@ -6,7 +6,6 @@ import type {
|
||||
IInstanceAdmin,
|
||||
IInstanceConfiguration,
|
||||
IInstanceInfo,
|
||||
TPage,
|
||||
} from "@plane/types";
|
||||
// api service
|
||||
import { APIService } from "../api.service";
|
||||
@@ -17,10 +16,6 @@ import { APIService } from "../api.service";
|
||||
* @extends {APIService}
|
||||
*/
|
||||
export class InstanceService extends APIService {
|
||||
/**
|
||||
* Creates an instance of InstanceService
|
||||
* Initializes the service with the base API URL
|
||||
*/
|
||||
constructor() {
|
||||
super(API_BASE_URL);
|
||||
}
|
||||
@@ -39,19 +34,6 @@ export class InstanceService extends APIService {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the changelog for the current instance
|
||||
* @returns {Promise<TPage>} Promise resolving to the changelog page data
|
||||
* @throws {Error} If the API request fails
|
||||
*/
|
||||
async changelog(): Promise<TPage> {
|
||||
return this.get("/api/instances/changelog/")
|
||||
.then((response) => response.data)
|
||||
.catch((error) => {
|
||||
throw error?.response?.data;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the list of instance admins
|
||||
* @returns {Promise<IInstanceAdmin[]>} Promise resolving to an array of instance admins
|
||||
@@ -1 +1 @@
|
||||
export * from "./instance.service";
|
||||
export * from "./core";
|
||||
|
||||
57
packages/services/src/instance/types.ts
Normal file
57
packages/services/src/instance/types.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import * as z from "zod";
|
||||
|
||||
export const InstanceSchema = z.object({
|
||||
id: z.string(),
|
||||
created_at: z.string(),
|
||||
updated_at: z.string(),
|
||||
instance_name: z.string().optional(),
|
||||
whitelist_emails: z.string().optional(),
|
||||
instance_id: z.string().optional(),
|
||||
current_version: z.string().optional(),
|
||||
latest_version: z.string().optional(),
|
||||
last_checked_at: z.string().optional(),
|
||||
namespace: z.string().optional(),
|
||||
is_telemetry_enabled: z.boolean(),
|
||||
is_support_required: z.boolean(),
|
||||
is_activated: z.boolean(),
|
||||
is_setup_done: z.boolean(),
|
||||
is_signup_screen_visited: z.boolean(),
|
||||
user_count: z.number().optional(),
|
||||
is_verified: z.boolean(),
|
||||
workspaces_exist: z.boolean(),
|
||||
});
|
||||
|
||||
export type TInstance = z.infer<typeof InstanceSchema>;
|
||||
|
||||
export const InstanceConfigSchema = z.object({
|
||||
enable_signup: z.boolean(),
|
||||
is_workspace_creation_disabled: z.boolean(),
|
||||
is_google_enabled: z.boolean(),
|
||||
is_github_enabled: z.boolean(),
|
||||
is_gitlab_enabled: z.boolean(),
|
||||
is_magic_login_enabled: z.boolean(),
|
||||
is_email_password_enabled: z.boolean(),
|
||||
github_app_name: z.string().optional(),
|
||||
slack_client_id: z.string().optional(),
|
||||
posthog_api_key: z.string().optional(),
|
||||
posthog_host: z.string().optional(),
|
||||
has_unsplash_configured: z.boolean(),
|
||||
has_llm_configured: z.boolean(),
|
||||
file_size_limit: z.number().optional(),
|
||||
is_smtp_configured: z.boolean(),
|
||||
app_base_url: z.string().optional(),
|
||||
space_base_url: z.string().optional(),
|
||||
admin_base_url: z.string().optional(),
|
||||
is_intercom_enabled: z.boolean(),
|
||||
intercom_app_id: z.string().optional(),
|
||||
instance_changelog_url: z.string().optional(),
|
||||
});
|
||||
|
||||
export type TInstanceConfig = z.infer<typeof InstanceConfigSchema>;
|
||||
|
||||
export const InstanceResponseSchema = z.object({
|
||||
instance: InstanceSchema,
|
||||
config: InstanceConfigSchema,
|
||||
});
|
||||
|
||||
export type TInstanceResponse = z.infer<typeof InstanceResponseSchema>;
|
||||
@@ -1,8 +0,0 @@
|
||||
import { API_BASE_URL } from "@plane/constants";
|
||||
import { APIService } from "./api.service";
|
||||
|
||||
export abstract class LiveService extends APIService {
|
||||
constructor(BASE_URL?: string) {
|
||||
super(BASE_URL || API_BASE_URL);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user