people endpoints and super user events built

This commit is contained in:
berkay 2025-04-13 17:28:20 +03:00
parent c3b7556e7e
commit 9a4696af77
363 changed files with 3270 additions and 264289 deletions

View File

@ -1,5 +1,6 @@
from Schemas import (
Users,
Events,
Services,
Service2Events,
Applications,
@ -10,15 +11,13 @@ from Schemas import (
)
list_of_event_codes = []
def init_service_to_event_matches_for_super_user(super_user, db_session=None) -> None:
service_match = Services.filter_one(
Services.service_name == "Super User",
db=db_session,
).data
for list_of_event_code in list_of_event_codes:
list_of_all_events = Events.filter_all(db=db_session).data
for list_of_event_code in list_of_all_events:
created_service = Service2Events.find_or_create(
service_id=service_match.id,
service_uu_id=str(service_match.uu_id),
@ -33,16 +32,17 @@ def init_service_to_event_matches_for_super_user(super_user, db_session=None) ->
print(
f"UUID: {created_service.uu_id} event is saved to {service_match.uu_id}"
)
employee_added_service = Event2Employee.find_or_create(
event_service_id=created_service.id,
event_service_uu_id=str(created_service.uu_id),
employee_id=super_user.id,
employee_uu_id=str(super_user.uu_id),
is_confirmed=True,
db=db_session,
employee_added_service = Event2Employee.find_or_create(
event_service_id=service_match.id,
event_service_uu_id=str(service_match.uu_id),
employee_id=super_user.id,
employee_uu_id=str(super_user.uu_id),
is_confirmed=True,
db=db_session,
)
if employee_added_service.meta_data.created:
employee_added_service.save(db=db_session)
print(
f"UUID: {employee_added_service.uu_id} event is saved to {super_user.uu_id}"
)
if employee_added_service.meta_data.created:
employee_added_service.save(db=db_session)
print(
f"UUID: {employee_added_service.uu_id} event is saved to {super_user.uu_id}"
)

View File

@ -0,0 +1,26 @@
FROM python:3.12-slim
WORKDIR /
# Install system dependencies and Poetry
RUN apt-get update && apt-get install -y --no-install-recommends gcc \
&& rm -rf /var/lib/apt/lists/* && pip install --no-cache-dir poetry
# Copy Poetry configuration
COPY /pyproject.toml ./pyproject.toml
# Configure Poetry and install dependencies with optimizations
RUN poetry config virtualenvs.create false \
&& poetry install --no-interaction --no-ansi --no-root --only main \
&& pip cache purge && rm -rf ~/.cache/pypoetry
# Copy application code
COPY /ApiServices/IdentityService /ApiServices/IdentityService
COPY /Controllers /Controllers
COPY /Schemas /Schemas
# Set Python path to include app directory
ENV PYTHONPATH=/ PYTHONUNBUFFERED=1 PYTHONDONTWRITEBYTECODE=1
# Run the application using the configured uvicorn server
CMD ["poetry", "run", "python", "ApiServices/IdentityService/app.py"]

View File

@ -0,0 +1,16 @@
import uvicorn
from config import api_config
from create_app import create_app
# from prometheus_fastapi_instrumentator import Instrumentator
app = create_app() # Create FastAPI application
# Instrumentator().instrument(app=app).expose(app=app) # Setup Prometheus metrics
if __name__ == "__main__":
# Run the application with Uvicorn Server
uvicorn_config = uvicorn.Config(**api_config.app_as_dict)
uvicorn.Server(uvicorn_config).run()

View File

@ -0,0 +1,64 @@
from pydantic_settings import BaseSettings, SettingsConfigDict
from fastapi.responses import JSONResponse
class Configs(BaseSettings):
"""
ApiTemplate configuration settings.
"""
PATH: str = ""
HOST: str = ""
PORT: int = 0
LOG_LEVEL: str = "info"
RELOAD: int = 0
ACCESS_TOKEN_TAG: str = ""
ACCESS_EMAIL_EXT: str = ""
TITLE: str = ""
ALGORITHM: str = ""
ACCESS_TOKEN_LENGTH: int = 90
REFRESHER_TOKEN_LENGTH: int = 144
EMAIL_HOST: str = ""
DATETIME_FORMAT: str = ""
FORGOT_LINK: str = ""
ALLOW_ORIGINS: list = ["http://localhost:3000"]
VERSION: str = "0.1.001"
DESCRIPTION: str = ""
@property
def app_as_dict(self) -> dict:
"""
Convert the settings to a dictionary.
"""
return {
"app": self.PATH,
"host": self.HOST,
"port": int(self.PORT),
"log_level": self.LOG_LEVEL,
"reload": bool(self.RELOAD),
}
@property
def api_info(self):
"""
Returns a dictionary with application information.
"""
return {
"title": self.TITLE,
"description": self.DESCRIPTION,
"default_response_class": JSONResponse,
"version": self.VERSION,
}
@classmethod
def forgot_link(cls, forgot_key):
"""
Generate a forgot password link.
"""
return cls.FORGOT_LINK + forgot_key
model_config = SettingsConfigDict(env_prefix="API_")
api_config = Configs()

View File

@ -0,0 +1,49 @@
from fastapi import FastAPI, Request
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import RedirectResponse
from endpoints.routes import get_routes
from open_api_creator import create_openapi_schema
from middlewares.token_middleware import token_middleware
from initializer.create_route import RouteRegisterController
from config import api_config
def create_events_if_any_cluster_set():
import events
for event_str in events.__all__:
if to_set_events := getattr(events, event_str, None):
to_set_events.set_events_to_database()
def create_app():
application = FastAPI(**api_config.api_info)
# application.mount(
# "/application/static",
# StaticFiles(directory="application/static"),
# name="static",
# )
application.add_middleware(
CORSMiddleware,
allow_origins=api_config.ALLOW_ORIGINS,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@application.middleware("http")
async def add_token_middleware(request: Request, call_next):
return await token_middleware(request, call_next)
@application.get("/", description="Redirect Route", include_in_schema=False)
async def redirect_to_docs():
return RedirectResponse(url="/docs")
route_register = RouteRegisterController(app=application, router_list=get_routes())
application = route_register.register_routes()
create_events_if_any_cluster_set()
application.openapi = lambda _=application: create_openapi_schema(_)
return application

View File

@ -0,0 +1,123 @@
import uuid
from fastapi import APIRouter, Request, Response, Header
from ApiServices.IdentityService.config import api_config
from ApiServices.IdentityService.events.people.event import PeopleCluster
from ApiServices.IdentityService.providers.token_provider import TokenProvider
from Controllers.Postgres.pagination import PaginateOnly
people_route = APIRouter(prefix="/people", tags=["People"])
@people_route.post(
path="/list",
description="Test Template Route",
operation_id="f102db46-031a-43e4-966a-dae6896f985b",
)
def people_route_list(
request: Request,
response: Response,
data: PaginateOnly,
language: str = Header(None, alias="language"),
domain: str = Header(None, alias="domain"),
tz: str = Header(None, alias="timezone"),
):
"""
Test Template Route
"""
endpoint_code = "f102db46-031a-43e4-966a-dae6896f985b"
token = request.headers.get(api_config.ACCESS_TOKEN_TAG, None)
headers = {
"language": language or "",
"domain": domain or "",
"eys-ext": f"{str(uuid.uuid4())}",
"tz": tz or "GMT+3",
"token": token,
}
token_object = TokenProvider.get_dict_from_redis(token=token)
event_key = TokenProvider.retrieve_event_codes(
endpoint_code=endpoint_code, token=token_object
)
event_cluster_matched = PeopleCluster.PeopleListCluster.match_event(
event_key=event_key
)
response.headers["X-Header"] = "Test Header GET"
if runner_callable := event_cluster_matched.event_callable(list_options=data):
return runner_callable
raise ValueError("Event key not found or multiple matches found")
@people_route.post(
path="/create",
description="Test Template Route with Post Method",
operation_id="eb465fde-337f-4b81-94cf-28c6d4f2b1b6",
)
def test_template_post(
request: Request,
response: Response,
language: str = Header(None, alias="language"),
domain: str = Header(None, alias="domain"),
tz: str = Header(None, alias="timezone"),
):
"""
Test Template Route with Post Method
"""
endpoint_code = "eb465fde-337f-4b81-94cf-28c6d4f2b1b6"
token = request.headers.get(api_config.ACCESS_TOKEN_TAG, None)
headers = {
"language": language or "",
"domain": domain or "",
"eys-ext": f"{str(uuid.uuid4())}",
"tz": tz or "GMT+3",
"token": token,
}
token_object = TokenProvider.get_dict_from_redis(token=token)
event_key = TokenProvider.retrieve_event_codes(
endpoint_code=endpoint_code, token=token_object
)
event_cluster_matched = PeopleCluster.PeopleCreateCluster.match_event(
event_key=event_key
)
response.headers["X-Header"] = "Test Header POST"
if runner_callable := event_cluster_matched.event_callable():
return runner_callable
raise ValueError("Event key not found or multiple matches found")
@people_route.post(
path="/update",
description="Test Template Route with Post Method",
operation_id="c9e5ba69-6915-43f5-8f9c-a5c2aa865b89",
)
def test_template_post(
request: Request,
response: Response,
language: str = Header(None, alias="language"),
domain: str = Header(None, alias="domain"),
tz: str = Header(None, alias="timezone"),
):
"""
Test Template Route with Post Method
"""
token = request.headers.get(api_config.ACCESS_TOKEN_TAG, None)
endpoint_code = "c9e5ba69-6915-43f5-8f9c-a5c2aa865b89"
headers = {
"language": language or "",
"domain": domain or "",
"eys-ext": f"{str(uuid.uuid4())}",
"tz": tz or "GMT+3",
"token": token,
}
token_object = TokenProvider.get_dict_from_redis(token=token)
event_key = TokenProvider.retrieve_event_codes(
endpoint_code=endpoint_code, token=token_object
)
event_cluster_matched = PeopleCluster.PeopleUpdateCluster.match_event(
event_key=event_key
)
response.headers["X-Header"] = "Test Header POST"
if runner_callable := event_cluster_matched.event_callable():
return runner_callable
raise ValueError("Event key not found or multiple matches found")

View File

@ -0,0 +1,21 @@
from fastapi import APIRouter
# from .user.route import user_route
from .people.route import people_route
def get_routes() -> list[APIRouter]:
return [
# user_route,
people_route
]
def get_safe_endpoint_urls() -> list[tuple[str, str]]:
return [
("/", "GET"),
("/docs", "GET"),
("/redoc", "GET"),
("/openapi.json", "GET"),
("/metrics", "GET"),
]

View File

@ -0,0 +1,90 @@
import uuid
from fastapi import APIRouter, Request, Response, Header
from ApiServices.IdentityService.config import api_config
from ApiServices.IdentityService.events.user.event import supers_users_list
user_route = APIRouter(prefix="/user", tags=["User"])
@user_route.post(
path="/list",
description="Test Template Route",
operation_id="5bc09312-d3f2-4f47-baba-17c928706da8",
)
def test_template(
request: Request,
response: Response,
language: str = Header(None, alias="language"),
domain: str = Header(None, alias="domain"),
tz: str = Header(None, alias="timezone"),
):
"""
Test Template Route
"""
event_code = "bb20c8c6-a289-4cab-9da7-34ca8a36c8e5"
token = request.headers.get(api_config.ACCESS_TOKEN_TAG, None)
headers = {
"language": language or "",
"domain": domain or "",
"eys-ext": f"{str(uuid.uuid4())}",
"tz": tz or "GMT+3",
"token": token,
}
event_cluster_matched = supers_users_list.match_event(
event_keys=[
"3f510dcf-9f84-4eb9-b919-f582f30adab1",
"9f403034-deba-4e1f-b43e-b25d3c808d39",
"b8ec6e64-286a-4f60-8554-7a3865454944",
]
)
response.headers["X-Header"] = "Test Header GET"
if runner_callable := event_cluster_matched.example_callable():
return runner_callable
raise ValueError("Event key not found or multiple matches found")
@user_route.post(
path="/create",
description="Test Template Route with Post Method",
operation_id="08d4b572-1584-47bb-aa42-8d068e5514e7",
)
def test_template_post(request: Request, response: Response):
"""
Test Template Route with Post Method
"""
event_cluster_matched = supers_users_list.match_event(
event_keys=[
"3f510dcf-9f84-4eb9-b919-f582f30adab1",
"9f403034-deba-4e1f-b43e-b25d3c808d39",
"b8ec6e64-286a-4f60-8554-7a3865454944",
]
)
response.headers["X-Header"] = "Test Header POST"
if runner_callable := event_cluster_matched.example_callable():
return runner_callable
raise ValueError("Event key not found or multiple matches found")
@user_route.post(
path="/update",
description="Test Template Route with Post Method",
operation_id="b641236a-928d-4f19-a1d2-5edf611d1e56",
)
def test_template_post(request: Request, response: Response):
"""
Test Template Route with Post Method
"""
event_cluster_matched = supers_users_list.match_event(
event_keys=[
"3f510dcf-9f84-4eb9-b919-f582f30adab1",
"9f403034-deba-4e1f-b43e-b25d3c808d39",
"b8ec6e64-286a-4f60-8554-7a3865454944",
]
)
response.headers["X-Header"] = "Test Header POST"
if runner_callable := event_cluster_matched.example_callable():
return runner_callable
raise ValueError("Event key not found or multiple matches found")

View File

@ -0,0 +1,12 @@
from .people.event import (
people_event_cluster_list,
people_event_cluster_update,
people_event_cluster_create,
)
__all__ = [
"people_event_cluster_list",
"people_event_cluster_update",
"people_event_cluster_create",
]

View File

@ -0,0 +1,128 @@
from ApiServices.IdentityService.initializer.event_clusters import EventCluster, Event
from ApiServices.IdentityService.validations.people.validations import (
REQUESTAWMXNTKMGPPOJWRCTZUBADNFLQDBDYVQAORFAVCSXUUHEBQHCEPCSKFBADBODFDBPYKOVINV,
)
from Controllers.Postgres.pagination import Pagination, PaginationResult, PaginateOnly
from Controllers.Postgres.response import EndpointResponse
from Schemas.identity.identity import People
# Create endpoint
supers_people_create = Event(
name="supers_people_list",
key="ec4c2404-a61b-46c7-bbdf-ce3357e6cf41",
request_validator=None, # TODO: Add request validator
response_validator=None, # TODO: Add response validator
description="Create events of people endpoint",
)
def supers_people_create_callable(list_options):
"""
Example callable method
"""
return {
"completed": True,
"message": "Example callable method 2",
"info": {
"host": "example_host",
"user_agent": "example_user_agent",
},
}
supers_people_create.event_callable = supers_people_create_callable
people_event_cluster_create = EventCluster(
endpoint_uu_id="eb465fde-337f-4b81-94cf-28c6d4f2b1b6"
)
people_event_cluster_create.add_event([supers_people_create])
# Update endpoint
supers_people_update = Event(
name="supers_people_update",
key="91e77de4-9f29-4309-b121-4aad256d440c",
request_validator=None, # TODO: Add request validator
response_validator=None, # TODO: Add response validator
description="Update events of people endpoint",
)
def supers_people_update_callable():
"""
Example callable method
"""
return {
"completed": True,
"message": "Example callable method 2",
"info": {
"host": "example_host",
"user_agent": "example_user_agent",
},
}
supers_people_update.event_callable = supers_people_update_callable
people_event_cluster_update = EventCluster(
endpoint_uu_id="c9e5ba69-6915-43f5-8f9c-a5c2aa865b89"
)
people_event_cluster_update.add_event([supers_people_update])
# List endpoint
supers_people_list = Event(
name="supers_people_list",
key="6828d280-e587-400d-a622-c318277386c3",
request_validator=None, # TODO: Add request validator
response_validator=None, # TODO: Add response validator
description="List events of people endpoint",
)
def supers_people_list_callable(list_options: PaginateOnly):
"""
Example callable method
"""
list_options = PaginateOnly(**list_options.model_dump())
with People.new_session() as db_session:
People.pre_query = People.filter_all(
People.firstname.ilike("%B%"), db=db_session
).query
if list_options.query:
people_list = People.filter_all(
*People.convert(list_options.query), db=db_session
)
else:
people_list = People.filter_all(db=db_session)
pagination = Pagination(data=people_list)
pagination.change(**list_options.model_dump())
pagination_result = PaginationResult(
data=people_list,
pagination=pagination,
response_model=REQUESTAWMXNTKMGPPOJWRCTZUBADNFLQDBDYVQAORFAVCSXUUHEBQHCEPCSKFBADBODFDBPYKOVINV,
)
return EndpointResponse(
message="MSG0002-LIST",
pagination_result=pagination_result,
).response
supers_people_list.event_callable = supers_people_list_callable
people_event_cluster_list = EventCluster(
endpoint_uu_id="f102db46-031a-43e4-966a-dae6896f985b"
)
people_event_cluster_list.add_event([supers_people_list])
class PeopleCluster:
"""
People Clusters
"""
PeopleListCluster = people_event_cluster_list
PeopleCreateCluster = people_event_cluster_create
PeopleUpdateCluster = people_event_cluster_update

View File

@ -0,0 +1,33 @@
from ApiServices.IdentityService.initializer.event_clusters import EventCluster, Event
supers_users_list = Event(
name="supers_people_list",
key="341b394f-9f11-4abb-99e7-4b27fa6bf012",
request_validator=None, # TODO: Add request validator
response_validator=None, # TODO: Add response validator
description="Example event description",
)
def supers_people_list_callable():
"""
Example callable method
"""
return {
"completed": True,
"message": "Example callable method 2",
"info": {
"host": "example_host",
"user_agent": "example_user_agent",
},
}
supers_users_list.event_callable = supers_people_list_callable
people_event_cluster_list = EventCluster(
endpoint_uu_id="f102db46-031a-43e4-966a-dae6896f985b"
)
people_event_cluster_list.add_event([supers_users_list])

View File

@ -0,0 +1,42 @@
from typing import List
from fastapi import APIRouter, FastAPI
class RouteRegisterController:
def __init__(self, app: FastAPI, router_list: List[APIRouter]):
self.router_list = router_list
self.app = app
@staticmethod
def add_router_with_event_to_database(router: APIRouter):
from Schemas import EndpointRestriction
with EndpointRestriction.new_session() as db_session:
for route in router.routes:
route_path = str(getattr(route, "path"))
route_summary = str(getattr(route, "name"))
operation_id = getattr(route, "operation_id", None)
if not operation_id:
continue
for route_method in [
method.lower() for method in getattr(route, "methods")
]:
restriction = EndpointRestriction.find_or_create(
endpoint_method=route_method,
endpoint_name=route_path,
endpoint_desc=route_summary.replace("_", " "),
endpoint_function=route_summary,
operation_uu_id=operation_id, # UUID of the endpoint
is_confirmed=True,
db=db_session,
)
if restriction.meta_data.created:
restriction.save(db=db_session)
def register_routes(self):
for router in self.router_list:
self.app.include_router(router)
self.add_router_with_event_to_database(router)
return self.app

View File

@ -0,0 +1,91 @@
from typing import Optional, Type
from pydantic import BaseModel
class EventCluster:
def __init__(self, endpoint_uu_id: str):
self.endpoint_uu_id = endpoint_uu_id
self.events = []
def add_event(self, list_of_events: list["Event"]):
"""
Add an event to the cluster
"""
for event in list_of_events:
self.events.append(event)
self.events = list(set(self.events))
def get_event(self, event_key: str):
"""
Get an event by its key
"""
for event in self.events:
if event.key == event_key:
return event
return None
def set_events_to_database(self):
from Schemas import Events, EndpointRestriction
with Events.new_session() as db_session:
if to_save_endpoint := EndpointRestriction.filter_one(
EndpointRestriction.operation_uu_id == self.endpoint_uu_id,
db=db_session,
).data:
for event in self.events:
event_to_save_database = Events.find_or_create(
function_code=event.key,
function_class=event.name,
description=event.description,
endpoint_code=self.endpoint_uu_id,
endpoint_id=to_save_endpoint.id,
endpoint_uu_id=str(to_save_endpoint.uu_id),
is_confirmed=True,
active=True,
db=db_session,
)
if event_to_save_database.meta_data.created:
event_to_save_database.save(db=db_session)
print(
f"UUID: {event_to_save_database.uu_id} event is saved to {to_save_endpoint.uu_id}"
)
def match_event(self, event_key: str) -> "Event":
"""
Match an event by its key
"""
# print('set(event_keys)', set(event_keys))
# print('event.keys', set([event.key for event in self.events]))
# intersection_of_key: set[str] = set(event_key) & set([event.key for event in self.events])
# if not len(intersection_of_key) == 1:
# raise ValueError(
# f"Event key not found or multiple matches found: {intersection_of_key}"
# )
return self.get_event(event_key=event_key)
class Event:
def __init__(
self,
name: str,
key: str,
request_validator: Optional[Type[BaseModel]] = None,
response_validator: Optional[Type[BaseModel]] = None,
description: str = "",
):
self.name = name
self.key = key
self.request_validator = request_validator
self.response_validator = response_validator
self.description = description
def event_callable(self):
"""
Example callable method
"""
print(self.name)
return {}

View File

@ -0,0 +1,24 @@
from fastapi import Request, status
from fastapi.responses import JSONResponse
from ApiServices.IdentityService.endpoints.routes import get_safe_endpoint_urls
from ApiServices.IdentityService.config import api_config
async def token_middleware(request: Request, call_next):
base_url = request.url.path
safe_endpoints = [_[0] for _ in get_safe_endpoint_urls()]
if base_url in safe_endpoints:
return await call_next(request)
token = request.headers.get(api_config.ACCESS_TOKEN_TAG, None)
if not token:
return JSONResponse(
content={
"error": "EYS_0002",
},
status_code=status.HTTP_401_UNAUTHORIZED,
)
response = await call_next(request)
return response

View File

@ -0,0 +1,116 @@
from typing import Any, Dict
from fastapi import FastAPI
from fastapi.routing import APIRoute
from fastapi.openapi.utils import get_openapi
from config import api_config as template_api_config
from endpoints.routes import get_safe_endpoint_urls
class OpenAPISchemaCreator:
"""
OpenAPI schema creator and customizer for FastAPI applications.
"""
def __init__(self, app: FastAPI):
"""
Initialize the OpenAPI schema creator.
Args:
app: FastAPI application instance
"""
self.app = app
self.safe_endpoint_list: list[tuple[str, str]] = get_safe_endpoint_urls()
self.routers_list = self.app.routes
@staticmethod
def create_security_schemes() -> Dict[str, Any]:
"""
Create security scheme definitions.
Returns:
Dict[str, Any]: Security scheme configurations
"""
return {
"BearerAuth": {
"type": "apiKey",
"in": "header",
"name": template_api_config.ACCESS_TOKEN_TAG,
"description": "Enter: **'Bearer <JWT>'**, where JWT is the access token",
}
}
def configure_route_security(
self, path: str, method: str, schema: Dict[str, Any]
) -> None:
"""
Configure security requirements for a specific route.
Args:
path: Route path
method: HTTP method
schema: OpenAPI schema to modify
"""
if not schema.get("paths", {}).get(path, {}).get(method):
return
# Check if endpoint is in safe list
endpoint_path = f"{path}:{method}"
list_of_safe_endpoints = [
f"{e[0]}:{str(e[1]).lower()}" for e in self.safe_endpoint_list
]
if endpoint_path not in list_of_safe_endpoints:
if "security" not in schema["paths"][path][method]:
schema["paths"][path][method]["security"] = []
schema["paths"][path][method]["security"].append({"BearerAuth": []})
def create_schema(self) -> Dict[str, Any]:
"""
Create the complete OpenAPI schema.
Returns:
Dict[str, Any]: Complete OpenAPI schema
"""
openapi_schema = get_openapi(
title=template_api_config.TITLE,
description=template_api_config.DESCRIPTION,
version=template_api_config.VERSION,
routes=self.app.routes,
)
# Add security schemes
if "components" not in openapi_schema:
openapi_schema["components"] = {}
openapi_schema["components"]["securitySchemes"] = self.create_security_schemes()
# Configure route security and responses
for route in self.app.routes:
if isinstance(route, APIRoute) and route.include_in_schema:
path = str(route.path)
methods = [method.lower() for method in route.methods]
for method in methods:
self.configure_route_security(path, method, openapi_schema)
# Add custom documentation extensions
openapi_schema["x-documentation"] = {
"postman_collection": "/docs/postman",
"swagger_ui": "/docs",
"redoc": "/redoc",
}
return openapi_schema
def create_openapi_schema(app: FastAPI) -> Dict[str, Any]:
"""
Create OpenAPI schema for a FastAPI application.
Args:
app: FastAPI application instance
Returns:
Dict[str, Any]: Complete OpenAPI schema
"""
creator = OpenAPISchemaCreator(app)
return creator.create_schema()

View File

@ -0,0 +1,206 @@
import enum
from typing import Optional, Union, Dict, Any, List
from pydantic import BaseModel
from Controllers.Redis.database import RedisActions
class UserType(enum.Enum):
employee = 1
occupant = 2
class Credentials(BaseModel):
person_id: int
person_name: str
class ApplicationToken(BaseModel):
# Application Token Object -> is the main object for the user
user_type: int = UserType.occupant.value
credential_token: str = ""
user_uu_id: str
user_id: int
person_id: int
person_uu_id: str
request: Optional[dict] = None # Request Info of Client
expires_at: Optional[float] = None # Expiry timestamp
class OccupantToken(BaseModel):
# Selection of the occupant type for a build part is made by the user
living_space_id: int # Internal use
living_space_uu_id: str # Outer use
occupant_type_id: int
occupant_type_uu_id: str
occupant_type: str
build_id: int
build_uuid: str
build_part_id: int
build_part_uuid: str
responsible_company_id: Optional[int] = None
responsible_company_uuid: Optional[str] = None
responsible_employee_id: Optional[int] = None
responsible_employee_uuid: Optional[str] = None
# ID list of reachable event codes as "endpoint_code": ["UUID", "UUID"]
reachable_event_codes: Optional[dict[str, str]] = None
# ID list of reachable applications as "page_url": ["UUID", "UUID"]
reachable_app_codes: Optional[dict[str, str]] = None
class CompanyToken(BaseModel):
# Selection of the company for an employee is made by the user
company_id: int
company_uu_id: str
department_id: int # ID list of departments
department_uu_id: str # ID list of departments
duty_id: int
duty_uu_id: str
staff_id: int
staff_uu_id: str
employee_id: int
employee_uu_id: str
bulk_duties_id: int
# ID list of reachable event codes as "endpoint_code": ["UUID", "UUID"]
reachable_event_codes: Optional[dict[str, str]] = None
# ID list of reachable applications as "page_url": ["UUID", "UUID"]
reachable_app_codes: Optional[dict[str, str]] = None
class OccupantTokenObject(ApplicationToken):
# Occupant Token Object -> Requires selection of the occupant type for a specific build part
available_occupants: dict = None
selected_occupant: Optional[OccupantToken] = None # Selected Occupant Type
@property
def is_employee(self) -> bool:
return False
@property
def is_occupant(self) -> bool:
return True
class EmployeeTokenObject(ApplicationToken):
# Full hierarchy Employee[staff_id] -> Staff -> Duty -> Department -> Company
companies_id_list: List[int] # List of company objects
companies_uu_id_list: List[str] # List of company objects
duty_id_list: List[int] # List of duty objects
duty_uu_id_list: List[str] # List of duty objects
selected_company: Optional[CompanyToken] = None # Selected Company Object
@property
def is_employee(self) -> bool:
return True
@property
def is_occupant(self) -> bool:
return False
TokenDictType = Union[EmployeeTokenObject, OccupantTokenObject]
class TokenProvider:
AUTH_TOKEN: str = "AUTH_TOKEN"
@classmethod
def convert_redis_object_to_token(
cls, redis_object: Dict[str, Any]
) -> TokenDictType:
"""
Process Redis object and return appropriate token object.
"""
if redis_object.get("user_type") == UserType.employee.value:
return EmployeeTokenObject(**redis_object)
elif redis_object.get("user_type") == UserType.occupant.value:
return OccupantTokenObject(**redis_object)
raise ValueError("Invalid user type")
@classmethod
def get_dict_from_redis(
cls, token: Optional[str] = None, user_uu_id: Optional[str] = None
) -> Union[TokenDictType, List[TokenDictType]]:
"""
Retrieve token object from Redis using token and user_uu_id
"""
token_to_use, user_uu_id_to_use = token or "*", user_uu_id or "*"
list_of_token_dict, auth_key_list = [], [
cls.AUTH_TOKEN,
token_to_use,
user_uu_id_to_use,
]
if token:
result = RedisActions.get_json(list_keys=auth_key_list, limit=1)
if first_record := result.first:
return cls.convert_redis_object_to_token(first_record)
elif user_uu_id:
result = RedisActions.get_json(list_keys=auth_key_list)
if all_records := result.all:
for all_record in all_records:
list_of_token_dict.append(
cls.convert_redis_object_to_token(all_record)
)
return list_of_token_dict
raise ValueError(
"Token not found in Redis. Please check the token or user_uu_id."
)
@classmethod
def retrieve_application_codes(cls, page_url: str, token: TokenDictType):
"""
Retrieve application code from the token object or list of token objects.
"""
if isinstance(token, EmployeeTokenObject):
if application_codes := token.selected_company.reachable_app_codes.get(
page_url, None
):
return application_codes
elif isinstance(token, OccupantTokenObject):
if application_codes := token.selected_occupant.reachable_app_codes.get(
page_url, None
):
return application_codes
raise ValueError("Invalid token type or no application code found.")
@classmethod
def retrieve_event_codes(cls, endpoint_code: str, token: TokenDictType) -> str:
"""
Retrieve event code from the token object or list of token objects.
"""
if isinstance(token, EmployeeTokenObject):
if event_codes := token.selected_company.reachable_event_codes.get(
endpoint_code, None
):
return event_codes
elif isinstance(token, OccupantTokenObject):
if event_codes := token.selected_occupant.reachable_event_codes.get(
endpoint_code, None
):
return event_codes
raise ValueError("Invalid token type or no event code found.")

View File

@ -0,0 +1,26 @@
from pydantic import BaseModel
from typing import Optional
class ListOptions(BaseModel):
"""
Query for list option abilities
"""
page: Optional[int] = 1
size: Optional[int] = 10
order_field: Optional[str] = "id"
order_type: Optional[str] = "asc"
# include_joins: Optional[list] = None
query: Optional[dict] = None
class PaginateOnly(BaseModel):
"""
Query for list option abilities
"""
page: Optional[int] = 1
size: Optional[int] = 10
order_field: Optional[str] = "id"
order_type: Optional[str] = "asc"

View File

@ -0,0 +1,53 @@
from pydantic import BaseModel
"""
"sex_code": "M",
"country_code": "TR",
"created_at": "2025-04-13 10:03:32 +00:00",
"father_name": "Father",
"birth_place": "Ankara",
"updated_credentials_token": null,
"cryp_uu_id": null,
"mother_name": "Mother",
"expiry_starts": "2025-04-13 10:03:32 +00:00",
"confirmed_credentials_token": null,
"surname": "Karatay",
"firstname": "Berkay Super User",
"birth_date": "1990-01-07 00:00:00 +00:00",
"expiry_ends": "2099-12-31 00:00:00 +00:00",
"is_confirmed": true,
"is_email_send": false,
"tax_no": "1231231232",
"person_ref": "",
"active": true,
"deleted": false,
"updated_at": "2025-04-13 10:03:32 +00:00",
"uu_id": "b5b6e68f-a4d0-4d64-aa18-634671cb1299",
"middle_name": "",
"created_credentials_token": null,
"person_tag": "BSU-System",
"is_notification_send": false
"""
class REQUESTAWMXNTKMGPPOJWRCTZUBADNFLQDBDYVQAORFAVCSXUUHEBQHCEPCSKFBADBODFDBPYKOVINV(
BaseModel
):
uu_id: str
created_at: str
updated_at: str
person_tag: str
expiry_starts: str
expiry_ends: str
firstname: str
middle_name: str
surname: str
birth_date: str
birth_place: str
sex_code: str
country_code: str
tax_no: str
active: bool
deleted: bool
is_confirmed: bool
is_notification_send: bool

View File

@ -0,0 +1,33 @@
from pydantic import BaseModel
class FF7C859A068EB4583A47AB5924EC8C19A033881823FBA42EAAD089BF7AC8059CE(BaseModel):
"""
a13143ade48954c2ba3f86869e027de5b28c8a9b619bf4ef28264a8e375371601
"""
pass
class F1B82565925FF4F5DAD2A36370788305A0A362E031EAC4A9E8BDFF4F35E265A6C(BaseModel):
"""
aa487ab3bfd9e4e6abc2db714ac6197f60bbc9068ac6541e7a815d5b1e969796b
"""
pass
class F3117E7D66FE6471C8452B97AB504EF0C29822B6395CA4D65A18FDD563F0EC8D7(BaseModel):
"""
a1bf55a214b684438a97a47e4f097ac7ae27b0dff03c4475cbd4301e24a032aac
"""
pass
class F33B4DE316B8A456480DD6ED5B5E2D35A2E6FCAF74BAC40D7A2970D318B153F85(BaseModel):
"""
F33B4DE316B8A456480DD6ED5B5E2D35A2E6FCAF74BAC40D7A2970D318B153F85
"""
pass

View File

@ -1,8 +1,7 @@
import uvicorn
from config import api_config
from ApiServices.TemplateService.create_app import create_app
from .create_app import create_app
# from prometheus_fastapi_instrumentator import Instrumentator

View File

@ -2,12 +2,12 @@ from fastapi import FastAPI, Request
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import RedirectResponse
from ApiServices.TemplateService.endpoints.routes import get_routes
from ApiServices.TemplateService.open_api_creator import create_openapi_schema
from ApiServices.TemplateService.middlewares.token_middleware import token_middleware
from ApiServices.TemplateService.initializer.create_route import RouteRegisterController
from endpoints.routes import get_routes
from open_api_creator import create_openapi_schema
from middlewares.token_middleware import token_middleware
from initializer.create_route import RouteRegisterController
from .config import api_config
from config import api_config
def create_events_if_any_cluster_set():

View File

@ -1,7 +1,7 @@
from fastapi import Request, status
from fastapi.responses import JSONResponse
from ..endpoints.routes import get_safe_endpoint_urls
from ..config import api_config
from ApiServices.TemplateService.endpoints.routes import get_safe_endpoint_urls
from ApiServices.TemplateService.config import api_config
async def token_middleware(request: Request, call_next):

View File

@ -3,8 +3,8 @@ from fastapi import FastAPI
from fastapi.routing import APIRoute
from fastapi.openapi.utils import get_openapi
from .config import api_config as template_api_config
from ApiServices.TemplateService.endpoints.routes import get_safe_endpoint_urls
from config import api_config as template_api_config
from endpoints.routes import get_safe_endpoint_urls
class OpenAPISchemaCreator:

View File

@ -0,0 +1,26 @@
from pydantic import BaseModel
from typing import Optional
class ListOptions(BaseModel):
"""
Query for list option abilities
"""
page: Optional[int] = 1
size: Optional[int] = 10
order_field: Optional[str] = "id"
order_type: Optional[str] = "asc"
query: Optional[dict] = None
# include_joins: Optional[list] = None
class PaginateOnly(BaseModel):
"""
Query for list option abilities
"""
page: Optional[int] = 1
size: Optional[int] = 10
order_field: Optional[str] = "id"
order_type: Optional[str] = "asc"

View File

@ -84,8 +84,8 @@ class MongoDBHandler(MongoDBConfig):
def __init__(
self,
uri: str,
max_pool_size: int = 20,
min_pool_size: int = 5,
max_pool_size: int = 5,
min_pool_size: int = 2,
max_idle_time_ms: int = 10000,
wait_queue_timeout_ms: int = 1000,
server_selection_timeout_ms: int = 3000,
@ -201,11 +201,11 @@ class CollectionContext:
self.collection = None
mongo_handler = MongoDBHandler(uri=mongo_configs.url)
"""
max_pool_size: int = 20,
min_pool_size: int = 10,
max_idle_time_ms: int = 30000,
wait_queue_timeout_ms: int = 2000,
server_selection_timeout_ms: int = 5000,
"""
mongo_handler = MongoDBHandler(
uri=mongo_configs.url,
max_pool_size=5,
min_pool_size=2,
max_idle_time_ms=30000,
wait_queue_timeout_ms=2000,
server_selection_timeout_ms=5000,
)

View File

@ -23,9 +23,17 @@ class BaseAlchemyModel:
__abstract__ = True
@classmethod
def refresh_class_attributes(cls):
cls.pre_query = None
cls.meta_data.created = False
cls.meta_data.updated = False
cls.meta_data.deleted = False
@classmethod
def new_session(cls):
"""Get database session."""
cls.refresh_class_attributes()
return get_db()
@classmethod

View File

@ -48,6 +48,8 @@ def get_db() -> Generator[Session, None, None]:
Yields:
Session: SQLAlchemy session object
"""
from Controllers.Postgres.mixin import CrudMixin
session_factory = get_session_factory()
session = session_factory()
try:

View File

@ -55,7 +55,6 @@ class QueryModel:
new_args = list(
dict.fromkeys(arg for arg in args_list if isinstance(arg, BinaryExpression))
)
# Check if argument already exists
if not any(
getattr(getattr(arg, "left", None), "key", None) == argument
@ -97,7 +96,6 @@ class QueryModel:
):
starts = cls.expiry_starts <= current_time
args = cls.add_new_arg_to_args(args, "expiry_starts", starts)
return args
except AttributeError as e:

View File

@ -0,0 +1,231 @@
from typing import Any, Dict, Optional, Union, TypeVar, Type
from sqlalchemy import desc, asc
from pydantic import BaseModel
from Controllers.Postgres.response import PostgresResponse
# Type variable for class methods returning self
T = TypeVar("T", bound="BaseModel")
class PaginateConfig:
"""
Configuration for pagination settings.
Attributes:
DEFAULT_SIZE: Default number of items per page (10)
MIN_SIZE: Minimum allowed page size (10)
MAX_SIZE: Maximum allowed page size (40)
"""
DEFAULT_SIZE = 10
MIN_SIZE = 1
MAX_SIZE = 100
class ListOptions(BaseModel):
"""
Query for list option abilities
"""
page: Optional[int] = 1
size: Optional[int] = 10
order_field: Optional[Union[tuple[str], list[str]]] = ["uu_id"]
order_type: Optional[Union[tuple[str], list[str]]] = ["asc"]
# include_joins: Optional[list] = None
class PaginateOnly(ListOptions):
"""
Query for list option abilities
"""
query: Optional[dict] = None
class PaginationConfig(BaseModel):
"""
Configuration for pagination settings.
Attributes:
page: Current page number (default: 1)
size: Items per page (default: 10)
order_field: Field to order by (default: "id")
order_type: Order direction (default: "asc")
"""
page: int = 1
size: int = 10
order_field: Optional[Union[tuple[str], list[str]]] = ["uu_id"]
order_type: Optional[Union[tuple[str], list[str]]] = ["asc"]
def __init__(self, **data):
super().__init__(**data)
if self.order_field is None:
self.order_field = ["uu_id"]
if self.order_type is None:
self.order_type = ["asc"]
class Pagination:
"""
Handles pagination logic for query results.
Manages page size, current page, ordering, and calculates total pages
and items based on the data source.
Attributes:
DEFAULT_SIZE: Default number of items per page (10)
MIN_SIZE: Minimum allowed page size (10)
MAX_SIZE: Maximum allowed page size (40)
"""
DEFAULT_SIZE = PaginateConfig.DEFAULT_SIZE
MIN_SIZE = PaginateConfig.MIN_SIZE
MAX_SIZE = PaginateConfig.MAX_SIZE
def __init__(self, data: PostgresResponse):
self.data = data
self.size: int = self.DEFAULT_SIZE
self.page: int = 1
self.orderField: Optional[Union[tuple[str], list[str]]] = ["uu_id"]
self.orderType: Optional[Union[tuple[str], list[str]]] = ["asc"]
self.page_count: int = 1
self.total_count: int = 0
self.all_count: int = 0
self.total_pages: int = 1
self._update_page_counts()
def change(self, **kwargs) -> None:
"""Update pagination settings from config."""
config = PaginationConfig(**kwargs)
self.size = (
config.size
if self.MIN_SIZE <= config.size <= self.MAX_SIZE
else self.DEFAULT_SIZE
)
self.page = config.page
self.orderField = config.order_field
self.orderType = config.order_type
self._update_page_counts()
def feed(self, data: PostgresResponse) -> None:
"""Calculate pagination based on data source."""
self.data = data
self._update_page_counts()
def _update_page_counts(self) -> None:
"""Update page counts and validate current page."""
if self.data:
self.total_count = self.data.count
self.all_count = self.data.total_count
self.size = (
self.size
if self.MIN_SIZE <= self.size <= self.MAX_SIZE
else self.DEFAULT_SIZE
)
self.total_pages = max(1, (self.total_count + self.size - 1) // self.size)
self.page = max(1, min(self.page, self.total_pages))
self.page_count = (
self.total_count % self.size
if self.page == self.total_pages and self.total_count % self.size
else self.size
)
def refresh(self) -> None:
"""Reset pagination state to defaults."""
self._update_page_counts()
def reset(self) -> None:
"""Reset pagination state to defaults."""
self.size = self.DEFAULT_SIZE
self.page = 1
self.orderField = "uu_id"
self.orderType = "asc"
def as_dict(self) -> Dict[str, Any]:
"""Convert pagination state to dictionary format."""
self.refresh()
return {
"size": self.size,
"page": self.page,
"allCount": self.all_count,
"totalCount": self.total_count,
"totalPages": self.total_pages,
"pageCount": self.page_count,
"orderField": self.orderField,
"orderType": self.orderType,
}
class PaginationResult:
"""
Result of a paginated query.
Contains the query result and pagination state.
data: PostgresResponse of query results
pagination: Pagination state
Attributes:
_query: Original query object
pagination: Pagination state
"""
def __init__(
self,
data: PostgresResponse,
pagination: Pagination,
response_model: Type[T] = None,
):
self._query = data.query
self.pagination = pagination
self.response_type = data.is_list
self.limit = self.pagination.size
self.offset = self.pagination.size * (self.pagination.page - 1)
self.order_by = self.pagination.orderField
self.response_model = response_model
def dynamic_order_by(self):
"""
Dynamically order a query by multiple fields.
Returns:
Ordered query object.
"""
if not len(self.order_by) == len(self.pagination.orderType):
raise ValueError(
"Order by fields and order types must have the same length."
)
order_criteria = zip(self.order_by, self.pagination.orderType)
for field, direction in order_criteria:
if hasattr(self._query.column_descriptions[0]["entity"], field):
if direction.lower().startswith("d"):
self._query = self._query.order_by(
desc(
getattr(self._query.column_descriptions[0]["entity"], field)
)
)
else:
self._query = self._query.order_by(
asc(
getattr(self._query.column_descriptions[0]["entity"], field)
)
)
return self._query
@property
def data(self) -> Union[list | dict]:
"""Get query object."""
query_ordered = self.dynamic_order_by()
query_paginated = query_ordered.limit(self.limit).offset(self.offset)
queried_data = (
query_paginated.all() if self.response_type else query_paginated.first()
)
data = (
[result.get_dict() for result in queried_data]
if self.response_type
else queried_data.get_dict()
)
if self.response_model:
return [self.response_model(**item).model_dump() for item in data]
return data

View File

@ -6,6 +6,8 @@ adding convenience methods for accessing data and managing query state.
"""
from typing import Any, Dict, Optional, TypeVar, Generic, Union
from pydantic import BaseModel
from sqlalchemy.orm import Query
@ -107,3 +109,19 @@ class PostgresResponse(Generic[T]):
"count": self.count,
"data": self.data.get_dict() if self.data else {},
}
class EndpointResponse(BaseModel):
completed: bool = True
message: str = "Success"
pagination_result: Any
@property
def response(self):
"""Convert response to dictionary format."""
return {
"completed": self.completed,
"message": self.message,
"data": self.pagination_result.data,
"pagination": self.pagination_result.pagination.as_dict(),
}

View File

@ -288,15 +288,14 @@ class Event2Employee(CrudCollection):
)
@classmethod
def get_event_codes(cls, employee_id: int, db) -> dict[str : list[str]]:
def get_event_codes(cls, employee_id: int, db) -> dict[str:str]:
employee_events = cls.filter_all(
cls.employee_id == employee_id,
db=db,
).data
active_event_ids = Service2Events.filter_all_system(
Service2Events.service_id.in_(
[event.event_service_id for event in employee_events]
),
service_ids = list(set([event.event_service_id for event in employee_events]))
active_event_ids = Service2Events.filter_all(
Service2Events.service_id.in_(service_ids),
db=db,
).data
active_events = Events.filter_all(
@ -314,10 +313,10 @@ class Event2Employee(CrudCollection):
active_events.extend(events_extra)
events_dict = {}
for event in active_events:
if event.endpoint_code in events_dict:
events_dict[event.endpoint_code].append(event.function_code)
if not event.endpoint_code in events_dict:
events_dict[str(event.endpoint_code)] = str(event.function_code)
else:
events_dict[event.endpoint_code] = [event.function_code]
ValueError("Duplicate event code found for single endpoint")
return events_dict
@ -355,15 +354,14 @@ class Event2Occupant(CrudCollection):
)
@classmethod
def get_event_codes(cls, build_living_space_id: int, db) -> dict[str : list[str]]:
def get_event_codes(cls, build_living_space_id: int, db) -> dict[str:str]:
occupant_events = cls.filter_all(
cls.build_living_space_id == build_living_space_id,
db=db,
).data
service_ids = list(set([event.event_service_id for event in occupant_events]))
active_event_ids = Service2Events.filter_all_system(
Service2Events.service_id.in_(
[event.event_service_id for event in occupant_events]
),
Service2Events.service_id.in_(service_ids),
db=db,
).data
active_events = Events.filter_all(
@ -381,10 +379,10 @@ class Event2Occupant(CrudCollection):
active_events.extend(events_extra)
events_dict = {}
for event in active_events:
if event.endpoint_code in events_dict:
events_dict[event.endpoint_code].append(event.function_code)
if not event.endpoint_code in events_dict:
events_dict[str(event.endpoint_code)] = str(event.function_code)
else:
events_dict[event.endpoint_code] = [event.function_code]
ValueError("Duplicate event code found for single endpoint")
return events_dict

View File

@ -0,0 +1,19 @@
import string
import random
import uuid
def generate_validation_name(validation_type: str = "Request") -> str:
"""
Generate a validation name based on the current date and time.
"""
list_of_alphabet = list(string.ascii_lowercase)
base_uuids = str(uuid.uuid4()) * 2
result_string_list = []
for base_uuid in base_uuids:
if str(base_uuid).lower() not in list_of_alphabet:
result_string_list.append(str(random.choice(list_of_alphabet)).upper())
else:
result_string_list.append(base_uuid.upper())
result_string = "".join(result_string_list)
return f"{validation_type.upper()}{result_string}"

View File

@ -1,4 +1,4 @@
FROM node:18-alpine
FROM node:23-alpine
WORKDIR /
@ -6,7 +6,7 @@ WORKDIR /
COPY /WebServices/client-frontend/package*.json ./WebServices/client-frontend/
# Install dependencies
RUN cd ./WebServices/client-frontend && npm install
RUN cd ./WebServices/client-frontend && npm install --legacy-peer-deps
# Copy the rest of the application
COPY /WebServices/client-frontend ./WebServices/client-frontend

View File

@ -0,0 +1,21 @@
{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "new-york",
"rsc": true,
"tsx": true,
"tailwind": {
"config": "",
"css": "src/app/globals.css",
"baseColor": "gray",
"cssVariables": true,
"prefix": ""
},
"aliases": {
"components": "@/components",
"utils": "@/lib/utils",
"ui": "@/components/ui",
"lib": "@/lib",
"hooks": "@/hooks"
},
"iconLibrary": "lucide"
}

View File

@ -9,14 +9,24 @@
"version": "0.1.0",
"dependencies": {
"@hookform/resolvers": "^5.0.1",
"@radix-ui/react-checkbox": "^1.1.5",
"@radix-ui/react-label": "^2.1.3",
"@radix-ui/react-popover": "^1.1.7",
"@radix-ui/react-slot": "^1.2.0",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"date-fns": "^4.1.0",
"flatpickr": "^4.6.13",
"lucide-react": "^0.487.0",
"next": "15.2.4",
"next-crypto": "^1.0.8",
"react": "^19.0.0",
"react-day-picker": "^8.10.1",
"react-dom": "^19.0.0",
"react-hook-form": "^7.55.0",
"sonner": "^2.0.3",
"tailwind-merge": "^3.2.0",
"tw-animate-css": "^1.2.5",
"zod": "^3.24.2"
},
"devDependencies": {
@ -49,6 +59,40 @@
"tslib": "^2.4.0"
}
},
"node_modules/@floating-ui/core": {
"version": "1.6.9",
"resolved": "https://registry.npmjs.org/@floating-ui/core/-/core-1.6.9.tgz",
"integrity": "sha512-uMXCuQ3BItDUbAMhIXw7UPXRfAlOAvZzdK9BWpE60MCn+Svt3aLn9jsPTi/WNGlRUu2uI0v5S7JiIUsbsvh3fw==",
"dependencies": {
"@floating-ui/utils": "^0.2.9"
}
},
"node_modules/@floating-ui/dom": {
"version": "1.6.13",
"resolved": "https://registry.npmjs.org/@floating-ui/dom/-/dom-1.6.13.tgz",
"integrity": "sha512-umqzocjDgNRGTuO7Q8CU32dkHkECqI8ZdMZ5Swb6QAM0t5rnlrN3lGo1hdpscRd3WS8T6DKYK4ephgIH9iRh3w==",
"dependencies": {
"@floating-ui/core": "^1.6.0",
"@floating-ui/utils": "^0.2.9"
}
},
"node_modules/@floating-ui/react-dom": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/@floating-ui/react-dom/-/react-dom-2.1.2.tgz",
"integrity": "sha512-06okr5cgPzMNBy+Ycse2A6udMi4bqwW/zgBF/rwjcNqWkyr82Mcg8b0vjX8OJpZFy/FKjJmw6wV7t44kK6kW7A==",
"dependencies": {
"@floating-ui/dom": "^1.0.0"
},
"peerDependencies": {
"react": ">=16.8.0",
"react-dom": ">=16.8.0"
}
},
"node_modules/@floating-ui/utils": {
"version": "0.2.9",
"resolved": "https://registry.npmjs.org/@floating-ui/utils/-/utils-0.2.9.tgz",
"integrity": "sha512-MDWhGtE+eHw5JW7lq4qhc5yRLS11ERl1c7Z6Xd0a58DozHES6EnNNwUWbMiG4J9Cgj053Bhk8zvlhFYKVhULwg=="
},
"node_modules/@hookform/resolvers": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/@hookform/resolvers/-/resolvers-5.0.1.tgz",
@ -527,6 +571,460 @@
"node": ">= 10"
}
},
"node_modules/@radix-ui/primitive": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/@radix-ui/primitive/-/primitive-1.1.2.tgz",
"integrity": "sha512-XnbHrrprsNqZKQhStrSwgRUQzoCI1glLzdw79xiZPoofhGICeZRSQ3dIxAKH1gb3OHfNf4d6f+vAv3kil2eggA=="
},
"node_modules/@radix-ui/react-arrow": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/@radix-ui/react-arrow/-/react-arrow-1.1.3.tgz",
"integrity": "sha512-2dvVU4jva0qkNZH6HHWuSz5FN5GeU5tymvCgutF8WaXz9WnD1NgUhy73cqzkjkN4Zkn8lfTPv5JIfrC221W+Nw==",
"dependencies": {
"@radix-ui/react-primitive": "2.0.3"
},
"peerDependencies": {
"@types/react": "*",
"@types/react-dom": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
},
"@types/react-dom": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-checkbox": {
"version": "1.1.5",
"resolved": "https://registry.npmjs.org/@radix-ui/react-checkbox/-/react-checkbox-1.1.5.tgz",
"integrity": "sha512-B0gYIVxl77KYDR25AY9EGe/G//ef85RVBIxQvK+m5pxAC7XihAc/8leMHhDvjvhDu02SBSb6BuytlWr/G7F3+g==",
"dependencies": {
"@radix-ui/primitive": "1.1.2",
"@radix-ui/react-compose-refs": "1.1.2",
"@radix-ui/react-context": "1.1.2",
"@radix-ui/react-presence": "1.1.3",
"@radix-ui/react-primitive": "2.0.3",
"@radix-ui/react-use-controllable-state": "1.1.1",
"@radix-ui/react-use-previous": "1.1.1",
"@radix-ui/react-use-size": "1.1.1"
},
"peerDependencies": {
"@types/react": "*",
"@types/react-dom": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
},
"@types/react-dom": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-compose-refs": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/@radix-ui/react-compose-refs/-/react-compose-refs-1.1.2.tgz",
"integrity": "sha512-z4eqJvfiNnFMHIIvXP3CY57y2WJs5g2v3X0zm9mEJkrkNv4rDxu+sg9Jh8EkXyeqBkB7SOcboo9dMVqhyrACIg==",
"peerDependencies": {
"@types/react": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-context": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/@radix-ui/react-context/-/react-context-1.1.2.tgz",
"integrity": "sha512-jCi/QKUM2r1Ju5a3J64TH2A5SpKAgh0LpknyqdQ4m6DCV0xJ2HG1xARRwNGPQfi1SLdLWZ1OJz6F4OMBBNiGJA==",
"peerDependencies": {
"@types/react": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-dismissable-layer": {
"version": "1.1.6",
"resolved": "https://registry.npmjs.org/@radix-ui/react-dismissable-layer/-/react-dismissable-layer-1.1.6.tgz",
"integrity": "sha512-7gpgMT2gyKym9Jz2ZhlRXSg2y6cNQIK8d/cqBZ0RBCaps8pFryCWXiUKI+uHGFrhMrbGUP7U6PWgiXzIxoyF3Q==",
"dependencies": {
"@radix-ui/primitive": "1.1.2",
"@radix-ui/react-compose-refs": "1.1.2",
"@radix-ui/react-primitive": "2.0.3",
"@radix-ui/react-use-callback-ref": "1.1.1",
"@radix-ui/react-use-escape-keydown": "1.1.1"
},
"peerDependencies": {
"@types/react": "*",
"@types/react-dom": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
},
"@types/react-dom": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-focus-guards": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/@radix-ui/react-focus-guards/-/react-focus-guards-1.1.2.tgz",
"integrity": "sha512-fyjAACV62oPV925xFCrH8DR5xWhg9KYtJT4s3u54jxp+L/hbpTY2kIeEFFbFe+a/HCE94zGQMZLIpVTPVZDhaA==",
"peerDependencies": {
"@types/react": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-focus-scope": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/@radix-ui/react-focus-scope/-/react-focus-scope-1.1.3.tgz",
"integrity": "sha512-4XaDlq0bPt7oJwR+0k0clCiCO/7lO7NKZTAaJBYxDNQT/vj4ig0/UvctrRscZaFREpRvUTkpKR96ov1e6jptQg==",
"dependencies": {
"@radix-ui/react-compose-refs": "1.1.2",
"@radix-ui/react-primitive": "2.0.3",
"@radix-ui/react-use-callback-ref": "1.1.1"
},
"peerDependencies": {
"@types/react": "*",
"@types/react-dom": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
},
"@types/react-dom": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-id": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@radix-ui/react-id/-/react-id-1.1.1.tgz",
"integrity": "sha512-kGkGegYIdQsOb4XjsfM97rXsiHaBwco+hFI66oO4s9LU+PLAC5oJ7khdOVFxkhsmlbpUqDAvXw11CluXP+jkHg==",
"dependencies": {
"@radix-ui/react-use-layout-effect": "1.1.1"
},
"peerDependencies": {
"@types/react": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-label": {
"version": "2.1.3",
"resolved": "https://registry.npmjs.org/@radix-ui/react-label/-/react-label-2.1.3.tgz",
"integrity": "sha512-zwSQ1NzSKG95yA0tvBMgv6XPHoqapJCcg9nsUBaQQ66iRBhZNhlpaQG2ERYYX4O4stkYFK5rxj5NsWfO9CS+Hg==",
"dependencies": {
"@radix-ui/react-primitive": "2.0.3"
},
"peerDependencies": {
"@types/react": "*",
"@types/react-dom": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
},
"@types/react-dom": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-popover": {
"version": "1.1.7",
"resolved": "https://registry.npmjs.org/@radix-ui/react-popover/-/react-popover-1.1.7.tgz",
"integrity": "sha512-I38OYWDmJF2kbO74LX8UsFydSHWOJuQ7LxPnTefjxxvdvPLempvAnmsyX9UsBlywcbSGpRH7oMLfkUf+ij4nrw==",
"dependencies": {
"@radix-ui/primitive": "1.1.2",
"@radix-ui/react-compose-refs": "1.1.2",
"@radix-ui/react-context": "1.1.2",
"@radix-ui/react-dismissable-layer": "1.1.6",
"@radix-ui/react-focus-guards": "1.1.2",
"@radix-ui/react-focus-scope": "1.1.3",
"@radix-ui/react-id": "1.1.1",
"@radix-ui/react-popper": "1.2.3",
"@radix-ui/react-portal": "1.1.5",
"@radix-ui/react-presence": "1.1.3",
"@radix-ui/react-primitive": "2.0.3",
"@radix-ui/react-slot": "1.2.0",
"@radix-ui/react-use-controllable-state": "1.1.1",
"aria-hidden": "^1.2.4",
"react-remove-scroll": "^2.6.3"
},
"peerDependencies": {
"@types/react": "*",
"@types/react-dom": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
},
"@types/react-dom": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-popper": {
"version": "1.2.3",
"resolved": "https://registry.npmjs.org/@radix-ui/react-popper/-/react-popper-1.2.3.tgz",
"integrity": "sha512-iNb9LYUMkne9zIahukgQmHlSBp9XWGeQQ7FvUGNk45ywzOb6kQa+Ca38OphXlWDiKvyneo9S+KSJsLfLt8812A==",
"dependencies": {
"@floating-ui/react-dom": "^2.0.0",
"@radix-ui/react-arrow": "1.1.3",
"@radix-ui/react-compose-refs": "1.1.2",
"@radix-ui/react-context": "1.1.2",
"@radix-ui/react-primitive": "2.0.3",
"@radix-ui/react-use-callback-ref": "1.1.1",
"@radix-ui/react-use-layout-effect": "1.1.1",
"@radix-ui/react-use-rect": "1.1.1",
"@radix-ui/react-use-size": "1.1.1",
"@radix-ui/rect": "1.1.1"
},
"peerDependencies": {
"@types/react": "*",
"@types/react-dom": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
},
"@types/react-dom": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-portal": {
"version": "1.1.5",
"resolved": "https://registry.npmjs.org/@radix-ui/react-portal/-/react-portal-1.1.5.tgz",
"integrity": "sha512-ps/67ZqsFm+Mb6lSPJpfhRLrVL2i2fntgCmGMqqth4eaGUf+knAuuRtWVJrNjUhExgmdRqftSgzpf0DF0n6yXA==",
"dependencies": {
"@radix-ui/react-primitive": "2.0.3",
"@radix-ui/react-use-layout-effect": "1.1.1"
},
"peerDependencies": {
"@types/react": "*",
"@types/react-dom": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
},
"@types/react-dom": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-presence": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/@radix-ui/react-presence/-/react-presence-1.1.3.tgz",
"integrity": "sha512-IrVLIhskYhH3nLvtcBLQFZr61tBG7wx7O3kEmdzcYwRGAEBmBicGGL7ATzNgruYJ3xBTbuzEEq9OXJM3PAX3tA==",
"dependencies": {
"@radix-ui/react-compose-refs": "1.1.2",
"@radix-ui/react-use-layout-effect": "1.1.1"
},
"peerDependencies": {
"@types/react": "*",
"@types/react-dom": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
},
"@types/react-dom": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-primitive": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/@radix-ui/react-primitive/-/react-primitive-2.0.3.tgz",
"integrity": "sha512-Pf/t/GkndH7CQ8wE2hbkXA+WyZ83fhQQn5DDmwDiDo6AwN/fhaH8oqZ0jRjMrO2iaMhDi6P1HRx6AZwyMinY1g==",
"dependencies": {
"@radix-ui/react-slot": "1.2.0"
},
"peerDependencies": {
"@types/react": "*",
"@types/react-dom": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
},
"@types/react-dom": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-slot": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/@radix-ui/react-slot/-/react-slot-1.2.0.tgz",
"integrity": "sha512-ujc+V6r0HNDviYqIK3rW4ffgYiZ8g5DEHrGJVk4x7kTlLXRDILnKX9vAUYeIsLOoDpDJ0ujpqMkjH4w2ofuo6w==",
"dependencies": {
"@radix-ui/react-compose-refs": "1.1.2"
},
"peerDependencies": {
"@types/react": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-use-callback-ref": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@radix-ui/react-use-callback-ref/-/react-use-callback-ref-1.1.1.tgz",
"integrity": "sha512-FkBMwD+qbGQeMu1cOHnuGB6x4yzPjho8ap5WtbEJ26umhgqVXbhekKUQO+hZEL1vU92a3wHwdp0HAcqAUF5iDg==",
"peerDependencies": {
"@types/react": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-use-controllable-state": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@radix-ui/react-use-controllable-state/-/react-use-controllable-state-1.1.1.tgz",
"integrity": "sha512-YnEXIy8/ga01Y1PN0VfaNH//MhA91JlEGVBDxDzROqwrAtG5Yr2QGEPz8A/rJA3C7ZAHryOYGaUv8fLSW2H/mg==",
"dependencies": {
"@radix-ui/react-use-callback-ref": "1.1.1"
},
"peerDependencies": {
"@types/react": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-use-escape-keydown": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@radix-ui/react-use-escape-keydown/-/react-use-escape-keydown-1.1.1.tgz",
"integrity": "sha512-Il0+boE7w/XebUHyBjroE+DbByORGR9KKmITzbR7MyQ4akpORYP/ZmbhAr0DG7RmmBqoOnZdy2QlvajJ2QA59g==",
"dependencies": {
"@radix-ui/react-use-callback-ref": "1.1.1"
},
"peerDependencies": {
"@types/react": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-use-layout-effect": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@radix-ui/react-use-layout-effect/-/react-use-layout-effect-1.1.1.tgz",
"integrity": "sha512-RbJRS4UWQFkzHTTwVymMTUv8EqYhOp8dOOviLj2ugtTiXRaRQS7GLGxZTLL1jWhMeoSCf5zmcZkqTl9IiYfXcQ==",
"peerDependencies": {
"@types/react": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-use-previous": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@radix-ui/react-use-previous/-/react-use-previous-1.1.1.tgz",
"integrity": "sha512-2dHfToCj/pzca2Ck724OZ5L0EVrr3eHRNsG/b3xQJLA2hZpVCS99bLAX+hm1IHXDEnzU6by5z/5MIY794/a8NQ==",
"peerDependencies": {
"@types/react": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-use-rect": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@radix-ui/react-use-rect/-/react-use-rect-1.1.1.tgz",
"integrity": "sha512-QTYuDesS0VtuHNNvMh+CjlKJ4LJickCMUAqjlE3+j8w+RlRpwyX3apEQKGFzbZGdo7XNG1tXa+bQqIE7HIXT2w==",
"dependencies": {
"@radix-ui/rect": "1.1.1"
},
"peerDependencies": {
"@types/react": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-use-size": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@radix-ui/react-use-size/-/react-use-size-1.1.1.tgz",
"integrity": "sha512-ewrXRDTAqAXlkl6t/fkXWNAhFX9I+CkKlw6zjEwk86RSPKwZr3xpBRso655aqYafwtnbpHLj6toFzmd6xdVptQ==",
"dependencies": {
"@radix-ui/react-use-layout-effect": "1.1.1"
},
"peerDependencies": {
"@types/react": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/@radix-ui/rect": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@radix-ui/rect/-/rect-1.1.1.tgz",
"integrity": "sha512-HPwpGIzkl28mWyZqG52jiqDJ12waP11Pa1lGoiyUkIEuMLBP0oeK/C89esbXrxsky5we7dfd8U58nm0SgAWpVw=="
},
"node_modules/@standard-schema/utils": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/@standard-schema/utils/-/utils-0.3.0.tgz",
@ -795,6 +1293,17 @@
"@types/react": "^19.0.0"
}
},
"node_modules/aria-hidden": {
"version": "1.2.4",
"resolved": "https://registry.npmjs.org/aria-hidden/-/aria-hidden-1.2.4.tgz",
"integrity": "sha512-y+CcFFwelSXpLZk/7fMB2mUbGtX9lKycf1MWJ7CaTIERyitVlyQx6C+sxcROU2BAJ24OiZyK+8wj2i8AlBoS3A==",
"dependencies": {
"tslib": "^2.0.0"
},
"engines": {
"node": ">=10"
}
},
"node_modules/busboy": {
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/busboy/-/busboy-1.6.0.tgz",
@ -825,11 +1334,30 @@
}
]
},
"node_modules/class-variance-authority": {
"version": "0.7.1",
"resolved": "https://registry.npmjs.org/class-variance-authority/-/class-variance-authority-0.7.1.tgz",
"integrity": "sha512-Ka+9Trutv7G8M6WT6SeiRWz792K5qEqIGEGzXKhAE6xOWAY6pPH8U+9IY3oCMv6kqTmLsv7Xh/2w2RigkePMsg==",
"dependencies": {
"clsx": "^2.1.1"
},
"funding": {
"url": "https://polar.sh/cva"
}
},
"node_modules/client-only": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/client-only/-/client-only-0.0.1.tgz",
"integrity": "sha512-IV3Ou0jSMzZrd3pZ48nLkT9DA7Ag1pnPzaiQhpW7c3RbcqqzvzzVu+L8gfqMp/8IM2MQtSiqaCxrrcfu8I8rMA=="
},
"node_modules/clsx": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/clsx/-/clsx-2.1.1.tgz",
"integrity": "sha512-eYm0QWBtUrBWZWG0d386OGAw16Z995PiOVo2B7bjWSbHedGl5e0ZWaq65kOGgUSNesEIDkB9ISbTg/JK9dhCZA==",
"engines": {
"node": ">=6"
}
},
"node_modules/color": {
"version": "4.2.3",
"resolved": "https://registry.npmjs.org/color/-/color-4.2.3.tgz",
@ -877,6 +1405,15 @@
"integrity": "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==",
"dev": true
},
"node_modules/date-fns": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/date-fns/-/date-fns-4.1.0.tgz",
"integrity": "sha512-Ukq0owbQXxa/U3EGtsdVBkR1w7KOQ5gIBqdH2hkvknzZPYvBxb/aa6E8L7tmjFtkwZBu3UXBbjIgPo/Ez4xaNg==",
"funding": {
"type": "github",
"url": "https://github.com/sponsors/kossnocorp"
}
},
"node_modules/detect-libc": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.3.tgz",
@ -886,6 +1423,11 @@
"node": ">=8"
}
},
"node_modules/detect-node-es": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/detect-node-es/-/detect-node-es-1.1.0.tgz",
"integrity": "sha512-ypdmJU/TbBby2Dxibuv7ZLW3Bs1QEmM7nHjEANfohJLvE0XVujisn1qPJcZxg+qDucsr+bP6fLD1rPS3AhJ7EQ=="
},
"node_modules/enhanced-resolve": {
"version": "5.18.1",
"resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.18.1.tgz",
@ -904,6 +1446,14 @@
"resolved": "https://registry.npmjs.org/flatpickr/-/flatpickr-4.6.13.tgz",
"integrity": "sha512-97PMG/aywoYpB4IvbvUJi0RQi8vearvU0oov1WW3k0WZPBMrTQVqekSX5CjSG/M4Q3i6A/0FKXC7RyAoAUUSPw=="
},
"node_modules/get-nonce": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/get-nonce/-/get-nonce-1.0.1.tgz",
"integrity": "sha512-FJhYRoDaiatfEkUK8HKlicmu/3SGFD51q3itKDGoSTysQJBnfOcxU5GxnhE1E6soB76MbT0MBtnKJuXyAx+96Q==",
"engines": {
"node": ">=6"
}
},
"node_modules/graceful-fs": {
"version": "4.2.11",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz",
@ -1304,6 +1854,19 @@
"node": ">=0.10.0"
}
},
"node_modules/react-day-picker": {
"version": "8.10.1",
"resolved": "https://registry.npmjs.org/react-day-picker/-/react-day-picker-8.10.1.tgz",
"integrity": "sha512-TMx7fNbhLk15eqcMt+7Z7S2KF7mfTId/XJDjKE8f+IUcFn0l08/kI4FiYTL/0yuOLmEcbR4Fwe3GJf/NiiMnPA==",
"funding": {
"type": "individual",
"url": "https://github.com/sponsors/gpbl"
},
"peerDependencies": {
"date-fns": "^2.28.0 || ^3.0.0",
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
}
},
"node_modules/react-dom": {
"version": "19.1.0",
"resolved": "https://registry.npmjs.org/react-dom/-/react-dom-19.1.0.tgz",
@ -1330,6 +1893,72 @@
"react": "^16.8.0 || ^17 || ^18 || ^19"
}
},
"node_modules/react-remove-scroll": {
"version": "2.6.3",
"resolved": "https://registry.npmjs.org/react-remove-scroll/-/react-remove-scroll-2.6.3.tgz",
"integrity": "sha512-pnAi91oOk8g8ABQKGF5/M9qxmmOPxaAnopyTHYfqYEwJhyFrbbBtHuSgtKEoH0jpcxx5o3hXqH1mNd9/Oi+8iQ==",
"dependencies": {
"react-remove-scroll-bar": "^2.3.7",
"react-style-singleton": "^2.2.3",
"tslib": "^2.1.0",
"use-callback-ref": "^1.3.3",
"use-sidecar": "^1.1.3"
},
"engines": {
"node": ">=10"
},
"peerDependencies": {
"@types/react": "*",
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/react-remove-scroll-bar": {
"version": "2.3.8",
"resolved": "https://registry.npmjs.org/react-remove-scroll-bar/-/react-remove-scroll-bar-2.3.8.tgz",
"integrity": "sha512-9r+yi9+mgU33AKcj6IbT9oRCO78WriSj6t/cF8DWBZJ9aOGPOTEDvdUDz1FwKim7QXWwmHqtdHnRJfhAxEG46Q==",
"dependencies": {
"react-style-singleton": "^2.2.2",
"tslib": "^2.0.0"
},
"engines": {
"node": ">=10"
},
"peerDependencies": {
"@types/react": "*",
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/react-style-singleton": {
"version": "2.2.3",
"resolved": "https://registry.npmjs.org/react-style-singleton/-/react-style-singleton-2.2.3.tgz",
"integrity": "sha512-b6jSvxvVnyptAiLjbkWLE/lOnR4lfTtDAl+eUC7RZy+QQWc6wRzIV2CE6xBuMmDxc2qIihtDCZD5NPOFl7fRBQ==",
"dependencies": {
"get-nonce": "^1.0.0",
"tslib": "^2.0.0"
},
"engines": {
"node": ">=10"
},
"peerDependencies": {
"@types/react": "*",
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/scheduler": {
"version": "0.26.0",
"resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.26.0.tgz",
@ -1442,6 +2071,15 @@
}
}
},
"node_modules/tailwind-merge": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/tailwind-merge/-/tailwind-merge-3.2.0.tgz",
"integrity": "sha512-FQT/OVqCD+7edmmJpsgCsY820RTD5AkBryuG5IUqR5YQZSdj5xlH5nLgH7YPths7WsLPSpSBNneJdM8aS8aeFA==",
"funding": {
"type": "github",
"url": "https://github.com/sponsors/dcastil"
}
},
"node_modules/tailwindcss": {
"version": "4.1.3",
"resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-4.1.3.tgz",
@ -1462,6 +2100,14 @@
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz",
"integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w=="
},
"node_modules/tw-animate-css": {
"version": "1.2.5",
"resolved": "https://registry.npmjs.org/tw-animate-css/-/tw-animate-css-1.2.5.tgz",
"integrity": "sha512-ABzjfgVo+fDbhRREGL4KQZUqqdPgvc5zVrLyeW9/6mVqvaDepXc7EvedA+pYmMnIOsUAQMwcWzNvom26J2qYvQ==",
"funding": {
"url": "https://github.com/sponsors/Wombosvideo"
}
},
"node_modules/typescript": {
"version": "5.8.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.8.3.tgz",
@ -1481,6 +2127,47 @@
"integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==",
"dev": true
},
"node_modules/use-callback-ref": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/use-callback-ref/-/use-callback-ref-1.3.3.tgz",
"integrity": "sha512-jQL3lRnocaFtu3V00JToYz/4QkNWswxijDaCVNZRiRTO3HQDLsdu1ZtmIUvV4yPp+rvWm5j0y0TG/S61cuijTg==",
"dependencies": {
"tslib": "^2.0.0"
},
"engines": {
"node": ">=10"
},
"peerDependencies": {
"@types/react": "*",
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/use-sidecar": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/use-sidecar/-/use-sidecar-1.1.3.tgz",
"integrity": "sha512-Fedw0aZvkhynoPYlA5WXrMCAMm+nSWdZt6lzJQ7Ok8S6Q+VsHmHpRWndVRJ8Be0ZbkfPc5LRYH+5XrzXcEeLRQ==",
"dependencies": {
"detect-node-es": "^1.1.0",
"tslib": "^2.0.0"
},
"engines": {
"node": ">=10"
},
"peerDependencies": {
"@types/react": "*",
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/zod": {
"version": "3.24.2",
"resolved": "https://registry.npmjs.org/zod/-/zod-3.24.2.tgz",

View File

@ -10,14 +10,24 @@
},
"dependencies": {
"@hookform/resolvers": "^5.0.1",
"@radix-ui/react-checkbox": "^1.1.5",
"@radix-ui/react-label": "^2.1.3",
"@radix-ui/react-popover": "^1.1.7",
"@radix-ui/react-slot": "^1.2.0",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"date-fns": "^4.1.0",
"flatpickr": "^4.6.13",
"lucide-react": "^0.487.0",
"next": "15.2.4",
"next-crypto": "^1.0.8",
"react": "^19.0.0",
"react-day-picker": "^8.10.1",
"react-dom": "^19.0.0",
"react-hook-form": "^7.55.0",
"sonner": "^2.0.3",
"tailwind-merge": "^3.2.0",
"tw-animate-css": "^1.2.5",
"zod": "^3.24.2"
},
"devDependencies": {

View File

@ -17,8 +17,8 @@ export default async function DashLayout({
redirect("/auth/login");
}
return (
<div className="min-h-screen min-w-screen flex h-screen w-screen overflow-hidden">
{children}
<div className="h-screen w-full">
<div className="h-full w-full overflow-y-auto">{children}</div>
</div>
);
}

View File

@ -1,26 +1,122 @@
@import "tailwindcss";
@import "tw-animate-css";
:root {
--background: #ffffff;
--foreground: #171717;
}
@custom-variant dark (&:is(.dark *));
@theme inline {
--color-background: var(--background);
--color-foreground: var(--foreground);
--font-sans: var(--font-geist-sans);
--font-mono: var(--font-geist-mono);
--color-sidebar-ring: var(--sidebar-ring);
--color-sidebar-border: var(--sidebar-border);
--color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
--color-sidebar-accent: var(--sidebar-accent);
--color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
--color-sidebar-primary: var(--sidebar-primary);
--color-sidebar-foreground: var(--sidebar-foreground);
--color-sidebar: var(--sidebar);
--color-chart-5: var(--chart-5);
--color-chart-4: var(--chart-4);
--color-chart-3: var(--chart-3);
--color-chart-2: var(--chart-2);
--color-chart-1: var(--chart-1);
--color-ring: var(--ring);
--color-input: var(--input);
--color-border: var(--border);
--color-destructive: var(--destructive);
--color-accent-foreground: var(--accent-foreground);
--color-accent: var(--accent);
--color-muted-foreground: var(--muted-foreground);
--color-muted: var(--muted);
--color-secondary-foreground: var(--secondary-foreground);
--color-secondary: var(--secondary);
--color-primary-foreground: var(--primary-foreground);
--color-primary: var(--primary);
--color-popover-foreground: var(--popover-foreground);
--color-popover: var(--popover);
--color-card-foreground: var(--card-foreground);
--color-card: var(--card);
--radius-sm: calc(var(--radius) - 4px);
--radius-md: calc(var(--radius) - 2px);
--radius-lg: var(--radius);
--radius-xl: calc(var(--radius) + 4px);
}
@media (prefers-color-scheme: dark) {
:root {
--background: #0a0a0a;
--foreground: #ededed;
:root {
--radius: 0.625rem;
--background: oklch(1 0 0);
--foreground: oklch(0.13 0.028 261.692);
--card: oklch(1 0 0);
--card-foreground: oklch(0.13 0.028 261.692);
--popover: oklch(1 0 0);
--popover-foreground: oklch(0.13 0.028 261.692);
--primary: oklch(0.21 0.034 264.665);
--primary-foreground: oklch(0.985 0.002 247.839);
--secondary: oklch(0.967 0.003 264.542);
--secondary-foreground: oklch(0.21 0.034 264.665);
--muted: oklch(0.967 0.003 264.542);
--muted-foreground: oklch(0.551 0.027 264.364);
--accent: oklch(0.967 0.003 264.542);
--accent-foreground: oklch(0.21 0.034 264.665);
--destructive: oklch(0.577 0.245 27.325);
--border: oklch(0.928 0.006 264.531);
--input: oklch(0.928 0.006 264.531);
--ring: oklch(0.707 0.022 261.325);
--chart-1: oklch(0.646 0.222 41.116);
--chart-2: oklch(0.6 0.118 184.704);
--chart-3: oklch(0.398 0.07 227.392);
--chart-4: oklch(0.828 0.189 84.429);
--chart-5: oklch(0.769 0.188 70.08);
--sidebar: oklch(0.985 0.002 247.839);
--sidebar-foreground: oklch(0.13 0.028 261.692);
--sidebar-primary: oklch(0.21 0.034 264.665);
--sidebar-primary-foreground: oklch(0.985 0.002 247.839);
--sidebar-accent: oklch(0.967 0.003 264.542);
--sidebar-accent-foreground: oklch(0.21 0.034 264.665);
--sidebar-border: oklch(0.928 0.006 264.531);
--sidebar-ring: oklch(0.707 0.022 261.325);
}
.dark {
--background: oklch(0.13 0.028 261.692);
--foreground: oklch(0.985 0.002 247.839);
--card: oklch(0.21 0.034 264.665);
--card-foreground: oklch(0.985 0.002 247.839);
--popover: oklch(0.21 0.034 264.665);
--popover-foreground: oklch(0.985 0.002 247.839);
--primary: oklch(0.928 0.006 264.531);
--primary-foreground: oklch(0.21 0.034 264.665);
--secondary: oklch(0.278 0.033 256.848);
--secondary-foreground: oklch(0.985 0.002 247.839);
--muted: oklch(0.278 0.033 256.848);
--muted-foreground: oklch(0.707 0.022 261.325);
--accent: oklch(0.278 0.033 256.848);
--accent-foreground: oklch(0.985 0.002 247.839);
--destructive: oklch(0.704 0.191 22.216);
--border: oklch(1 0 0 / 10%);
--input: oklch(1 0 0 / 15%);
--ring: oklch(0.551 0.027 264.364);
--chart-1: oklch(0.488 0.243 264.376);
--chart-2: oklch(0.696 0.17 162.48);
--chart-3: oklch(0.769 0.188 70.08);
--chart-4: oklch(0.627 0.265 303.9);
--chart-5: oklch(0.645 0.246 16.439);
--sidebar: oklch(0.21 0.034 264.665);
--sidebar-foreground: oklch(0.985 0.002 247.839);
--sidebar-primary: oklch(0.488 0.243 264.376);
--sidebar-primary-foreground: oklch(0.985 0.002 247.839);
--sidebar-accent: oklch(0.278 0.033 256.848);
--sidebar-accent-foreground: oklch(0.985 0.002 247.839);
--sidebar-border: oklch(1 0 0 / 10%);
--sidebar-ring: oklch(0.551 0.027 264.364);
}
@layer base {
* {
@apply border-border outline-ring/50;
}
body {
@apply bg-background text-foreground;
}
}
body {
background: var(--background);
color: var(--foreground);
font-family: Arial, Helvetica, sans-serif;
}

View File

@ -1,6 +1,6 @@
"use client";
import React from "react";
import { Pencil, Plus } from "lucide-react";
import { Pencil, Plus, ScanSearch } from "lucide-react";
// Define types
interface CardData {
@ -43,11 +43,11 @@ const mockData: CardData[] = [
// Card component
const Card: React.FC<CardProps> = ({ data, onUpdate }) => (
<div className="bg-white rounded-lg shadow-md p-6 mb-4 hover:shadow-lg transition-shadow">
<div className="bg-white text-black rounded-lg shadow-md p-6 mb-4 hover:shadow-lg transition-shadow">
<div className="flex justify-between items-start">
<div>
<h3 className="text-xl font-semibold mb-2">{data.title}</h3>
<p className="text-gray-600 mb-2">{data.description}</p>
<p className="mb-2">{data.description}</p>
<div className="flex items-center gap-4">
<span className="text-sm text-gray-500">Status: {data.status}</span>
<span className="text-sm text-gray-500">
@ -60,13 +60,23 @@ const Card: React.FC<CardProps> = ({ data, onUpdate }) => (
className="text-blue-500 hover:text-blue-700 p-2"
aria-label="Update"
>
<Pencil />
<div className="flex flex-col">
<div>
<Pencil />
</div>
<div className="mt-5">
<ScanSearch />
</div>
</div>
</button>
</div>
</div>
);
function app000002() {
const [modifyEnable, setModifyEnable] = React.useState(false);
const [selectedId, setSelectedId] = React.useState<number | null>(null);
const handleUpdate = (id: number) => {
console.log(`Update clicked for item ${id}`);
// Add your update logic here
@ -89,12 +99,30 @@ function app000002() {
Create New
</button>
</div>
<div className="grid gap-4">
{mockData.map((item) => (
<Card key={item.id} data={item} onUpdate={handleUpdate} />
))}
</div>
{!selectedId ? (
<div className="grid gap-4">
{mockData.map((item) => (
<Card
key={item.id}
data={item}
onUpdate={() => setSelectedId(item.id)}
/>
))}
</div>
) : (
<>
<div
key={selectedId}
className="flex min-h-full justify-between items-center mb-6"
>
<input
type="text"
className="border border-gray-300 rounded-lg p-2 w-full"
placeholder="Enter new title"
/>
</div>
</>
)}
</div>
);
}

View File

@ -1,7 +1,100 @@
import React from "react";
"use client";
import React, { useEffect } from "react";
import buildingsMockData from "./mock-data";
import { BuildingFormData } from "../Pages/build/buildschema1";
import BuildPageForm1 from "../Pages/build/buildform1";
import BuildPage1 from "../Pages/build/buildpage1";
import BuildInfo1 from "../Pages/build/buildinfo1";
function app000003() {
return <div>app000003</div>;
const [modifyEnable, setModifyEnable] = React.useState<boolean | null>(false);
const [isCreate, setIsCreate] = React.useState<boolean | null>(false);
const [selectedId, setSelectedId] = React.useState<string | null>(null);
const [tableData, setTableData] = React.useState<BuildingFormData[]>([]);
const fecthData = async ({
// Add any parameters if needed
page = 1,
pageSize = 10,
orderBy = "asc",
orderType = "name",
query = {},
}) => {
// Simulate an API call
const response = await new Promise((resolve) =>
setTimeout(() => resolve(buildingsMockData), 1000)
);
setTableData(response as BuildingFormData[]);
};
// Fetch data when the component mounts
useEffect(() => {
fecthData({
page: 1,
pageSize: 10,
orderBy: "asc",
orderType: "uu_id",
query: {},
});
}, []);
const onSubmit = (data: BuildingFormData) => {
console.log("Form data:", data);
// Submit to API or do other operations
};
const handleUpdateModify = (uuid: string) => {
setSelectedId(uuid);
setModifyEnable(false);
};
const handleView = (uuid: string) => {
setSelectedId(uuid);
setModifyEnable(true);
};
return (
<>
<div className="h-screen overflow-y-auto">
<BuildInfo1
data={tableData}
selectedId={selectedId}
setIsCreate={() => setIsCreate(true)}
/>
{!isCreate ? (
<div className="min-w-full mx-4 p-6 rounded-lg shadow-md ">
{!selectedId ? (
<BuildPage1
data={tableData}
handleUpdateModify={handleUpdateModify}
handleView={handleView}
/>
) : (
<BuildPageForm1
data={tableData.find((item) => item.uu_id === selectedId) || {}}
onSubmit={onSubmit}
modifyEnable={modifyEnable}
setSelectedId={() => setSelectedId(null)}
/>
)}
</div>
) : (
<>
<BuildPageForm1
data={{
build_date: new Date(),
decision_period_date: new Date(),
}}
onSubmit={onSubmit}
modifyEnable={modifyEnable}
setSelectedId={() => setIsCreate(null)}
/>
</>
)}
</div>
</>
);
}
export default app000003;

View File

@ -1,12 +1,14 @@
import React from "react";
import App000001 from "./app000001";
import App000002 from "./app000002";
import { PageProps } from "./interFaces";
export const PageIndexs = {
import App000001 from "./app000001";
import App000002 from "./app000002";
import app000003 from "./app000003";
export const PageIndex = {
app000001: App000001,
app000002: App000002,
app000003: app000003,
};
function UnAuthorizedPage({ lang, queryParams }: PageProps) {
@ -30,12 +32,8 @@ function UnAuthorizedPage({ lang, queryParams }: PageProps) {
);
}
export function retrievePage({
pageId,
}: {
pageId: string;
}): React.ComponentType<PageProps> {
const PageComponent = PageIndexs[pageId as keyof typeof PageIndexs];
export function retrievePage(pageId: string): React.ComponentType<PageProps> {
const PageComponent = PageIndex[pageId as keyof typeof PageIndex];
if (!PageComponent) {
return UnAuthorizedPage;
}

View File

@ -0,0 +1,215 @@
// Mock data for buildings table
const buildingsMockData = [
{
uu_id: "63192f8a-0b36-49b5-a058-423eb375ab1b",
gov_address_code: "GAC12345678",
build_name: "Sunset Towers",
build_no: "A123",
max_floor: 15,
underground_floor: 2,
build_date: "2010-05-12T00:00:00Z",
decision_period_date: "2024-03-15T00:00:00Z",
tax_no: "TX123456789012",
lift_count: 3,
heating_system: true,
cooling_system: true,
hot_water_system: true,
block_service_man_count: 2,
security_service_man_count: 1,
garage_count: 25,
site_uu_id: "site-uuid-6789abcd-1234",
address_uu_id: "addr-uuid-1234-5678-abcd",
build_types_uu_id: "type-uuid-residential-apt",
},
{
uu_id: "8149fcac-3ac8-4107-acce-ef52f378a874",
gov_address_code: "GAC23456789",
build_name: "Ocean View Plaza",
build_no: "B456",
max_floor: 22,
underground_floor: 3,
build_date: "2015-07-23T00:00:00Z",
decision_period_date: "2024-05-10T00:00:00Z",
tax_no: "TX234567890123",
lift_count: 5,
heating_system: true,
cooling_system: true,
hot_water_system: true,
block_service_man_count: 3,
security_service_man_count: 2,
garage_count: 50,
site_uu_id: "site-uuid-7890bcde-2345",
address_uu_id: "addr-uuid-2345-6789-bcde",
build_types_uu_id: "type-uuid-residential-condo",
},
{
uu_id: "10fb6ffe-610b-4e7e-bb5b-b46e0946cff7",
gov_address_code: "GAC34567890",
build_name: "Parkside Heights",
build_no: "C789",
max_floor: 8,
underground_floor: 1,
build_date: "2005-11-30T00:00:00Z",
decision_period_date: "2024-04-22T00:00:00Z",
tax_no: "TX345678901234",
lift_count: 2,
heating_system: true,
cooling_system: false,
hot_water_system: true,
block_service_man_count: 1,
security_service_man_count: 1,
garage_count: 16,
site_uu_id: "site-uuid-8901cdef-3456",
address_uu_id: "addr-uuid-3456-7890-cdef",
build_types_uu_id: "type-uuid-commercial-office",
},
{
uu_id: "0447123a-8992-4e22-ba86-2f0feaa763d2",
gov_address_code: "GAC45678901",
build_name: "Riverside Apartments",
build_no: "D012",
max_floor: 12,
underground_floor: 2,
build_date: "2018-03-17T00:00:00Z",
decision_period_date: "2024-02-28T00:00:00Z",
tax_no: "TX456789012345",
lift_count: 3,
heating_system: true,
cooling_system: true,
hot_water_system: false,
block_service_man_count: 2,
security_service_man_count: 1,
garage_count: 30,
site_uu_id: "site-uuid-9012defg-4567",
address_uu_id: "addr-uuid-4567-8901-defg",
build_types_uu_id: "type-uuid-residential-apt",
},
{
uu_id: "6682a927-abb7-4d33-b877-3df170c3679c",
gov_address_code: "GAC56789012",
build_name: "Mountain View Plaza",
build_no: "E345",
max_floor: 5,
underground_floor: 0,
build_date: "2000-09-05T00:00:00Z",
decision_period_date: "2024-01-15T00:00:00Z",
tax_no: "TX567890123456",
lift_count: 1,
heating_system: true,
cooling_system: false,
hot_water_system: false,
block_service_man_count: 1,
security_service_man_count: 0,
garage_count: 8,
site_uu_id: "site-uuid-0123efgh-5678",
address_uu_id: "addr-uuid-5678-9012-efgh",
build_types_uu_id: "type-uuid-mixed-use",
},
{
uu_id: "a06fef1b-3eb7-4aed-b901-47a171a12a93",
gov_address_code: "GAC67890123",
build_name: "City Center Tower",
build_no: "F678",
max_floor: 30,
underground_floor: 4,
build_date: "2020-01-10T00:00:00Z",
decision_period_date: "2024-06-30T00:00:00Z",
tax_no: "TX678901234567",
lift_count: 8,
heating_system: true,
cooling_system: true,
hot_water_system: true,
block_service_man_count: 4,
security_service_man_count: 3,
garage_count: 100,
site_uu_id: "site-uuid-1234fghi-6789",
address_uu_id: "addr-uuid-6789-0123-fghi",
build_types_uu_id: "type-uuid-commercial-skyscraper",
},
{
uu_id: "22be0407-f6a4-456e-a183-6641d2714d73",
gov_address_code: "GAC78901234",
build_name: "Garden Villas",
build_no: "G901",
max_floor: 3,
underground_floor: 0,
build_date: "2012-06-22T00:00:00Z",
decision_period_date: "2024-03-01T00:00:00Z",
tax_no: "TX789012345678",
lift_count: 0,
heating_system: true,
cooling_system: false,
hot_water_system: true,
block_service_man_count: 1,
security_service_man_count: 0,
garage_count: 6,
site_uu_id: "site-uuid-2345ghij-7890",
address_uu_id: "addr-uuid-7890-1234-ghij",
build_types_uu_id: "type-uuid-residential-townhouse",
},
{
uu_id: "7792645f-350c-4567-8a78-190014674e6b",
gov_address_code: "GAC89012345",
build_name: "Industrial Complex",
build_no: "H234",
max_floor: 2,
underground_floor: 1,
build_date: "2008-12-05T00:00:00Z",
decision_period_date: "2024-05-15T00:00:00Z",
tax_no: "TX890123456789",
lift_count: 1,
heating_system: true,
cooling_system: false,
hot_water_system: false,
block_service_man_count: 0,
security_service_man_count: 1,
garage_count: 12,
site_uu_id: "site-uuid-3456hijk-8901",
address_uu_id: "addr-uuid-8901-2345-hijk",
build_types_uu_id: "type-uuid-industrial",
},
{
uu_id: "8de7a620-3c1e-4925-8147-3eb33a2059cc",
gov_address_code: "GAC90123456",
build_name: "Hillside Residences",
build_no: "I567",
max_floor: 10,
underground_floor: 2,
build_date: "2017-04-18T00:00:00Z",
decision_period_date: "2024-02-10T00:00:00Z",
tax_no: "TX901234567890",
lift_count: 2,
heating_system: true,
cooling_system: true,
hot_water_system: true,
block_service_man_count: 2,
security_service_man_count: 1,
garage_count: 20,
site_uu_id: "site-uuid-4567ijkl-9012",
address_uu_id: "addr-uuid-9012-3456-ijkl",
build_types_uu_id: "type-uuid-residential-apt",
},
{
uu_id: "1a680003-d005-414c-86ab-f16e090aba25",
gov_address_code: "GACA0123456",
build_name: "Tech Hub Center",
build_no: "J890",
max_floor: 18,
underground_floor: 3,
build_date: "2019-08-30T00:00:00Z",
decision_period_date: "2024-04-01T00:00:00Z",
tax_no: "TXA01234567890",
lift_count: 6,
heating_system: true,
cooling_system: true,
hot_water_system: true,
block_service_man_count: 3,
security_service_man_count: 2,
garage_count: 45,
site_uu_id: "site-uuid-5678jklm-0123",
address_uu_id: "addr-uuid-0123-4567-jklm",
build_types_uu_id: "type-uuid-commercial-office",
},
];
export default buildingsMockData;

View File

@ -1,8 +1,9 @@
"use server";
import React from "react";
import Link from "next/link";
import { Home } from "lucide-react";
import { transformMenu, LanguageTranslation } from "@/components/menu/runner";
import Link from "next/link";
async function LeftMenu({
searchParams,

View File

@ -0,0 +1,59 @@
import * as React from "react"
import { Slot } from "@radix-ui/react-slot"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "@/lib/utils"
const buttonVariants = cva(
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
{
variants: {
variant: {
default:
"bg-primary text-primary-foreground shadow-xs hover:bg-primary/90",
destructive:
"bg-destructive text-white shadow-xs hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
outline:
"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
secondary:
"bg-secondary text-secondary-foreground shadow-xs hover:bg-secondary/80",
ghost:
"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
link: "text-primary underline-offset-4 hover:underline",
},
size: {
default: "h-9 px-4 py-2 has-[>svg]:px-3",
sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
icon: "size-9",
},
},
defaultVariants: {
variant: "default",
size: "default",
},
}
)
function Button({
className,
variant,
size,
asChild = false,
...props
}: React.ComponentProps<"button"> &
VariantProps<typeof buttonVariants> & {
asChild?: boolean
}) {
const Comp = asChild ? Slot : "button"
return (
<Comp
data-slot="button"
className={cn(buttonVariants({ variant, size, className }))}
{...props}
/>
)
}
export { Button, buttonVariants }

View File

@ -0,0 +1,75 @@
"use client"
import * as React from "react"
import { ChevronLeft, ChevronRight } from "lucide-react"
import { DayPicker } from "react-day-picker"
import { cn } from "@/lib/utils"
import { buttonVariants } from "@/components/ui/button"
function Calendar({
className,
classNames,
showOutsideDays = true,
...props
}: React.ComponentProps<typeof DayPicker>) {
return (
<DayPicker
showOutsideDays={showOutsideDays}
className={cn("p-3", className)}
classNames={{
months: "flex flex-col sm:flex-row gap-2",
month: "flex flex-col gap-4",
caption: "flex justify-center pt-1 relative items-center w-full",
caption_label: "text-sm font-medium",
nav: "flex items-center gap-1",
nav_button: cn(
buttonVariants({ variant: "outline" }),
"size-7 bg-transparent p-0 opacity-50 hover:opacity-100"
),
nav_button_previous: "absolute left-1",
nav_button_next: "absolute right-1",
table: "w-full border-collapse space-x-1",
head_row: "flex",
head_cell:
"text-muted-foreground rounded-md w-8 font-normal text-[0.8rem]",
row: "flex w-full mt-2",
cell: cn(
"relative p-0 text-center text-sm focus-within:relative focus-within:z-20 [&:has([aria-selected])]:bg-accent [&:has([aria-selected].day-range-end)]:rounded-r-md",
props.mode === "range"
? "[&:has(>.day-range-end)]:rounded-r-md [&:has(>.day-range-start)]:rounded-l-md first:[&:has([aria-selected])]:rounded-l-md last:[&:has([aria-selected])]:rounded-r-md"
: "[&:has([aria-selected])]:rounded-md"
),
day: cn(
buttonVariants({ variant: "ghost" }),
"size-8 p-0 font-normal aria-selected:opacity-100"
),
day_range_start:
"day-range-start aria-selected:bg-primary aria-selected:text-primary-foreground",
day_range_end:
"day-range-end aria-selected:bg-primary aria-selected:text-primary-foreground",
day_selected:
"bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground focus:bg-primary focus:text-primary-foreground",
day_today: "bg-accent text-accent-foreground",
day_outside:
"day-outside text-muted-foreground aria-selected:text-muted-foreground",
day_disabled: "text-muted-foreground opacity-50",
day_range_middle:
"aria-selected:bg-accent aria-selected:text-accent-foreground",
day_hidden: "invisible",
...classNames,
}}
components={{
IconLeft: ({ className, ...props }) => (
<ChevronLeft className={cn("size-4", className)} {...props} />
),
IconRight: ({ className, ...props }) => (
<ChevronRight className={cn("size-4", className)} {...props} />
),
}}
{...props}
/>
)
}
export { Calendar }

View File

@ -0,0 +1,32 @@
"use client"
import * as React from "react"
import * as CheckboxPrimitive from "@radix-ui/react-checkbox"
import { CheckIcon } from "lucide-react"
import { cn } from "@/lib/utils"
function Checkbox({
className,
...props
}: React.ComponentProps<typeof CheckboxPrimitive.Root>) {
return (
<CheckboxPrimitive.Root
data-slot="checkbox"
className={cn(
"peer border-input dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",
className
)}
{...props}
>
<CheckboxPrimitive.Indicator
data-slot="checkbox-indicator"
className="flex items-center justify-center text-current transition-none"
>
<CheckIcon className="size-3.5" />
</CheckboxPrimitive.Indicator>
</CheckboxPrimitive.Root>
)
}
export { Checkbox }

View File

@ -0,0 +1,70 @@
"use client";
import * as React from "react";
import { format } from "date-fns";
import { CalendarIcon } from "lucide-react";
import { Control, Controller, FieldValues, Path } from "react-hook-form";
import { cn } from "@/lib/utils";
import { Button } from "@/components/ui/button";
import { Calendar } from "@/components/ui/calendar";
import {
Popover,
PopoverContent,
PopoverTrigger,
} from "@/components/ui/popover";
interface DatePickerProps<T extends FieldValues> {
control: Control<T>;
name: Path<T>;
initialDate?: Date;
disabled: boolean;
}
export function DatePicker<T extends FieldValues>({
control,
name,
initialDate,
disabled,
}: DatePickerProps<T>) {
return (
<Controller
control={control}
name={name}
render={({ field }) => {
const selectedDate = field.value ?? initialDate;
return (
<Popover>
<PopoverTrigger asChild>
<Button
variant="outline"
disabled={disabled}
className={cn(
"w-[240px] justify-start text-left font-normal",
!selectedDate && "text-muted-foreground"
)}
>
<CalendarIcon className="mr-2 h-4 w-4" />
{selectedDate ? (
format(selectedDate, "PPP")
) : (
<span>Pick a date</span>
)}
</Button>
</PopoverTrigger>
<PopoverContent className="w-auto p-0" align="start">
<Calendar
disabled={disabled}
mode="single"
selected={selectedDate}
onSelect={field.onChange}
initialFocus
/>
</PopoverContent>
</Popover>
);
}}
/>
);
}

View File

@ -0,0 +1,167 @@
"use client"
import * as React from "react"
import * as LabelPrimitive from "@radix-ui/react-label"
import { Slot } from "@radix-ui/react-slot"
import {
Controller,
FormProvider,
useFormContext,
useFormState,
type ControllerProps,
type FieldPath,
type FieldValues,
} from "react-hook-form"
import { cn } from "@/lib/utils"
import { Label } from "@/components/ui/label"
const Form = FormProvider
type FormFieldContextValue<
TFieldValues extends FieldValues = FieldValues,
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
> = {
name: TName
}
const FormFieldContext = React.createContext<FormFieldContextValue>(
{} as FormFieldContextValue
)
const FormField = <
TFieldValues extends FieldValues = FieldValues,
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
>({
...props
}: ControllerProps<TFieldValues, TName>) => {
return (
<FormFieldContext.Provider value={{ name: props.name }}>
<Controller {...props} />
</FormFieldContext.Provider>
)
}
const useFormField = () => {
const fieldContext = React.useContext(FormFieldContext)
const itemContext = React.useContext(FormItemContext)
const { getFieldState } = useFormContext()
const formState = useFormState({ name: fieldContext.name })
const fieldState = getFieldState(fieldContext.name, formState)
if (!fieldContext) {
throw new Error("useFormField should be used within <FormField>")
}
const { id } = itemContext
return {
id,
name: fieldContext.name,
formItemId: `${id}-form-item`,
formDescriptionId: `${id}-form-item-description`,
formMessageId: `${id}-form-item-message`,
...fieldState,
}
}
type FormItemContextValue = {
id: string
}
const FormItemContext = React.createContext<FormItemContextValue>(
{} as FormItemContextValue
)
function FormItem({ className, ...props }: React.ComponentProps<"div">) {
const id = React.useId()
return (
<FormItemContext.Provider value={{ id }}>
<div
data-slot="form-item"
className={cn("grid gap-2", className)}
{...props}
/>
</FormItemContext.Provider>
)
}
function FormLabel({
className,
...props
}: React.ComponentProps<typeof LabelPrimitive.Root>) {
const { error, formItemId } = useFormField()
return (
<Label
data-slot="form-label"
data-error={!!error}
className={cn("data-[error=true]:text-destructive", className)}
htmlFor={formItemId}
{...props}
/>
)
}
function FormControl({ ...props }: React.ComponentProps<typeof Slot>) {
const { error, formItemId, formDescriptionId, formMessageId } = useFormField()
return (
<Slot
data-slot="form-control"
id={formItemId}
aria-describedby={
!error
? `${formDescriptionId}`
: `${formDescriptionId} ${formMessageId}`
}
aria-invalid={!!error}
{...props}
/>
)
}
function FormDescription({ className, ...props }: React.ComponentProps<"p">) {
const { formDescriptionId } = useFormField()
return (
<p
data-slot="form-description"
id={formDescriptionId}
className={cn("text-muted-foreground text-sm", className)}
{...props}
/>
)
}
function FormMessage({ className, ...props }: React.ComponentProps<"p">) {
const { error, formMessageId } = useFormField()
const body = error ? String(error?.message ?? "") : props.children
if (!body) {
return null
}
return (
<p
data-slot="form-message"
id={formMessageId}
className={cn("text-destructive text-sm", className)}
{...props}
>
{body}
</p>
)
}
export {
useFormField,
Form,
FormItem,
FormLabel,
FormControl,
FormDescription,
FormMessage,
FormField,
}

View File

@ -0,0 +1,21 @@
import * as React from "react"
import { cn } from "@/lib/utils"
function Input({ className, type, ...props }: React.ComponentProps<"input">) {
return (
<input
type={type}
data-slot="input"
className={cn(
"file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input flex h-9 w-full min-w-0 rounded-md border bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
"focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]",
"aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
className
)}
{...props}
/>
)
}
export { Input }

View File

@ -0,0 +1,24 @@
"use client"
import * as React from "react"
import * as LabelPrimitive from "@radix-ui/react-label"
import { cn } from "@/lib/utils"
function Label({
className,
...props
}: React.ComponentProps<typeof LabelPrimitive.Root>) {
return (
<LabelPrimitive.Root
data-slot="label"
className={cn(
"flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",
className
)}
{...props}
/>
)
}
export { Label }

View File

@ -0,0 +1,48 @@
"use client"
import * as React from "react"
import * as PopoverPrimitive from "@radix-ui/react-popover"
import { cn } from "@/lib/utils"
function Popover({
...props
}: React.ComponentProps<typeof PopoverPrimitive.Root>) {
return <PopoverPrimitive.Root data-slot="popover" {...props} />
}
function PopoverTrigger({
...props
}: React.ComponentProps<typeof PopoverPrimitive.Trigger>) {
return <PopoverPrimitive.Trigger data-slot="popover-trigger" {...props} />
}
function PopoverContent({
className,
align = "center",
sideOffset = 4,
...props
}: React.ComponentProps<typeof PopoverPrimitive.Content>) {
return (
<PopoverPrimitive.Portal>
<PopoverPrimitive.Content
data-slot="popover-content"
align={align}
sideOffset={sideOffset}
className={cn(
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border p-4 shadow-md outline-hidden",
className
)}
{...props}
/>
</PopoverPrimitive.Portal>
)
}
function PopoverAnchor({
...props
}: React.ComponentProps<typeof PopoverPrimitive.Anchor>) {
return <PopoverPrimitive.Anchor data-slot="popover-anchor" {...props} />
}
export { Popover, PopoverTrigger, PopoverContent, PopoverAnchor }

View File

@ -1,4 +1,4 @@
FROM node:18-alpine
FROM node:23-alpine
WORKDIR /
@ -6,7 +6,7 @@ WORKDIR /
COPY WebServices/management-frontend/package*.json ./WebServices/management-frontend/
# Install dependencies
RUN cd ./WebServices/management-frontend && npm install
RUN cd ./WebServices/management-frontend && npm install --legacy-peer-deps
# Copy the rest of the application
COPY WebServices/management-frontend ./WebServices/management-frontend

View File

@ -20,6 +20,7 @@ REDIS_HOST=redis_service
REDIS_PASSWORD=commercial_redis_password
REDIS_PORT=6379
REDIS_DB=0
API_ACCESS_EMAIL_EXT=evyos.com.tr
API_ALGORITHM=HS256
API_ACCESS_TOKEN_LENGTH=90
@ -29,6 +30,7 @@ API_DATETIME_FORMAT=YYYY-MM-DD HH:mm:ss Z
API_FORGOT_LINK=https://www.evyos.com.tr/password/create?tokenUrl=
API_VERSION=0.1.001
API_ACCESS_TOKEN_TAG=eys-acs-tkn
EMAIL_HOST=10.10.2.34
EMAIL_USERNAME=karatay@mehmetkaratay.com.tr
EMAIL_PASSWORD=system

View File

@ -1,4 +1,5 @@
services:
mongo_service:
container_name: mongo_service
image: "bitnami/mongodb:latest"
@ -17,6 +18,8 @@ services:
- "11777:27017"
volumes:
- mongodb-data:/bitnami/mongodb
mem_limit: 2048M
cpus: 1.0
postgres-service:
container_name: postgres-service
@ -49,19 +52,21 @@ services:
ports:
- "11222:6379"
client_frontend:
container_name: client_frontend
build:
context: .
dockerfile: WebServices/client-frontend/Dockerfile
networks:
- wag-services
ports:
- "3000:3000"
# volumes:
# - client-frontend:/WebServices/client-frontend
environment:
- NODE_ENV=development
# client_frontend:
# container_name: client_frontend
# build:
# context: .
# dockerfile: WebServices/client-frontend/Dockerfile
# networks:
# - wag-services
# ports:
# - "3000:3000"
# # volumes:
# # - client-frontend:/WebServices/client-frontend
# environment:
# - NODE_ENV=development
# mem_limit: 4096M
# cpus: 2.0
# management_frontend:
# container_name: management_frontend
@ -77,19 +82,19 @@ services:
# environment:
# - NODE_ENV=development
# initializer_service:
# container_name: initializer_service
# build:
# context: .
# dockerfile: ApiServices/InitialService/Dockerfile
# networks:
# - wag-services
# env_file:
# - api_env.env
# depends_on:
# - postgres-service
# - mongo_service
# - redis_service
# initializer_service:
# container_name: initializer_service
# build:
# context: .
# dockerfile: ApiServices/InitialService/Dockerfile
# networks:
# - wag-services
# env_file:
# - api_env.env
# depends_on:
# - postgres-service
# - mongo_service
# - redis_service
# dealer_service:
# container_name: dealer_service
@ -120,7 +125,6 @@ services:
# - API_PORT=8000
# - API_LOG_LEVEL=info
# - API_RELOAD=1
# - API_ACCESS_TOKEN_TAG=1
# - API_APP_NAME=evyos-template-api-gateway
# - API_TITLE=WAG API Template Api Gateway
# - API_FORGOT_LINK=https://template_service/forgot-password
@ -133,6 +137,47 @@ services:
# - mongo_service
# - redis_service
# dealer_service:
# container_name: dealer_service
# build:
# context: .
# dockerfile: ApiServices/DealerService/Dockerfile
# networks:
# - wag-services
# env_file:
# - api_env.env
# depends_on:
# - postgres-service
# - mongo_service
# - redis_service
identity_service:
container_name: identity_service
build:
context: .
dockerfile: ApiServices/IdentityService/Dockerfile
networks:
- wag-services
env_file:
- api_env.env
environment:
- API_PATH=app:app
- API_HOST=0.0.0.0
- API_PORT=8002
- API_LOG_LEVEL=info
- API_RELOAD=1
- API_APP_NAME=evyos-identity-api-gateway
- API_TITLE=WAG API Identity Api Gateway
- API_FORGOT_LINK=https://identity_service/forgot-password
- API_DESCRIPTION=This api is serves as web identity api gateway only to evyos web services.
- API_APP_URL=https://identity_service
ports:
- "8002:8002"
depends_on:
- postgres-service
- mongo_service
- redis_service
auth_service:
container_name: auth_service
build:
@ -176,5 +221,5 @@ networks:
volumes:
postgres-data:
mongodb-data:
client-frontend:
management-frontend:
# client-frontend:
# management-frontend:

100
node_modules/.package-lock.json generated vendored
View File

@ -1,100 +0,0 @@
{
"name": "prod-wag-backend-automate-services",
"lockfileVersion": 3,
"requires": true,
"packages": {
"node_modules/@hookform/resolvers": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/@hookform/resolvers/-/resolvers-5.0.1.tgz",
"integrity": "sha512-u/+Jp83luQNx9AdyW2fIPGY6Y7NG68eN2ZW8FOJYL+M0i4s49+refdJdOp/A9n9HFQtQs3HIDHQvX3ZET2o7YA==",
"dependencies": {
"@standard-schema/utils": "^0.3.0"
},
"peerDependencies": {
"react-hook-form": "^7.55.0"
}
},
"node_modules/@standard-schema/utils": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/@standard-schema/utils/-/utils-0.3.0.tgz",
"integrity": "sha512-e7Mew686owMaPJVNNLs55PUvgz371nKgwsc4vxE49zsODpJEnxgxRo2y/OKrqueavXgZNMDVj3DdHFlaSAeU8g=="
},
"node_modules/flatpickr": {
"version": "4.6.13",
"resolved": "https://registry.npmjs.org/flatpickr/-/flatpickr-4.6.13.tgz",
"integrity": "sha512-97PMG/aywoYpB4IvbvUJi0RQi8vearvU0oov1WW3k0WZPBMrTQVqekSX5CjSG/M4Q3i6A/0FKXC7RyAoAUUSPw=="
},
"node_modules/lucide-react": {
"version": "0.487.0",
"resolved": "https://registry.npmjs.org/lucide-react/-/lucide-react-0.487.0.tgz",
"integrity": "sha512-aKqhOQ+YmFnwq8dWgGjOuLc8V1R9/c/yOd+zDY4+ohsR2Jo05lSGc3WsstYPIzcTpeosN7LoCkLReUUITvaIvw==",
"peerDependencies": {
"react": "^16.5.1 || ^17.0.0 || ^18.0.0 || ^19.0.0"
}
},
"node_modules/next-crypto": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/next-crypto/-/next-crypto-1.0.8.tgz",
"integrity": "sha512-6VcrH+xFuuCRGCdDMjFFibhJ97c4s+J/6SEV73RUYJhh38MDW4WXNZNTWIMZBq0B29LOIfAQ0XA37xGUZZCCjA=="
},
"node_modules/react": {
"version": "19.1.0",
"resolved": "https://registry.npmjs.org/react/-/react-19.1.0.tgz",
"integrity": "sha512-FS+XFBNvn3GTAWq26joslQgWNoFu08F4kl0J4CgdNKADkdSGXQyTCnKteIAJy96Br6YbpEU1LSzV5dYtjMkMDg==",
"peer": true,
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/react-dom": {
"version": "19.1.0",
"resolved": "https://registry.npmjs.org/react-dom/-/react-dom-19.1.0.tgz",
"integrity": "sha512-Xs1hdnE+DyKgeHJeJznQmYMIBG3TKIHJJT95Q58nHLSrElKlGQqDTR2HQ9fx5CN/Gk6Vh/kupBTDLU11/nDk/g==",
"peer": true,
"dependencies": {
"scheduler": "^0.26.0"
},
"peerDependencies": {
"react": "^19.1.0"
}
},
"node_modules/react-hook-form": {
"version": "7.55.0",
"resolved": "https://registry.npmjs.org/react-hook-form/-/react-hook-form-7.55.0.tgz",
"integrity": "sha512-XRnjsH3GVMQz1moZTW53MxfoWN7aDpUg/GpVNc4A3eXRVNdGXfbzJ4vM4aLQ8g6XCUh1nIbx70aaNCl7kxnjog==",
"engines": {
"node": ">=18.0.0"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/react-hook-form"
},
"peerDependencies": {
"react": "^16.8.0 || ^17 || ^18 || ^19"
}
},
"node_modules/scheduler": {
"version": "0.26.0",
"resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.26.0.tgz",
"integrity": "sha512-NlHwttCI/l5gCPR3D1nNXtWABUmBwvZpEQiD4IXSbIDq8BzLIK/7Ir5gTFSGZDUu37K5cMNp0hFtzO38sC7gWA==",
"peer": true
},
"node_modules/sonner": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/sonner/-/sonner-2.0.3.tgz",
"integrity": "sha512-njQ4Hht92m0sMqqHVDL32V2Oun9W1+PHO9NDv9FHfJjT3JT22IG4Jpo3FPQy+mouRKCXFWO+r67v6MrHX2zeIA==",
"peerDependencies": {
"react": "^18.0.0 || ^19.0.0 || ^19.0.0-rc",
"react-dom": "^18.0.0 || ^19.0.0 || ^19.0.0-rc"
}
},
"node_modules/zod": {
"version": "3.24.2",
"resolved": "https://registry.npmjs.org/zod/-/zod-3.24.2.tgz",
"integrity": "sha512-lY7CDW43ECgW9u1TcT3IoXHflywfVqDYze4waEz812jR/bZ8FHDsl7pFQoSZTz5N+2NqRXs8GBwnAwo3ZNxqhQ==",
"funding": {
"url": "https://github.com/sponsors/colinhacks"
}
}
}
}

View File

@ -1,21 +0,0 @@
MIT License
Copyright (c) 2019-present Beier(Bill) Luo
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -1,926 +0,0 @@
<div align="center">
<p align="center">
<a href="https://react-hook-form.com" title="React Hook Form - Simple React forms validation">
<img src="https://raw.githubusercontent.com/bluebill1049/react-hook-form/master/docs/logo.png" alt="React Hook Form Logo - React hook custom hook for form validation" />
</a>
</p>
</div>
<p align="center">Performant, flexible and extensible forms with easy to use validation.</p>
<div align="center">
[![npm downloads](https://img.shields.io/npm/dm/@hookform/resolvers.svg?style=for-the-badge)](https://www.npmjs.com/package/@hookform/resolvers)
[![npm](https://img.shields.io/npm/dt/@hookform/resolvers.svg?style=for-the-badge)](https://www.npmjs.com/package/@hookform/resolvers)
[![npm](https://img.shields.io/bundlephobia/minzip/@hookform/resolvers?style=for-the-badge)](https://bundlephobia.com/result?p=@hookform/resolvers)
</div>
## React Hook Form Resolvers
This function allows you to use any external validation library such as Yup, Zod, Joi, Vest, Ajv and many others. The goal is to make sure you can seamlessly integrate whichever validation library you prefer. If you're not using a library, you can always write your own logic to validate your forms.
## Install
Install your preferred validation library alongside `@hookform/resolvers`.
npm install @hookform/resolvers # npm
yarn add @hookform/resolvers # yarn
pnpm install @hookform/resolvers # pnpm
bun install @hookform/resolvers # bun
<details>
<summary>Resolver Comparison</summary>
| resolver | Infer values <br /> from schema | [criteriaMode](https://react-hook-form.com/docs/useform#criteriaMode) |
|---|---|---|
| AJV | ❌ | `firstError | all` |
| Arktype | ✅ | `firstError` |
| class-validator | ✅ | `firstError | all` |
| computed-types | ✅ | `firstError` |
| Effect | ✅ | `firstError | all` |
| fluentvalidation-ts | ❌ | `firstError` |
| io-ts | ✅ | `firstError` |
| joi | ❌ | `firstError | all` |
| Nope | ❌ | `firstError` |
| Standard Schema | ✅ | `firstError | all` |
| Superstruct | ✅ | `firstError` |
| typanion | ✅ | `firstError` |
| typebox | ✅ | `firstError | all` |
| typeschema | ❌ | `firstError | all` |
| valibot | ✅ | `firstError | all` |
| vest | ❌ | `firstError | all` |
| vine | ✅ | `firstError | all` |
| yup | ✅ | `firstError | all` |
| zod | ✅ | `firstError | all` |
</details>
## TypeScript
Most of the resolvers can infer the output type from the schema. See comparison table for more details.
```tsx
useForm<Input, Context, Output>()
```
Example:
```tsx
import { useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import { z } from 'zod';
const schema = z.object({
id: z.number(),
});
// Automatically infers the output type from the schema
useForm({
resolver: zodResolver(schema),
});
// Force the output type
useForm<z.input<typeof schema>, any, z.output<typeof schema>>({
resolver: zodResolver(schema),
});
```
## Links
- [React-hook-form validation resolver documentation ](https://react-hook-form.com/docs/useform#resolver)
### Supported resolvers
- [Install](#install)
- [Links](#links)
- [Supported resolvers](#supported-resolvers)
- [API](#api)
- [Quickstart](#quickstart)
- [Yup](#yup)
- [Zod](#zod)
- [Superstruct](#superstruct)
- [Joi](#joi)
- [Vest](#vest)
- [Class Validator](#class-validator)
- [io-ts](#io-ts)
- [Nope](#nope)
- [computed-types](#computed-types)
- [typanion](#typanion)
- [Ajv](#ajv)
- [TypeBox](#typebox)
- [With `ValueCheck`](#with-valuecheck)
- [With `TypeCompiler`](#with-typecompiler)
- [ArkType](#arktype)
- [Valibot](#valibot)
- [TypeSchema](#typeschema)
- [effect-ts](#effect-ts)
- [VineJS](#vinejs)
- [fluentvalidation-ts](#fluentvalidation-ts)
- [standard-schema](#standard-schema)
- [Backers](#backers)
- [Sponsors](#sponsors)
- [Contributors](#contributors)
## API
```
type Options = {
mode: 'async' | 'sync',
raw?: boolean
}
resolver(schema: object, schemaOptions?: object, resolverOptions: Options)
```
| | type | Required | Description |
| --------------- | -------- | -------- | --------------------------------------------- |
| schema | `object` | ✓ | validation schema |
| schemaOptions | `object` | | validation library schema options |
| resolverOptions | `object` | | resolver options, `async` is the default mode |
## Quickstart
### [Yup](https://github.com/jquense/yup)
Dead simple Object schema validation.
[![npm](https://img.shields.io/bundlephobia/minzip/yup?style=for-the-badge)](https://bundlephobia.com/result?p=yup)
```typescript jsx
import { useForm } from 'react-hook-form';
import { yupResolver } from '@hookform/resolvers/yup';
import * as yup from 'yup';
const schema = yup
.object()
.shape({
name: yup.string().required(),
age: yup.number().required(),
})
.required();
const App = () => {
const { register, handleSubmit } = useForm({
resolver: yupResolver(schema),
});
return (
<form onSubmit={handleSubmit((d) => console.log(d))}>
<input {...register('name')} />
<input type="number" {...register('age')} />
<input type="submit" />
</form>
);
};
```
### [Zod](https://github.com/vriad/zod)
TypeScript-first schema validation with static type inference
[![npm](https://img.shields.io/bundlephobia/minzip/zod?style=for-the-badge)](https://bundlephobia.com/result?p=zod)
> ⚠️ Example below uses the `valueAsNumber`, which requires `react-hook-form` v6.12.0 (released Nov 28, 2020) or later.
```tsx
import { useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import { z } from 'zod';
const schema = z.object({
name: z.string().min(1, { message: 'Required' }),
age: z.number().min(10),
});
const App = () => {
const {
register,
handleSubmit,
formState: { errors },
} = useForm({
resolver: zodResolver(schema),
});
return (
<form onSubmit={handleSubmit((d) => console.log(d))}>
<input {...register('name')} />
{errors.name?.message && <p>{errors.name?.message}</p>}
<input type="number" {...register('age', { valueAsNumber: true })} />
{errors.age?.message && <p>{errors.age?.message}</p>}
<input type="submit" />
</form>
);
};
```
### [Superstruct](https://github.com/ianstormtaylor/superstruct)
A simple and composable way to validate data in JavaScript (or TypeScript).
[![npm](https://img.shields.io/bundlephobia/minzip/superstruct?style=for-the-badge)](https://bundlephobia.com/result?p=superstruct)
```typescript jsx
import { useForm } from 'react-hook-form';
import { superstructResolver } from '@hookform/resolvers/superstruct';
import { object, string, number } from 'superstruct';
const schema = object({
name: string(),
age: number(),
});
const App = () => {
const { register, handleSubmit } = useForm({
resolver: superstructResolver(schema),
});
return (
<form onSubmit={handleSubmit((d) => console.log(d))}>
<input {...register('name')} />
<input type="number" {...register('age', { valueAsNumber: true })} />
<input type="submit" />
</form>
);
};
```
### [Joi](https://github.com/sideway/joi)
The most powerful data validation library for JS.
[![npm](https://img.shields.io/bundlephobia/minzip/joi?style=for-the-badge)](https://bundlephobia.com/result?p=joi)
```typescript jsx
import { useForm } from 'react-hook-form';
import { joiResolver } from '@hookform/resolvers/joi';
import Joi from 'joi';
const schema = Joi.object({
name: Joi.string().required(),
age: Joi.number().required(),
});
const App = () => {
const { register, handleSubmit } = useForm({
resolver: joiResolver(schema),
});
return (
<form onSubmit={handleSubmit((d) => console.log(d))}>
<input {...register('name')} />
<input type="number" {...register('age')} />
<input type="submit" />
</form>
);
};
```
### [Vest](https://github.com/ealush/vest)
Vest 🦺 Declarative Validation Testing.
[![npm](https://img.shields.io/bundlephobia/minzip/vest?style=for-the-badge)](https://bundlephobia.com/result?p=vest)
```typescript jsx
import { useForm } from 'react-hook-form';
import { vestResolver } from '@hookform/resolvers/vest';
import { create, test, enforce } from 'vest';
const validationSuite = create((data = {}) => {
test('username', 'Username is required', () => {
enforce(data.username).isNotEmpty();
});
test('password', 'Password is required', () => {
enforce(data.password).isNotEmpty();
});
});
const App = () => {
const { register, handleSubmit, errors } = useForm({
resolver: vestResolver(validationSuite),
});
return (
<form onSubmit={handleSubmit((data) => console.log(data))}>
<input {...register('username')} />
<input type="password" {...register('password')} />
<input type="submit" />
</form>
);
};
```
### [Class Validator](https://github.com/typestack/class-validator)
Decorator-based property validation for classes.
[![npm](https://img.shields.io/bundlephobia/minzip/class-validator?style=for-the-badge)](https://bundlephobia.com/result?p=class-validator)
> ⚠️ Remember to add these options to your `tsconfig.json`!
```
"strictPropertyInitialization": false,
"experimentalDecorators": true
```
```tsx
import { useForm } from 'react-hook-form';
import { classValidatorResolver } from '@hookform/resolvers/class-validator';
import { Length, Min, IsEmail } from 'class-validator';
class User {
@Length(2, 30)
username: string;
@IsEmail()
email: string;
}
const resolver = classValidatorResolver(User);
const App = () => {
const {
register,
handleSubmit,
formState: { errors },
} = useForm<User>({ resolver });
return (
<form onSubmit={handleSubmit((data) => console.log(data))}>
<input type="text" {...register('username')} />
{errors.username && <span>{errors.username.message}</span>}
<input type="text" {...register('email')} />
{errors.email && <span>{errors.email.message}</span>}
<input type="submit" value="Submit" />
</form>
);
};
```
### [io-ts](https://github.com/gcanti/io-ts)
Validate your data with powerful decoders.
[![npm](https://img.shields.io/bundlephobia/minzip/io-ts?style=for-the-badge)](https://bundlephobia.com/result?p=io-ts)
```typescript jsx
import React from 'react';
import { useForm } from 'react-hook-form';
import { ioTsResolver } from '@hookform/resolvers/io-ts';
import t from 'io-ts';
// you don't have to use io-ts-types, but it's very useful
import tt from 'io-ts-types';
const schema = t.type({
username: t.string,
age: tt.NumberFromString,
});
const App = () => {
const { register, handleSubmit } = useForm({
resolver: ioTsResolver(schema),
});
return (
<form onSubmit={handleSubmit((d) => console.log(d))}>
<input {...register('username')} />
<input type="number" {...register('age')} />
<input type="submit" />
</form>
);
};
export default App;
```
### [Nope](https://github.com/bvego/nope-validator)
A small, simple, and fast JS validator
[![npm](https://img.shields.io/bundlephobia/minzip/nope-validator?style=for-the-badge)](https://bundlephobia.com/result?p=nope-validator)
```typescript jsx
import { useForm } from 'react-hook-form';
import { nopeResolver } from '@hookform/resolvers/nope';
import Nope from 'nope-validator';
const schema = Nope.object().shape({
name: Nope.string().required(),
age: Nope.number().required(),
});
const App = () => {
const { register, handleSubmit } = useForm({
resolver: nopeResolver(schema),
});
return (
<form onSubmit={handleSubmit((d) => console.log(d))}>
<input {...register('name')} />
<input type="number" {...register('age')} />
<input type="submit" />
</form>
);
};
```
### [computed-types](https://github.com/neuledge/computed-types)
TypeScript-first schema validation with static type inference
[![npm](https://img.shields.io/bundlephobia/minzip/computed-types?style=for-the-badge)](https://bundlephobia.com/result?p=computed-types)
```tsx
import { useForm } from 'react-hook-form';
import { computedTypesResolver } from '@hookform/resolvers/computed-types';
import Schema, { number, string } from 'computed-types';
const schema = Schema({
username: string.min(1).error('username field is required'),
age: number,
});
const App = () => {
const {
register,
handleSubmit,
formState: { errors },
} = useForm({
resolver: computedTypesResolver(schema),
});
return (
<form onSubmit={handleSubmit((d) => console.log(d))}>
<input {...register('name')} />
{errors.name?.message && <p>{errors.name?.message}</p>}
<input type="number" {...register('age', { valueAsNumber: true })} />
{errors.age?.message && <p>{errors.age?.message}</p>}
<input type="submit" />
</form>
);
};
```
### [typanion](https://github.com/arcanis/typanion)
Static and runtime type assertion library with no dependencies
[![npm](https://img.shields.io/bundlephobia/minzip/typanion?style=for-the-badge)](https://bundlephobia.com/result?p=typanion)
```tsx
import { useForm } from 'react-hook-form';
import { typanionResolver } from '@hookform/resolvers/typanion';
import * as t from 'typanion';
const isUser = t.isObject({
username: t.applyCascade(t.isString(), [t.hasMinLength(1)]),
age: t.applyCascade(t.isNumber(), [
t.isInteger(),
t.isInInclusiveRange(1, 100),
]),
});
const App = () => {
const {
register,
handleSubmit,
formState: { errors },
} = useForm({
resolver: typanionResolver(isUser),
});
return (
<form onSubmit={handleSubmit((d) => console.log(d))}>
<input {...register('name')} />
{errors.name?.message && <p>{errors.name?.message}</p>}
<input type="number" {...register('age')} />
{errors.age?.message && <p>{errors.age?.message}</p>}
<input type="submit" />
</form>
);
};
```
### [Ajv](https://github.com/ajv-validator/ajv)
The fastest JSON validator for Node.js and browser
[![npm](https://img.shields.io/bundlephobia/minzip/ajv?style=for-the-badge)](https://bundlephobia.com/result?p=ajv)
```tsx
import { useForm } from 'react-hook-form';
import { ajvResolver } from '@hookform/resolvers/ajv';
// must use `minLength: 1` to implement required field
const schema = {
type: 'object',
properties: {
username: {
type: 'string',
minLength: 1,
errorMessage: { minLength: 'username field is required' },
},
password: {
type: 'string',
minLength: 1,
errorMessage: { minLength: 'password field is required' },
},
},
required: ['username', 'password'],
additionalProperties: false,
};
const App = () => {
const {
register,
handleSubmit,
formState: { errors },
} = useForm({
resolver: ajvResolver(schema),
});
return (
<form onSubmit={handleSubmit((data) => console.log(data))}>
<input {...register('username')} />
{errors.username && <span>{errors.username.message}</span>}
<input {...register('password')} />
{errors.password && <span>{errors.password.message}</span>}
<button type="submit">submit</button>
</form>
);
};
```
### [TypeBox](https://github.com/sinclairzx81/typebox)
JSON Schema Type Builder with Static Type Resolution for TypeScript
[![npm](https://img.shields.io/bundlephobia/minzip/@sinclair/typebox?style=for-the-badge)](https://bundlephobia.com/result?p=@sinclair/typebox)
#### With `ValueCheck`
```typescript jsx
import { useForm } from 'react-hook-form';
import { typeboxResolver } from '@hookform/resolvers/typebox';
import { Type } from '@sinclair/typebox';
const schema = Type.Object({
username: Type.String({ minLength: 1 }),
password: Type.String({ minLength: 1 }),
});
const App = () => {
const { register, handleSubmit } = useForm({
resolver: typeboxResolver(schema),
});
return (
<form onSubmit={handleSubmit((d) => console.log(d))}>
<input {...register('username')} />
<input type="password" {...register('password')} />
<input type="submit" />
</form>
);
};
```
#### With `TypeCompiler`
A high-performance JIT of `TypeBox`, [read more](https://github.com/sinclairzx81/typebox#typecompiler)
```typescript jsx
import { useForm } from 'react-hook-form';
import { typeboxResolver } from '@hookform/resolvers/typebox';
import { Type } from '@sinclair/typebox';
import { TypeCompiler } from '@sinclair/typebox/compiler';
const schema = Type.Object({
username: Type.String({ minLength: 1 }),
password: Type.String({ minLength: 1 }),
});
const typecheck = TypeCompiler.Compile(schema);
const App = () => {
const { register, handleSubmit } = useForm({
resolver: typeboxResolver(typecheck),
});
return (
<form onSubmit={handleSubmit((d) => console.log(d))}>
<input {...register('username')} />
<input type="password" {...register('password')} />
<input type="submit" />
</form>
);
};
```
### [ArkType](https://github.com/arktypeio/arktype)
TypeScript's 1:1 validator, optimized from editor to runtime
[![npm](https://img.shields.io/bundlephobia/minzip/arktype?style=for-the-badge)](https://bundlephobia.com/result?p=arktype)
```typescript jsx
import { useForm } from 'react-hook-form';
import { arktypeResolver } from '@hookform/resolvers/arktype';
import { type } from 'arktype';
const schema = type({
username: 'string>1',
password: 'string>1',
});
const App = () => {
const { register, handleSubmit } = useForm({
resolver: arktypeResolver(schema),
});
return (
<form onSubmit={handleSubmit((d) => console.log(d))}>
<input {...register('username')} />
<input type="password" {...register('password')} />
<input type="submit" />
</form>
);
};
```
### [Valibot](https://github.com/fabian-hiller/valibot)
The modular and type safe schema library for validating structural data
[![npm](https://img.shields.io/bundlephobia/minzip/valibot?style=for-the-badge)](https://bundlephobia.com/result?p=valibot)
```typescript jsx
import { useForm } from 'react-hook-form';
import { valibotResolver } from '@hookform/resolvers/valibot';
import * as v from 'valibot';
const schema = v.object({
username: v.pipe(
v.string('username is required'),
v.minLength(3, 'Needs to be at least 3 characters'),
v.endsWith('cool', 'Needs to end with `cool`'),
),
password: v.string('password is required'),
});
const App = () => {
const { register, handleSubmit } = useForm({
resolver: valibotResolver(schema),
});
return (
<form onSubmit={handleSubmit((d) => console.log(d))}>
<input {...register('username')} />
<input type="password" {...register('password')} />
<input type="submit" />
</form>
);
};
```
### [TypeSchema](https://typeschema.com)
Universal adapter for schema validation, compatible with [any validation library](https://typeschema.com/#coverage)
[![npm](https://img.shields.io/bundlephobia/minzip/@typeschema/main?style=for-the-badge)](https://bundlephobia.com/result?p=@typeschema/main)
```typescript jsx
import { useForm } from 'react-hook-form';
import { typeschemaResolver } from '@hookform/resolvers/typeschema';
import { z } from 'zod';
// Use your favorite validation library
const schema = z.object({
username: z.string().min(1, { message: 'Required' }),
password: z.number().min(1, { message: 'Required' }),
});
const App = () => {
const { register, handleSubmit } = useForm({
resolver: typeschemaResolver(schema),
});
return (
<form onSubmit={handleSubmit((d) => console.log(d))}>
<input {...register('username')} />
<input type="password" {...register('password')} />
<input type="submit" />
</form>
);
};
```
### [effect-ts](https://github.com/Effect-TS/effect)
A powerful TypeScript framework that provides a fully-fledged functional effect system with a rich standard library.
[![npm](https://img.shields.io/bundlephobia/minzip/effect?style=for-the-badge)](https://bundlephobia.com/result?p=effect)
```typescript jsx
import React from 'react';
import { useForm } from 'react-hook-form';
import { effectTsResolver } from '@hookform/resolvers/effect-ts';
import { Schema } from 'effect';
const schema = Schema.Struct({
username: Schema.String.pipe(
Schema.nonEmptyString({ message: () => 'username required' }),
),
password: Schema.String.pipe(
Schema.nonEmptyString({ message: () => 'password required' }),
),
});
type FormData = typeof schema.Type;
interface Props {
onSubmit: (data: FormData) => void;
}
function TestComponent({ onSubmit }: Props) {
const {
register,
handleSubmit,
formState: { errors },
// provide generic if TS has issues inferring types
} = useForm<FormData>({
resolver: effectTsResolver(schema),
});
return (
<form onSubmit={handleSubmit(onSubmit)}>
<input {...register('username')} />
{errors.username && <span role="alert">{errors.username.message}</span>}
<input {...register('password')} />
{errors.password && <span role="alert">{errors.password.message}</span>}
<button type="submit">submit</button>
</form>
);
}
```
### [VineJS](https://github.com/vinejs/vine)
VineJS is a form data validation library for Node.js
[![npm](https://img.shields.io/bundlephobia/minzip/@vinejs/vine?style=for-the-badge)](https://bundlephobia.com/result?p=@vinejs/vine)
```typescript jsx
import { useForm } from 'react-hook-form';
import { vineResolver } from '@hookform/resolvers/vine';
import vine from '@vinejs/vine';
const schema = vine.compile(
vine.object({
username: vine.string().minLength(1),
password: vine.string().minLength(1),
}),
);
const App = () => {
const { register, handleSubmit } = useForm({
resolver: vineResolver(schema),
});
return (
<form onSubmit={handleSubmit((d) => console.log(d))}>
<input {...register('username')} />
{errors.username && <span role="alert">{errors.username.message}</span>}
<input {...register('password')} />
{errors.password && <span role="alert">{errors.password.message}</span>}
<button type="submit">submit</button>
</form>
);
};
```
### [fluentvalidation-ts](https://github.com/AlexJPotter/fluentvalidation-ts)
A TypeScript-first library for building strongly-typed validation rules
[![npm](https://img.shields.io/bundlephobia/minzip/@vinejs/vine?style=for-the-badge)](https://bundlephobia.com/result?p=@vinejs/vine)
```typescript jsx
import { useForm } from 'react-hook-form';
import { fluentValidationResolver } from '@hookform/resolvers/fluentvalidation-ts';
import { Validator } from 'fluentvalidation-ts';
class FormDataValidator extends Validator<FormData> {
constructor() {
super();
this.ruleFor('username')
.notEmpty()
.withMessage('username is a required field');
this.ruleFor('password')
.notEmpty()
.withMessage('password is a required field');
}
}
const App = () => {
const { register, handleSubmit } = useForm({
resolver: fluentValidationResolver(new FormDataValidator()),
});
return (
<form onSubmit={handleSubmit((d) => console.log(d))}>
<input {...register('username')} />
{errors.username && <span role="alert">{errors.username.message}</span>}
<input {...register('password')} />
{errors.password && <span role="alert">{errors.password.message}</span>}
<button type="submit">submit</button>
</form>
);
};
```
### [standard-schema](https://github.com/standard-schema/standard-schema)
A standard interface for TypeScript schema validation libraries
[![npm](https://img.shields.io/bundlephobia/minzip/@standard-schema/spec?style=for-the-badge)](https://bundlephobia.com/result?p=@standard-schema/spec)
Example zod
```typescript jsx
import { useForm } from 'react-hook-form';
import { standardSchemaResolver } from '@hookform/resolvers/standard-schema';
import { z } from 'zod';
const schema = z.object({
name: z.string().min(1, { message: 'Required' }),
age: z.number().min(10),
});
const App = () => {
const {
register,
handleSubmit,
formState: { errors },
} = useForm({
resolver: standardSchemaResolver(schema),
});
return (
<form onSubmit={handleSubmit((d) => console.log(d))}>
<input {...register('name')} />
{errors.name?.message && <p>{errors.name?.message}</p>}
<input type="number" {...register('age', { valueAsNumber: true })} />
{errors.age?.message && <p>{errors.age?.message}</p>}
<input type="submit" />
</form>
);
};
```
Example arkType
```typescript jsx
import { useForm } from 'react-hook-form';
import { standardSchemaResolver } from '@hookform/resolvers/standard-schema';
import { type } from 'arktype';
const schema = type({
username: 'string>1',
password: 'string>1',
});
const App = () => {
const { register, handleSubmit } = useForm({
resolver: standardSchemaResolver(schema),
});
return (
<form onSubmit={handleSubmit((d) => console.log(d))}>
<input {...register('username')} />
<input type="password" {...register('password')} />
<input type="submit" />
</form>
);
};
```
## Backers
Thanks go to all our backers! [[Become a backer](https://opencollective.com/react-hook-form#backer)].
<a href="https://opencollective.com/react-hook-form#backers">
<img src="https://opencollective.com/react-hook-form/backers.svg?width=950" />
</a>
## Contributors
Thanks go to these wonderful people! [[Become a contributor](CONTRIBUTING.md)].
<a href="https://github.com/react-hook-form/react-hook-form/graphs/contributors">
<img src="https://opencollective.com/react-hook-form/contributors.svg?width=950" />
</a>

View File

@ -1,19 +0,0 @@
{
"name": "@hookform/resolvers/ajv",
"amdName": "hookformResolversAjv",
"version": "1.0.0",
"private": true,
"description": "React Hook Form validation resolver: ajv",
"main": "dist/ajv.js",
"module": "dist/ajv.module.js",
"umd:main": "dist/ajv.umd.js",
"source": "src/index.ts",
"types": "dist/index.d.ts",
"license": "MIT",
"peerDependencies": {
"react-hook-form": "^7.55.0",
"@hookform/resolvers": "^2.0.0",
"ajv": "^8.12.0",
"ajv-errors": "^3.0.0"
}
}

View File

@ -1,94 +0,0 @@
import { render, screen } from '@testing-library/react';
import user from '@testing-library/user-event';
import { JSONSchemaType } from 'ajv';
import React from 'react';
import { useForm } from 'react-hook-form';
import { ajvResolver } from '..';
const USERNAME_REQUIRED_MESSAGE = 'username field is required';
const PASSWORD_REQUIRED_MESSAGE = 'password field is required';
type FormData = { username: string; password: string };
const schema: JSONSchemaType<FormData> = {
type: 'object',
properties: {
username: {
type: 'string',
minLength: 1,
errorMessage: { minLength: USERNAME_REQUIRED_MESSAGE },
},
password: {
type: 'string',
minLength: 1,
errorMessage: { minLength: PASSWORD_REQUIRED_MESSAGE },
},
},
required: ['username', 'password'],
additionalProperties: false,
};
interface Props {
onSubmit: (data: FormData) => void;
}
function TestComponent({ onSubmit }: Props) {
const { register, handleSubmit } = useForm<FormData>({
resolver: ajvResolver(schema),
shouldUseNativeValidation: true,
});
return (
<form onSubmit={handleSubmit(onSubmit)}>
<input {...register('username')} placeholder="username" />
<input {...register('password')} placeholder="password" />
<button type="submit">submit</button>
</form>
);
}
test("form's native validation with Ajv", async () => {
const handleSubmit = vi.fn();
render(<TestComponent onSubmit={handleSubmit} />);
// username
let usernameField = screen.getByPlaceholderText(
/username/i,
) as HTMLInputElement;
expect(usernameField.validity.valid).toBe(true);
expect(usernameField.validationMessage).toBe('');
// password
let passwordField = screen.getByPlaceholderText(
/password/i,
) as HTMLInputElement;
expect(passwordField.validity.valid).toBe(true);
expect(passwordField.validationMessage).toBe('');
await user.click(screen.getByText(/submit/i));
// username
usernameField = screen.getByPlaceholderText(/username/i) as HTMLInputElement;
expect(usernameField.validity.valid).toBe(false);
expect(usernameField.validationMessage).toBe(USERNAME_REQUIRED_MESSAGE);
// password
passwordField = screen.getByPlaceholderText(/password/i) as HTMLInputElement;
expect(passwordField.validity.valid).toBe(false);
expect(passwordField.validationMessage).toBe(PASSWORD_REQUIRED_MESSAGE);
await user.type(screen.getByPlaceholderText(/username/i), 'joe');
await user.type(screen.getByPlaceholderText(/password/i), 'password');
// username
usernameField = screen.getByPlaceholderText(/username/i) as HTMLInputElement;
expect(usernameField.validity.valid).toBe(true);
expect(usernameField.validationMessage).toBe('');
// password
passwordField = screen.getByPlaceholderText(/password/i) as HTMLInputElement;
expect(passwordField.validity.valid).toBe(true);
expect(passwordField.validationMessage).toBe('');
});

View File

@ -1,65 +0,0 @@
import { render, screen } from '@testing-library/react';
import user from '@testing-library/user-event';
import { JSONSchemaType } from 'ajv';
import React from 'react';
import { useForm } from 'react-hook-form';
import { ajvResolver } from '..';
type FormData = { username: string; password: string };
const schema: JSONSchemaType<FormData> = {
type: 'object',
properties: {
username: {
type: 'string',
minLength: 1,
errorMessage: { minLength: 'username field is required' },
},
password: {
type: 'string',
minLength: 1,
errorMessage: { minLength: 'password field is required' },
},
},
required: ['username', 'password'],
additionalProperties: false,
};
interface Props {
onSubmit: (data: FormData) => void;
}
function TestComponent({ onSubmit }: Props) {
const {
register,
formState: { errors },
handleSubmit,
} = useForm<FormData>({
resolver: ajvResolver(schema), // Useful to check TypeScript regressions
});
return (
<form onSubmit={handleSubmit(onSubmit)}>
<input {...register('username')} />
{errors.username && <span role="alert">{errors.username.message}</span>}
<input {...register('password')} />
{errors.password && <span role="alert">{errors.password.message}</span>}
<button type="submit">submit</button>
</form>
);
}
test("form's validation with Ajv and TypeScript's integration", async () => {
const handleSubmit = vi.fn();
render(<TestComponent onSubmit={handleSubmit} />);
expect(screen.queryAllByRole('alert')).toHaveLength(0);
await user.click(screen.getByText(/submit/i));
expect(screen.getByText(/username field is required/i)).toBeInTheDocument();
expect(screen.getByText(/password field is required/i)).toBeInTheDocument();
expect(handleSubmit).not.toHaveBeenCalled();
});

View File

@ -1,216 +0,0 @@
import { JSONSchemaType } from 'ajv';
import { Field, InternalFieldName } from 'react-hook-form';
interface DataA {
username: string;
password: string;
}
export const schemaA: JSONSchemaType<DataA> = {
type: 'object',
properties: {
username: {
type: 'string',
minLength: 3,
errorMessage: {
minLength: 'username should be at least three characters long',
},
},
password: {
type: 'string',
pattern: '.*[A-Z].*',
minLength: 8,
errorMessage: {
pattern: 'One uppercase character',
minLength: 'passwords should be at least eight characters long',
},
},
},
required: ['username', 'password'],
additionalProperties: false,
errorMessage: {
required: {
username: 'username field is required',
password: 'password field is required',
},
},
};
export const validDataA: DataA = {
username: 'kt666',
password: 'validPassword',
};
export const invalidDataA = {
username: 'kt',
password: 'invalid',
};
export const undefinedDataA = {
username: undefined,
password: undefined,
};
export const fieldsA: Record<InternalFieldName, Field['_f']> = {
username: {
ref: { name: 'username' },
name: 'username',
},
password: {
ref: { name: 'password' },
name: 'password',
},
email: {
ref: { name: 'email' },
name: 'email',
},
birthday: {
ref: { name: 'birthday' },
name: 'birthday',
},
};
// examples from [ajv-errors](https://github.com/ajv-validator/ajv-errors)
interface DataB {
foo: number;
}
export const schemaB: JSONSchemaType<DataB> = {
type: 'object',
required: ['foo'],
properties: {
foo: { type: 'integer' },
},
additionalProperties: false,
errorMessage: 'should be an object with an integer property foo only',
};
export const validDataB: DataB = { foo: 666 };
export const invalidDataB = { foo: 'kt', bar: 6 };
export const undefinedDataB = { foo: undefined };
interface DataC {
foo: number;
}
export const schemaC: JSONSchemaType<DataC> = {
type: 'object',
required: ['foo'],
properties: {
foo: { type: 'integer' },
},
additionalProperties: false,
errorMessage: {
type: 'should be an object',
required: 'should have property foo',
additionalProperties: 'should not have properties other than foo',
},
};
export const validDataC: DataC = { foo: 666 };
export const invalidDataC = { foo: 'kt', bar: 6 };
export const undefinedDataC = { foo: undefined };
export const invalidTypeDataC = 'something';
interface DataD {
foo: number;
bar: string;
}
export const schemaD: JSONSchemaType<DataD> = {
type: 'object',
required: ['foo', 'bar'],
properties: {
foo: { type: 'integer' },
bar: { type: 'string' },
},
errorMessage: {
type: 'should be an object', // will not replace internal "type" error for the property "foo"
required: {
foo: 'should have an integer property "foo"',
bar: 'should have a string property "bar"',
},
},
};
export const validDataD: DataD = { foo: 666, bar: 'kt' };
export const invalidDataD = { foo: 'kt', bar: 6 };
export const undefinedDataD = { foo: undefined, bar: undefined };
export const invalidTypeDataD = 'something';
interface DataE {
foo: number;
bar: string;
}
export const schemaE: JSONSchemaType<DataE> = {
type: 'object',
required: ['foo', 'bar'],
allOf: [
{
properties: {
foo: { type: 'integer', minimum: 2 },
bar: { type: 'string', minLength: 2 },
},
additionalProperties: false,
},
],
errorMessage: {
properties: {
foo: 'data.foo should be integer >= 2',
bar: 'data.bar should be string with length >= 2',
},
},
};
export const validDataE: DataE = { foo: 666, bar: 'kt' };
export const invalidDataE = { foo: 1, bar: 'k' };
export const undefinedDataE = { foo: undefined, bar: undefined };
interface DataF {
foo: number;
bar: string;
}
export const schemaF: JSONSchemaType<DataF> = {
type: 'object',
required: ['foo', 'bar'],
allOf: [
{
properties: {
foo: { type: 'integer', minimum: 2 },
bar: { type: 'string', minLength: 2 },
},
additionalProperties: false,
},
],
errorMessage: {
type: 'data should be an object',
properties: {
foo: 'data.foo should be integer >= 2',
bar: 'data.bar should be string with length >= 2',
},
_: 'data should have properties "foo" and "bar" only',
},
};
export const validDataF: DataF = { foo: 666, bar: 'kt' };
export const invalidDataF = {};
export const undefinedDataF = { foo: 1, bar: undefined };
export const invalidTypeDataF = 'something';
export const fieldsRest: Record<InternalFieldName, Field['_f']> = {
foo: {
ref: { name: 'foo' },
name: 'foo',
},
bar: {
ref: { name: 'bar' },
name: 'bar',
},
lorem: {
ref: { name: 'lorem' },
name: 'lorem',
},
};

View File

@ -1,90 +0,0 @@
import { JSONSchemaType } from 'ajv';
import { Field, InternalFieldName } from 'react-hook-form';
interface Data {
username: string;
password: string;
deepObject: { data: string; twoLayersDeep: { name: string } };
}
export const schema: JSONSchemaType<Data> = {
type: 'object',
properties: {
username: {
type: 'string',
minLength: 3,
},
password: {
type: 'string',
pattern: '.*[A-Z].*',
errorMessage: {
pattern: 'One uppercase character',
},
},
deepObject: {
type: 'object',
properties: {
data: { type: 'string' },
twoLayersDeep: {
type: 'object',
properties: { name: { type: 'string' } },
additionalProperties: false,
required: ['name'],
},
},
required: ['data', 'twoLayersDeep'],
},
},
required: ['username', 'password', 'deepObject'],
additionalProperties: false,
};
export const validData: Data = {
username: 'jsun969',
password: 'validPassword',
deepObject: {
twoLayersDeep: {
name: 'deeper',
},
data: 'data',
},
};
export const invalidData = {
username: '__',
password: 'invalid-password',
deepObject: {
data: 233,
twoLayersDeep: { name: 123 },
},
};
export const invalidDataWithUndefined = {
username: 'jsun969',
password: undefined,
deepObject: {
twoLayersDeep: {
name: 'deeper',
},
data: undefined,
},
};
export const fields: Record<InternalFieldName, Field['_f']> = {
username: {
ref: { name: 'username' },
name: 'username',
},
password: {
ref: { name: 'password' },
name: 'password',
},
email: {
ref: { name: 'email' },
name: 'email',
},
birthday: {
ref: { name: 'birthday' },
name: 'birthday',
},
};

View File

@ -1,462 +0,0 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`ajvResolver with errorMessage > should return a default message if there is no specific message for the error when requirement fails 1`] = `
{
"errors": {
"bar": {
"message": "data should have properties "foo" and "bar" only",
"ref": {
"name": "bar",
},
"type": "required",
"types": {
"required": "data should have properties "foo" and "bar" only",
},
},
"foo": {
"message": "data should have properties "foo" and "bar" only",
"ref": {
"name": "foo",
},
"type": "required",
"types": {
"required": "data should have properties "foo" and "bar" only",
},
},
},
"values": {},
}
`;
exports[`ajvResolver with errorMessage > should return a default message if there is no specific message for the error when some properties are undefined 1`] = `
{
"errors": {
"bar": {
"message": "data should have properties "foo" and "bar" only",
"ref": {
"name": "bar",
},
"type": "required",
"types": {
"required": "data should have properties "foo" and "bar" only",
},
},
"foo": {
"message": "data.foo should be integer >= 2",
"ref": {
"name": "foo",
},
"type": "minimum",
"types": {
"minimum": "data.foo should be integer >= 2",
},
},
},
"values": {},
}
`;
exports[`ajvResolver with errorMessage > should return a default message if there is no specific message for the error when walidation fails 1`] = `
{
"errors": {
"bar": {
"message": "data should have properties "foo" and "bar" only",
"ref": {
"name": "bar",
},
"type": "required",
"types": {
"required": "data should have properties "foo" and "bar" only",
},
},
"foo": {
"message": "data should have properties "foo" and "bar" only",
"ref": {
"name": "foo",
},
"type": "required",
"types": {
"required": "data should have properties "foo" and "bar" only",
},
},
},
"values": {},
}
`;
exports[`ajvResolver with errorMessage > should return customized error messages for certain keywords when requirement fails 1`] = `
{
"errors": {
"foo": {
"message": "should have property foo",
"ref": {
"name": "foo",
},
"type": "required",
"types": {
"required": "should have property foo",
},
},
},
"values": {},
}
`;
exports[`ajvResolver with errorMessage > should return customized error messages for certain keywords when some properties are undefined 1`] = `
{
"errors": {
"foo": {
"message": "should have property foo",
"ref": {
"name": "foo",
},
"type": "required",
"types": {
"required": "should have property foo",
},
},
},
"values": {},
}
`;
exports[`ajvResolver with errorMessage > should return customized error messages for certain keywords when walidation fails 1`] = `
{
"errors": {
"": {
"message": "should not have properties other than foo",
"ref": undefined,
"type": "additionalProperties",
"types": {
"additionalProperties": "should not have properties other than foo",
},
},
"foo": {
"message": "must be integer",
"ref": {
"name": "foo",
},
"type": "type",
"types": {
"type": "must be integer",
},
},
},
"values": {},
}
`;
exports[`ajvResolver with errorMessage > should return customized error messages when requirement fails 1`] = `
{
"errors": {
"password": {
"message": "password field is required",
"ref": {
"name": "password",
},
"type": "required",
"types": {
"required": "password field is required",
},
},
"username": {
"message": "username field is required",
"ref": {
"name": "username",
},
"type": "required",
"types": {
"required": "username field is required",
},
},
},
"values": {},
}
`;
exports[`ajvResolver with errorMessage > should return customized error messages when some properties are undefined 1`] = `
{
"errors": {
"password": {
"message": "password field is required",
"ref": {
"name": "password",
},
"type": "required",
"types": {
"required": "password field is required",
},
},
"username": {
"message": "username field is required",
"ref": {
"name": "username",
},
"type": "required",
"types": {
"required": "username field is required",
},
},
},
"values": {},
}
`;
exports[`ajvResolver with errorMessage > should return customized error messages when validation fails 1`] = `
{
"errors": {
"password": {
"message": "One uppercase character",
"ref": {
"name": "password",
},
"type": "pattern",
"types": {
"minLength": "passwords should be at least eight characters long",
"pattern": "One uppercase character",
},
},
"username": {
"message": "username should be at least three characters long",
"ref": {
"name": "username",
},
"type": "minLength",
"types": {
"minLength": "username should be at least three characters long",
},
},
},
"values": {},
}
`;
exports[`ajvResolver with errorMessage > should return customized errors for properties/items when requirement fails 1`] = `
{
"errors": {
"bar": {
"message": "must have required property 'bar'",
"ref": {
"name": "bar",
},
"type": "required",
"types": {
"required": "must have required property 'bar'",
},
},
"foo": {
"message": "must have required property 'foo'",
"ref": {
"name": "foo",
},
"type": "required",
"types": {
"required": "must have required property 'foo'",
},
},
},
"values": {},
}
`;
exports[`ajvResolver with errorMessage > should return customized errors for properties/items when some properties are undefined 1`] = `
{
"errors": {
"bar": {
"message": "must have required property 'bar'",
"ref": {
"name": "bar",
},
"type": "required",
"types": {
"required": "must have required property 'bar'",
},
},
"foo": {
"message": "must have required property 'foo'",
"ref": {
"name": "foo",
},
"type": "required",
"types": {
"required": "must have required property 'foo'",
},
},
},
"values": {},
}
`;
exports[`ajvResolver with errorMessage > should return customized errors for properties/items when walidation fails 1`] = `
{
"errors": {
"bar": {
"message": "data.bar should be string with length >= 2",
"ref": {
"name": "bar",
},
"type": "minLength",
"types": {
"minLength": "data.bar should be string with length >= 2",
},
},
"foo": {
"message": "data.foo should be integer >= 2",
"ref": {
"name": "foo",
},
"type": "minimum",
"types": {
"minimum": "data.foo should be integer >= 2",
},
},
},
"values": {},
}
`;
exports[`ajvResolver with errorMessage > should return different messages for different properties when requirement fails 1`] = `
{
"errors": {
"bar": {
"message": "should have a string property "bar"",
"ref": {
"name": "bar",
},
"type": "required",
"types": {
"required": "should have a string property "bar"",
},
},
"foo": {
"message": "should have an integer property "foo"",
"ref": {
"name": "foo",
},
"type": "required",
"types": {
"required": "should have an integer property "foo"",
},
},
},
"values": {},
}
`;
exports[`ajvResolver with errorMessage > should return different messages for different properties when some properties are undefined 1`] = `
{
"errors": {
"bar": {
"message": "should have a string property "bar"",
"ref": {
"name": "bar",
},
"type": "required",
"types": {
"required": "should have a string property "bar"",
},
},
"foo": {
"message": "should have an integer property "foo"",
"ref": {
"name": "foo",
},
"type": "required",
"types": {
"required": "should have an integer property "foo"",
},
},
},
"values": {},
}
`;
exports[`ajvResolver with errorMessage > should return different messages for different properties when walidation fails 1`] = `
{
"errors": {
"bar": {
"message": "must be string",
"ref": {
"name": "bar",
},
"type": "type",
"types": {
"type": "must be string",
},
},
"foo": {
"message": "must be integer",
"ref": {
"name": "foo",
},
"type": "type",
"types": {
"type": "must be integer",
},
},
},
"values": {},
}
`;
exports[`ajvResolver with errorMessage > should return the same customized error message when requirement fails 1`] = `
{
"errors": {
"foo": {
"message": "should be an object with an integer property foo only",
"ref": {
"name": "foo",
},
"type": "required",
"types": {
"required": "should be an object with an integer property foo only",
},
},
},
"values": {},
}
`;
exports[`ajvResolver with errorMessage > should return the same customized message for all validation failures 1`] = `
{
"errors": {
"": {
"message": "should be an object with an integer property foo only",
"ref": undefined,
"type": "additionalProperties",
"types": {
"additionalProperties": "should be an object with an integer property foo only",
},
},
"foo": {
"message": "should be an object with an integer property foo only",
"ref": {
"name": "foo",
},
"type": "type",
"types": {
"type": "should be an object with an integer property foo only",
},
},
},
"values": {},
}
`;
exports[`ajvResolver with errorMessage > should return the same customized message when some properties are undefined 1`] = `
{
"errors": {
"foo": {
"message": "should be an object with an integer property foo only",
"ref": {
"name": "foo",
},
"type": "required",
"types": {
"required": "should be an object with an integer property foo only",
},
},
},
"values": {},
}
`;

View File

@ -1,245 +0,0 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`ajvResolver > should return all the error messages from ajvResolver when requirement fails and validateAllFieldCriteria set to true 1`] = `
{
"errors": {
"deepObject": {
"message": "must have required property 'deepObject'",
"ref": undefined,
"type": "required",
},
"password": {
"message": "must have required property 'password'",
"ref": {
"name": "password",
},
"type": "required",
},
"username": {
"message": "must have required property 'username'",
"ref": {
"name": "username",
},
"type": "required",
},
},
"values": {},
}
`;
exports[`ajvResolver > should return all the error messages from ajvResolver when requirement fails and validateAllFieldCriteria set to true and \`mode: sync\` 1`] = `
{
"errors": {
"deepObject": {
"message": "must have required property 'deepObject'",
"ref": undefined,
"type": "required",
},
"password": {
"message": "must have required property 'password'",
"ref": {
"name": "password",
},
"type": "required",
},
"username": {
"message": "must have required property 'username'",
"ref": {
"name": "username",
},
"type": "required",
},
},
"values": {},
}
`;
exports[`ajvResolver > should return all the error messages from ajvResolver when some property is undefined and result will keep the input data structure 1`] = `
{
"errors": {
"deepObject": {
"data": {
"message": "must have required property 'data'",
"ref": undefined,
"type": "required",
},
},
"password": {
"message": "must have required property 'password'",
"ref": {
"name": "password",
},
"type": "required",
},
},
"values": {},
}
`;
exports[`ajvResolver > should return all the error messages from ajvResolver when validation fails and validateAllFieldCriteria set to true 1`] = `
{
"errors": {
"deepObject": {
"data": {
"message": "must be string",
"ref": undefined,
"type": "type",
"types": {
"type": "must be string",
},
},
"twoLayersDeep": {
"name": {
"message": "must be string",
"ref": undefined,
"type": "type",
"types": {
"type": "must be string",
},
},
},
},
"password": {
"message": "One uppercase character",
"ref": {
"name": "password",
},
"type": "pattern",
"types": {
"pattern": "One uppercase character",
},
},
"username": {
"message": "must NOT have fewer than 3 characters",
"ref": {
"name": "username",
},
"type": "minLength",
"types": {
"minLength": "must NOT have fewer than 3 characters",
},
},
},
"values": {},
}
`;
exports[`ajvResolver > should return all the error messages from ajvResolver when validation fails and validateAllFieldCriteria set to true and \`mode: sync\` 1`] = `
{
"errors": {
"deepObject": {
"data": {
"message": "must be string",
"ref": undefined,
"type": "type",
"types": {
"type": "must be string",
},
},
"twoLayersDeep": {
"name": {
"message": "must be string",
"ref": undefined,
"type": "type",
"types": {
"type": "must be string",
},
},
},
},
"password": {
"message": "One uppercase character",
"ref": {
"name": "password",
},
"type": "pattern",
"types": {
"pattern": "One uppercase character",
},
},
"username": {
"message": "must NOT have fewer than 3 characters",
"ref": {
"name": "username",
},
"type": "minLength",
"types": {
"minLength": "must NOT have fewer than 3 characters",
},
},
},
"values": {},
}
`;
exports[`ajvResolver > should return single error message from ajvResolver when validation fails and validateAllFieldCriteria set to false 1`] = `
{
"errors": {
"deepObject": {
"data": {
"message": "must be string",
"ref": undefined,
"type": "type",
},
"twoLayersDeep": {
"name": {
"message": "must be string",
"ref": undefined,
"type": "type",
},
},
},
"password": {
"message": "One uppercase character",
"ref": {
"name": "password",
},
"type": "pattern",
},
"username": {
"message": "must NOT have fewer than 3 characters",
"ref": {
"name": "username",
},
"type": "minLength",
},
},
"values": {},
}
`;
exports[`ajvResolver > should return single error message from ajvResolver when validation fails and validateAllFieldCriteria set to false and \`mode: sync\` 1`] = `
{
"errors": {
"deepObject": {
"data": {
"message": "must be string",
"ref": undefined,
"type": "type",
},
"twoLayersDeep": {
"name": {
"message": "must be string",
"ref": undefined,
"type": "type",
},
},
},
"password": {
"message": "One uppercase character",
"ref": {
"name": "password",
},
"type": "pattern",
},
"username": {
"message": "must NOT have fewer than 3 characters",
"ref": {
"name": "username",
},
"type": "minLength",
},
},
"values": {},
}
`;

View File

@ -1,227 +0,0 @@
import { ajvResolver } from '..';
import * as fixture from './__fixtures__/data-errors';
const shouldUseNativeValidation = false;
describe('ajvResolver with errorMessage', () => {
it('should return values when validation pass', async () => {
expect(
await ajvResolver(fixture.schemaA)(fixture.validDataA, undefined, {
fields: fixture.fieldsA,
criteriaMode: 'all',
shouldUseNativeValidation,
}),
).toEqual({
values: fixture.validDataA,
errors: {},
});
});
it('should return customized error messages when validation fails', async () => {
expect(
await ajvResolver(fixture.schemaA)(
fixture.invalidDataA,
{},
{
fields: fixture.fieldsA,
criteriaMode: 'all',
shouldUseNativeValidation,
},
),
).toMatchSnapshot();
});
it('should return customized error messages when requirement fails', async () => {
expect(
await ajvResolver(fixture.schemaA)({}, undefined, {
fields: fixture.fieldsA,
criteriaMode: 'all',
shouldUseNativeValidation,
}),
).toMatchSnapshot();
});
it('should return customized error messages when some properties are undefined', async () => {
expect(
await ajvResolver(fixture.schemaA, undefined, { mode: 'sync' })(
fixture.undefinedDataA,
undefined,
{
fields: fixture.fieldsA,
criteriaMode: 'all',
shouldUseNativeValidation,
},
),
).toMatchSnapshot();
});
it('should return the same customized message for all validation failures', async () => {
expect(
await ajvResolver(fixture.schemaB)(
fixture.invalidDataB,
{},
{
fields: fixture.fieldsRest,
criteriaMode: 'all',
shouldUseNativeValidation,
},
),
).toMatchSnapshot();
});
it('should return the same customized error message when requirement fails', async () => {
expect(
await ajvResolver(fixture.schemaB)({}, undefined, {
fields: fixture.fieldsRest,
criteriaMode: 'all',
shouldUseNativeValidation,
}),
).toMatchSnapshot();
});
it('should return the same customized message when some properties are undefined', async () => {
expect(
await ajvResolver(fixture.schemaB)(fixture.undefinedDataB, undefined, {
fields: fixture.fieldsRest,
criteriaMode: 'all',
shouldUseNativeValidation,
}),
).toMatchSnapshot();
});
it('should return customized error messages for certain keywords when walidation fails', async () => {
expect(
await ajvResolver(fixture.schemaC)(
fixture.invalidDataC,
{},
{
fields: fixture.fieldsRest,
criteriaMode: 'all',
shouldUseNativeValidation,
},
),
).toMatchSnapshot();
});
it('should return customized error messages for certain keywords when requirement fails', async () => {
expect(
await ajvResolver(fixture.schemaC)({}, undefined, {
fields: fixture.fieldsRest,
criteriaMode: 'all',
shouldUseNativeValidation,
}),
).toMatchSnapshot();
});
it('should return customized error messages for certain keywords when some properties are undefined', async () => {
expect(
await ajvResolver(fixture.schemaC)(fixture.undefinedDataC, undefined, {
fields: fixture.fieldsRest,
criteriaMode: 'all',
shouldUseNativeValidation,
}),
).toMatchSnapshot();
});
it('should return different messages for different properties when walidation fails', async () => {
expect(
await ajvResolver(fixture.schemaD)(
fixture.invalidDataD,
{},
{
fields: fixture.fieldsRest,
criteriaMode: 'all',
shouldUseNativeValidation,
},
),
).toMatchSnapshot();
});
it('should return different messages for different properties when requirement fails', async () => {
expect(
await ajvResolver(fixture.schemaD)({}, undefined, {
fields: fixture.fieldsRest,
criteriaMode: 'all',
shouldUseNativeValidation,
}),
).toMatchSnapshot();
});
it('should return different messages for different properties when some properties are undefined', async () => {
expect(
await ajvResolver(fixture.schemaD)(fixture.undefinedDataD, undefined, {
fields: fixture.fieldsRest,
criteriaMode: 'all',
shouldUseNativeValidation,
}),
).toMatchSnapshot();
});
it('should return customized errors for properties/items when walidation fails', async () => {
expect(
await ajvResolver(fixture.schemaE)(
fixture.invalidDataE,
{},
{
fields: fixture.fieldsRest,
criteriaMode: 'all',
shouldUseNativeValidation,
},
),
).toMatchSnapshot();
});
it('should return customized errors for properties/items when requirement fails', async () => {
expect(
await ajvResolver(fixture.schemaE)({}, undefined, {
fields: fixture.fieldsRest,
criteriaMode: 'all',
shouldUseNativeValidation,
}),
).toMatchSnapshot();
});
it('should return customized errors for properties/items when some properties are undefined', async () => {
expect(
await ajvResolver(fixture.schemaE)(fixture.undefinedDataE, undefined, {
fields: fixture.fieldsRest,
criteriaMode: 'all',
shouldUseNativeValidation,
}),
).toMatchSnapshot();
});
it('should return a default message if there is no specific message for the error when walidation fails', async () => {
expect(
await ajvResolver(fixture.schemaF)(
fixture.invalidDataF,
{},
{
fields: fixture.fieldsRest,
criteriaMode: 'all',
shouldUseNativeValidation,
},
),
).toMatchSnapshot();
});
it('should return a default message if there is no specific message for the error when requirement fails', async () => {
expect(
await ajvResolver(fixture.schemaF)({}, undefined, {
fields: fixture.fieldsRest,
criteriaMode: 'all',
shouldUseNativeValidation,
}),
).toMatchSnapshot();
});
it('should return a default message if there is no specific message for the error when some properties are undefined', async () => {
expect(
await ajvResolver(fixture.schemaF)(fixture.undefinedDataF, undefined, {
fields: fixture.fieldsRest,
criteriaMode: 'all',
shouldUseNativeValidation,
}),
).toMatchSnapshot();
});
});

View File

@ -1,103 +0,0 @@
import { ajvResolver } from '..';
import {
fields,
invalidData,
invalidDataWithUndefined,
schema,
validData,
} from './__fixtures__/data';
const shouldUseNativeValidation = false;
describe('ajvResolver', () => {
it('should return values from ajvResolver when validation pass', async () => {
expect(
await ajvResolver(schema)(validData, undefined, {
fields,
shouldUseNativeValidation,
}),
).toEqual({
values: validData,
errors: {},
});
});
it('should return values from ajvResolver with `mode: sync` when validation pass', async () => {
expect(
await ajvResolver(schema, undefined, {
mode: 'sync',
})(validData, undefined, { fields, shouldUseNativeValidation }),
).toEqual({
values: validData,
errors: {},
});
});
it('should return single error message from ajvResolver when validation fails and validateAllFieldCriteria set to false', async () => {
expect(
await ajvResolver(schema)(invalidData, undefined, {
fields,
shouldUseNativeValidation,
}),
).toMatchSnapshot();
});
it('should return single error message from ajvResolver when validation fails and validateAllFieldCriteria set to false and `mode: sync`', async () => {
expect(
await ajvResolver(schema, undefined, {
mode: 'sync',
})(invalidData, undefined, { fields, shouldUseNativeValidation }),
).toMatchSnapshot();
});
it('should return all the error messages from ajvResolver when validation fails and validateAllFieldCriteria set to true', async () => {
expect(
await ajvResolver(schema)(
invalidData,
{},
{ fields, criteriaMode: 'all', shouldUseNativeValidation },
),
).toMatchSnapshot();
});
it('should return all the error messages from ajvResolver when validation fails and validateAllFieldCriteria set to true and `mode: sync`', async () => {
expect(
await ajvResolver(schema, undefined, { mode: 'sync' })(
invalidData,
{},
{ fields, criteriaMode: 'all', shouldUseNativeValidation },
),
).toMatchSnapshot();
});
it('should return all the error messages from ajvResolver when requirement fails and validateAllFieldCriteria set to true', async () => {
expect(
await ajvResolver(schema)({}, undefined, {
fields,
shouldUseNativeValidation,
}),
).toMatchSnapshot();
});
it('should return all the error messages from ajvResolver when requirement fails and validateAllFieldCriteria set to true and `mode: sync`', async () => {
expect(
await ajvResolver(schema, undefined, { mode: 'sync' })({}, undefined, {
fields,
shouldUseNativeValidation,
}),
).toMatchSnapshot();
});
it('should return all the error messages from ajvResolver when some property is undefined and result will keep the input data structure', async () => {
expect(
await ajvResolver(schema, undefined, { mode: 'sync' })(
invalidDataWithUndefined,
undefined,
{
fields,
shouldUseNativeValidation,
},
),
).toMatchSnapshot();
});
});

View File

@ -1,121 +0,0 @@
import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
import Ajv, { DefinedError } from 'ajv';
import ajvErrors from 'ajv-errors';
import { FieldError, appendErrors } from 'react-hook-form';
import { AjvError, Resolver } from './types';
const parseErrorSchema = (
ajvErrors: AjvError[],
validateAllFieldCriteria: boolean,
) => {
const parsedErrors: Record<string, FieldError> = {};
const reduceError = (error: AjvError) => {
// Ajv will return empty instancePath when require error
if (error.keyword === 'required') {
error.instancePath += `/${error.params.missingProperty}`;
}
// `/deepObject/data` -> `deepObject.data`
const path = error.instancePath.substring(1).replace(/\//g, '.');
if (!parsedErrors[path]) {
parsedErrors[path] = {
message: error.message,
type: error.keyword,
};
}
if (validateAllFieldCriteria) {
const types = parsedErrors[path].types;
const messages = types && types[error.keyword];
parsedErrors[path] = appendErrors(
path,
validateAllFieldCriteria,
parsedErrors,
error.keyword,
messages
? ([] as string[]).concat(messages as string[], error.message || '')
: error.message,
) as FieldError;
}
};
for (let index = 0; index < ajvErrors.length; index += 1) {
const error = ajvErrors[index];
if (error.keyword === 'errorMessage') {
error.params.errors.forEach((originalError) => {
originalError.message = error.message;
reduceError(originalError);
});
} else {
reduceError(error);
}
}
return parsedErrors;
};
/**
* Creates a resolver for react-hook-form using Ajv schema validation
* @param {Schema} schema - The Ajv schema to validate against
* @param {Object} schemaOptions - Additional schema validation options
* @param {Object} resolverOptions - Additional resolver configuration
* @param {string} [resolverOptions.mode='async'] - Validation mode
* @returns {Resolver<Schema>} A resolver function compatible with react-hook-form
* @example
* const schema = ajv.compile({
* type: 'object',
* properties: {
* name: { type: 'string' },
* age: { type: 'number' }
* }
* });
*
* useForm({
* resolver: ajvResolver(schema)
* });
*/
export const ajvResolver: Resolver =
(schema, schemaOptions, resolverOptions = {}) =>
async (values, _, options) => {
const ajv = new Ajv(
Object.assign(
{},
{
allErrors: true,
validateSchema: true,
},
schemaOptions,
),
);
ajvErrors(ajv);
const validate = ajv.compile(
Object.assign(
{ $async: resolverOptions && resolverOptions.mode === 'async' },
schema,
),
);
const valid = validate(values);
options.shouldUseNativeValidation && validateFieldsNatively({}, options);
return valid
? { values, errors: {} }
: {
values: {},
errors: toNestErrors(
parseErrorSchema(
validate.errors as DefinedError[],
!options.shouldUseNativeValidation &&
options.criteriaMode === 'all',
),
options,
),
};
};

View File

@ -1,2 +0,0 @@
export * from './ajv';
export * from './types';

View File

@ -1,20 +0,0 @@
import * as Ajv from 'ajv';
import type { DefinedError, ErrorObject } from 'ajv';
import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
export type Resolver = <T>(
schema: Ajv.JSONSchemaType<T>,
schemaOptions?: Ajv.Options,
factoryOptions?: { mode?: 'async' | 'sync' },
) => <TFieldValues extends FieldValues, TContext>(
values: TFieldValues,
context: TContext | undefined,
options: ResolverOptions<TFieldValues>,
) => Promise<ResolverResult<TFieldValues>>;
// ajv doesn't export any types for errors with `keyword='errorMessage'`
type ErrorMessage = ErrorObject<
'errorMessage',
{ errors: (DefinedError & { emUsed: boolean })[] }
>;
export type AjvError = ErrorMessage | DefinedError;

View File

@ -1,18 +0,0 @@
{
"name": "@hookform/resolvers/arktype",
"amdName": "hookformResolversArktype",
"version": "2.0.0",
"private": true,
"description": "React Hook Form validation resolver: arktype",
"main": "dist/arktype.js",
"module": "dist/arktype.module.js",
"umd:main": "dist/arktype.umd.js",
"source": "src/index.ts",
"types": "dist/index.d.ts",
"license": "MIT",
"peerDependencies": {
"react-hook-form": "^7.55.0",
"@hookform/resolvers": "^2.0.0",
"arktype": "^2.0.0"
}
}

View File

@ -1,82 +0,0 @@
import { render, screen } from '@testing-library/react';
import user from '@testing-library/user-event';
import { type } from 'arktype';
import React from 'react';
import { useForm } from 'react-hook-form';
import { arktypeResolver } from '..';
const schema = type({
username: 'string>1',
password: 'string>1',
});
type FormData = typeof schema.infer;
interface Props {
onSubmit: (data: FormData) => void;
}
function TestComponent({ onSubmit }: Props) {
const { register, handleSubmit } = useForm<FormData>({
resolver: arktypeResolver(schema),
shouldUseNativeValidation: true,
});
return (
<form onSubmit={handleSubmit(onSubmit)}>
<input {...register('username')} placeholder="username" />
<input {...register('password')} placeholder="password" />
<button type="submit">submit</button>
</form>
);
}
test("form's native validation with Arktype", async () => {
const handleSubmit = vi.fn();
render(<TestComponent onSubmit={handleSubmit} />);
// username
let usernameField = screen.getByPlaceholderText(
/username/i,
) as HTMLInputElement;
expect(usernameField.validity.valid).toBe(true);
expect(usernameField.validationMessage).toBe('');
// password
let passwordField = screen.getByPlaceholderText(
/password/i,
) as HTMLInputElement;
expect(passwordField.validity.valid).toBe(true);
expect(passwordField.validationMessage).toBe('');
await user.click(screen.getByText(/submit/i));
// username
usernameField = screen.getByPlaceholderText(/username/i) as HTMLInputElement;
expect(usernameField.validity.valid).toBe(false);
expect(usernameField.validationMessage).toBe(
'username must be at least length 2',
);
// password
passwordField = screen.getByPlaceholderText(/password/i) as HTMLInputElement;
expect(passwordField.validity.valid).toBe(false);
expect(passwordField.validationMessage).toBe(
'password must be at least length 2',
);
await user.type(screen.getByPlaceholderText(/username/i), 'joe');
await user.type(screen.getByPlaceholderText(/password/i), 'password');
// username
usernameField = screen.getByPlaceholderText(/username/i) as HTMLInputElement;
expect(usernameField.validity.valid).toBe(true);
expect(usernameField.validationMessage).toBe('');
// password
passwordField = screen.getByPlaceholderText(/password/i) as HTMLInputElement;
expect(passwordField.validity.valid).toBe(true);
expect(passwordField.validationMessage).toBe('');
});

View File

@ -1,54 +0,0 @@
import { render, screen } from '@testing-library/react';
import user from '@testing-library/user-event';
import { type } from 'arktype';
import React from 'react';
import { useForm } from 'react-hook-form';
import { arktypeResolver } from '..';
const schema = type({
username: 'string>1',
password: 'string>1',
});
function TestComponent({
onSubmit,
}: {
onSubmit: (data: typeof schema.infer) => void;
}) {
const {
register,
handleSubmit,
formState: { errors },
} = useForm({
resolver: arktypeResolver(schema), // Useful to check TypeScript regressions
});
return (
<form onSubmit={handleSubmit(onSubmit)}>
<input {...register('username')} />
{errors.username && <span role="alert">{errors.username.message}</span>}
<input {...register('password')} />
{errors.password && <span role="alert">{errors.password.message}</span>}
<button type="submit">submit</button>
</form>
);
}
test("form's validation with arkType and TypeScript's integration", async () => {
const handleSubmit = vi.fn();
render(<TestComponent onSubmit={handleSubmit} />);
expect(screen.queryAllByRole('alert')).toHaveLength(0);
await user.click(screen.getByText(/submit/i));
expect(
screen.getByText('username must be at least length 2'),
).toBeInTheDocument();
expect(
screen.getByText('password must be at least length 2'),
).toBeInTheDocument();
expect(handleSubmit).not.toHaveBeenCalled();
});

View File

@ -1,65 +0,0 @@
import { type } from 'arktype';
import { Field, InternalFieldName } from 'react-hook-form';
export const schema = type({
username: 'string>2',
password: '/.*[A-Za-z].*/>8|/.*\\d.*/',
repeatPassword: 'string>1',
accessToken: 'string|number',
birthYear: '1900<number<2013',
email: 'string.email',
tags: 'string[]',
enabled: 'boolean',
url: 'string>1',
'like?': type({
id: 'number',
name: 'string>3',
}).array(),
dateStr: 'Date',
});
export const validData: typeof schema.infer = {
username: 'Doe',
password: 'Password123_',
repeatPassword: 'Password123_',
birthYear: 2000,
email: 'john@doe.com',
tags: ['tag1', 'tag2'],
enabled: true,
accessToken: 'accessToken',
url: 'https://react-hook-form.com/',
like: [
{
id: 1,
name: 'name',
},
],
dateStr: new Date('2020-01-01'),
};
export const invalidData = {
password: '___',
email: '',
birthYear: 'birthYear',
like: [{ id: 'z' }],
url: 'abc',
} as any as typeof schema.infer;
export const fields: Record<InternalFieldName, Field['_f']> = {
username: {
ref: { name: 'username' },
name: 'username',
},
password: {
ref: { name: 'password' },
name: 'password',
},
email: {
ref: { name: 'email' },
name: 'email',
},
birthday: {
ref: { name: 'birthday' },
name: 'birthday',
},
};

View File

@ -1,74 +0,0 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`arktypeResolver > should return a single error from arktypeResolver when validation fails 1`] = `
{
"errors": {
"accessToken": {
"message": "accessToken must be a number or a string (was missing)",
"ref": undefined,
"type": "required",
},
"birthYear": {
"message": "birthYear must be a number (was a string)",
"ref": undefined,
"type": "domain",
},
"dateStr": {
"message": "dateStr must be a Date (was missing)",
"ref": undefined,
"type": "required",
},
"email": {
"message": "email must be an email address (was "")",
"ref": {
"name": "email",
},
"type": "pattern",
},
"enabled": {
"message": "enabled must be boolean (was missing)",
"ref": undefined,
"type": "required",
},
"like": [
{
"id": {
"message": "like[0].id must be a number (was a string)",
"ref": undefined,
"type": "domain",
},
"name": {
"message": "like[0].name must be a string (was missing)",
"ref": undefined,
"type": "required",
},
},
],
"password": {
"message": "password must be matched by .*[A-Za-z].* or matched by .*\\d.* (was "___")",
"ref": {
"name": "password",
},
"type": "union",
},
"repeatPassword": {
"message": "repeatPassword must be a string (was missing)",
"ref": undefined,
"type": "required",
},
"tags": {
"message": "tags must be an array (was missing)",
"ref": undefined,
"type": "required",
},
"username": {
"message": "username must be a string (was missing)",
"ref": {
"name": "username",
},
"type": "required",
},
},
"values": {},
}
`;

View File

@ -1,82 +0,0 @@
import { type } from 'arktype';
import { Resolver, useForm } from 'react-hook-form';
import { SubmitHandler } from 'react-hook-form';
import { arktypeResolver } from '..';
import { fields, invalidData, schema, validData } from './__fixtures__/data';
const shouldUseNativeValidation = false;
describe('arktypeResolver', () => {
it('should return values from arktypeResolver when validation pass & raw=true', async () => {
const result = await arktypeResolver(schema, undefined, {
raw: true,
})(validData, undefined, {
fields,
shouldUseNativeValidation,
});
expect(result).toEqual({ errors: {}, values: validData });
});
it('should return a single error from arktypeResolver when validation fails', async () => {
const result = await arktypeResolver(schema)(invalidData, undefined, {
fields,
shouldUseNativeValidation,
});
expect(result).toMatchSnapshot();
});
/**
* Type inference tests
*/
it('should correctly infer the output type from a arktype schema', () => {
const resolver = arktypeResolver(type({ id: 'number' }));
expectTypeOf(resolver).toEqualTypeOf<
Resolver<{ id: number }, unknown, { id: number }>
>();
});
it('should correctly infer the output type from a arktype schema using a transform', () => {
const resolver = arktypeResolver(
type({ id: type('string').pipe((s) => Number.parseInt(s)) }),
);
expectTypeOf(resolver).toEqualTypeOf<
Resolver<{ id: string }, unknown, { id: number }>
>();
});
it('should correctly infer the output type from a arktype schema for the handleSubmit function in useForm', () => {
const schema = type({ id: 'number' });
const form = useForm({
resolver: arktypeResolver(schema),
});
expectTypeOf(form.watch('id')).toEqualTypeOf<number>();
expectTypeOf(form.handleSubmit).parameter(0).toEqualTypeOf<
SubmitHandler<{
id: number;
}>
>();
});
it('should correctly infer the output type from a arktype schema with a transform for the handleSubmit function in useForm', () => {
const schema = type({ id: type('string').pipe((s) => Number.parseInt(s)) });
const form = useForm({
resolver: arktypeResolver(schema),
});
expectTypeOf(form.watch('id')).toEqualTypeOf<string>();
expectTypeOf(form.handleSubmit).parameter(0).toEqualTypeOf<
SubmitHandler<{
id: number;
}>
>();
});
});

View File

@ -1,98 +0,0 @@
import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
import { StandardSchemaV1 } from '@standard-schema/spec';
import { getDotPath } from '@standard-schema/utils';
import { FieldError, FieldValues, Resolver } from 'react-hook-form';
function parseErrorSchema(
issues: readonly StandardSchemaV1.Issue[],
validateAllFieldCriteria: boolean,
) {
const errors: Record<string, FieldError> = {};
for (let i = 0; i < issues.length; i++) {
const error = issues[i];
const path = getDotPath(error);
if (path) {
if (!errors[path]) {
errors[path] = { message: error.message, type: '' };
}
if (validateAllFieldCriteria) {
const types = errors[path].types || {};
errors[path].types = {
...types,
[Object.keys(types).length]: error.message,
};
}
}
}
return errors;
}
export function arktypeResolver<Input extends FieldValues, Context, Output>(
schema: StandardSchemaV1<Input, Output>,
_schemaOptions?: never,
resolverOptions?: {
raw?: false;
},
): Resolver<Input, Context, Output>;
export function arktypeResolver<Input extends FieldValues, Context, Output>(
schema: StandardSchemaV1<Input, Output>,
_schemaOptions: never | undefined,
resolverOptions: {
raw: true;
},
): Resolver<Input, Context, Input>;
/**
* Creates a resolver for react-hook-form using Arktype schema validation
* @param {Schema} schema - The Arktype schema to validate against
* @param {Object} resolverOptions - Additional resolver configuration
* @param {string} [resolverOptions.mode='raw'] - Return the raw input values rather than the parsed values
* @returns {Resolver<Schema['inferOut']>} A resolver function compatible with react-hook-form
* @example
* const schema = type({
* username: 'string>2'
* });
*
* useForm({
* resolver: arktypeResolver(schema)
* });
*/
export function arktypeResolver<Input extends FieldValues, Context, Output>(
schema: StandardSchemaV1<Input, Output>,
_schemaOptions?: never,
resolverOptions: {
raw?: boolean;
} = {},
): Resolver<Input, Context, Input | Output> {
return async (values: Input, _, options) => {
let result = schema['~standard'].validate(values);
if (result instanceof Promise) {
result = await result;
}
if (result.issues) {
const errors = parseErrorSchema(
result.issues,
!options.shouldUseNativeValidation && options.criteriaMode === 'all',
);
return {
values: {},
errors: toNestErrors(errors, options),
};
}
options.shouldUseNativeValidation && validateFieldsNatively({}, options);
return {
values: resolverOptions.raw ? Object.assign({}, values) : result.value,
errors: {},
};
};
}

View File

@ -1 +0,0 @@
export * from './arktype';

View File

@ -1,19 +0,0 @@
{
"name": "@hookform/resolvers/class-validator",
"amdName": "hookformResolversClassValidator",
"version": "1.0.0",
"private": true,
"description": "React Hook Form validation resolver: class-validator",
"main": "dist/class-validator.js",
"module": "dist/class-validator.module.js",
"umd:main": "dist/class-validator.umd.js",
"source": "src/index.ts",
"types": "dist/index.d.ts",
"license": "MIT",
"peerDependencies": {
"react-hook-form": ">=6.6.0",
"@hookform/resolvers": ">=2.0.0",
"class-transformer": "^0.4.0",
"class-validator": "^0.12.0"
}
}

View File

@ -1,79 +0,0 @@
import { render, screen } from '@testing-library/react';
import user from '@testing-library/user-event';
import { IsNotEmpty } from 'class-validator';
import React from 'react';
import { SubmitHandler, useForm } from 'react-hook-form';
import { classValidatorResolver } from '..';
class Schema {
@IsNotEmpty()
username: string;
@IsNotEmpty()
password: string;
}
interface Props {
onSubmit: SubmitHandler<Schema>;
}
function TestComponent({ onSubmit }: Props) {
const { register, handleSubmit } = useForm<Schema>({
resolver: classValidatorResolver(Schema),
shouldUseNativeValidation: true,
});
return (
<form onSubmit={handleSubmit(onSubmit)}>
<input {...register('username')} placeholder="username" />
<input {...register('password')} placeholder="password" />
<button type="submit">submit</button>
</form>
);
}
test("form's native validation with Class Validator", async () => {
const handleSubmit = vi.fn();
render(<TestComponent onSubmit={handleSubmit} />);
// username
let usernameField = screen.getByPlaceholderText(
/username/i,
) as HTMLInputElement;
expect(usernameField.validity.valid).toBe(true);
expect(usernameField.validationMessage).toBe('');
// password
let passwordField = screen.getByPlaceholderText(
/password/i,
) as HTMLInputElement;
expect(passwordField.validity.valid).toBe(true);
expect(passwordField.validationMessage).toBe('');
await user.click(screen.getByText(/submit/i));
// username
usernameField = screen.getByPlaceholderText(/username/i) as HTMLInputElement;
expect(usernameField.validity.valid).toBe(false);
expect(usernameField.validationMessage).toBe('username should not be empty');
// password
passwordField = screen.getByPlaceholderText(/password/i) as HTMLInputElement;
expect(passwordField.validity.valid).toBe(false);
expect(passwordField.validationMessage).toBe('password should not be empty');
await user.type(screen.getByPlaceholderText(/username/i), 'joe');
await user.type(screen.getByPlaceholderText(/password/i), 'password');
// username
usernameField = screen.getByPlaceholderText(/username/i) as HTMLInputElement;
expect(usernameField.validity.valid).toBe(true);
expect(usernameField.validationMessage).toBe('');
// password
passwordField = screen.getByPlaceholderText(/password/i) as HTMLInputElement;
expect(passwordField.validity.valid).toBe(true);
expect(passwordField.validationMessage).toBe('');
});

View File

@ -1,53 +0,0 @@
import { render, screen } from '@testing-library/react';
import user from '@testing-library/user-event';
import { IsNotEmpty } from 'class-validator';
import React from 'react';
import { SubmitHandler, useForm } from 'react-hook-form';
import { classValidatorResolver } from '..';
class Schema {
@IsNotEmpty()
username: string;
@IsNotEmpty()
password: string;
}
interface Props {
onSubmit: SubmitHandler<Schema>;
}
function TestComponent({ onSubmit }: Props) {
const {
register,
formState: { errors },
handleSubmit,
} = useForm<Schema>({
resolver: classValidatorResolver(Schema),
});
return (
<form onSubmit={handleSubmit(onSubmit)}>
<input {...register('username')} />
{errors.username && <span role="alert">{errors.username.message}</span>}
<input {...register('password')} />
{errors.password && <span role="alert">{errors.password.message}</span>}
<button type="submit">submit</button>
</form>
);
}
test("form's validation with Class Validator and TypeScript's integration", async () => {
const handleSubmit = vi.fn();
render(<TestComponent onSubmit={handleSubmit} />);
expect(screen.queryAllByRole('alert')).toHaveLength(0);
await user.click(screen.getByText(/submit/i));
expect(screen.getByText(/username should not be empty/i)).toBeInTheDocument();
expect(screen.getByText(/password should not be empty/i)).toBeInTheDocument();
expect(handleSubmit).not.toHaveBeenCalled();
});

View File

@ -1,88 +0,0 @@
import 'reflect-metadata';
import { Type } from 'class-transformer';
import {
IsEmail,
IsNotEmpty,
Length,
Matches,
Max,
Min,
ValidateNested,
} from 'class-validator';
import { Field, InternalFieldName } from 'react-hook-form';
class Like {
@IsNotEmpty()
id: number;
@Length(4)
name: string;
}
export class Schema {
@Matches(/^\w+$/)
@Length(3, 30)
username: string;
@Matches(/^[a-zA-Z0-9]{3,30}/)
password: string;
@Min(1900)
@Max(2013)
birthYear: number;
@IsEmail()
email: string;
accessToken: string;
tags: string[];
enabled: boolean;
@ValidateNested({ each: true })
@Type(() => Like)
like: Like[];
}
export const validData: Schema = {
username: 'Doe',
password: 'Password123',
birthYear: 2000,
email: 'john@doe.com',
tags: ['tag1', 'tag2'],
enabled: true,
accessToken: 'accessToken',
like: [
{
id: 1,
name: 'name',
},
],
};
export const invalidData = {
password: '___',
email: '',
birthYear: 'birthYear',
like: [{ id: 'z' }],
} as any as Schema;
export const fields: Record<InternalFieldName, Field['_f']> = {
username: {
ref: { name: 'username' },
name: 'username',
},
password: {
ref: { name: 'password' },
name: 'password',
},
email: {
ref: { name: 'email' },
name: 'email',
},
birthday: {
ref: { name: 'birthday' },
name: 'birthday',
},
};

View File

@ -1,242 +0,0 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`classValidatorResolver > should return a single error from classValidatorResolver when validation fails 1`] = `
{
"errors": {
"birthYear": {
"message": "birthYear must not be greater than 2013",
"ref": undefined,
"type": "max",
},
"email": {
"message": "email must be an email",
"ref": {
"name": "email",
},
"type": "isEmail",
},
"like": [
{
"name": {
"message": "name must be longer than or equal to 4 characters",
"ref": undefined,
"type": "isLength",
},
},
],
"password": {
"message": "password must match /^[a-zA-Z0-9]{3,30}/ regular expression",
"ref": {
"name": "password",
},
"type": "matches",
},
"username": {
"message": "username must be longer than or equal to 3 characters",
"ref": {
"name": "username",
},
"type": "isLength",
},
},
"values": {},
}
`;
exports[`classValidatorResolver > should return a single error from classValidatorResolver with \`mode: sync\` when validation fails 1`] = `
{
"errors": {
"birthYear": {
"message": "birthYear must not be greater than 2013",
"ref": undefined,
"type": "max",
},
"email": {
"message": "email must be an email",
"ref": {
"name": "email",
},
"type": "isEmail",
},
"like": [
{
"name": {
"message": "name must be longer than or equal to 4 characters",
"ref": undefined,
"type": "isLength",
},
},
],
"password": {
"message": "password must match /^[a-zA-Z0-9]{3,30}/ regular expression",
"ref": {
"name": "password",
},
"type": "matches",
},
"username": {
"message": "username must be longer than or equal to 3 characters",
"ref": {
"name": "username",
},
"type": "isLength",
},
},
"values": {},
}
`;
exports[`classValidatorResolver > should return all the errors from classValidatorResolver when validation fails with \`validateAllFieldCriteria\` set to true 1`] = `
{
"errors": {
"birthYear": {
"message": "birthYear must not be greater than 2013",
"ref": undefined,
"type": "max",
"types": {
"max": "birthYear must not be greater than 2013",
"min": "birthYear must not be less than 1900",
},
},
"email": {
"message": "email must be an email",
"ref": {
"name": "email",
},
"type": "isEmail",
"types": {
"isEmail": "email must be an email",
},
},
"like": [
{
"name": {
"message": "name must be longer than or equal to 4 characters",
"ref": undefined,
"type": "isLength",
"types": {
"isLength": "name must be longer than or equal to 4 characters",
},
},
},
],
"password": {
"message": "password must match /^[a-zA-Z0-9]{3,30}/ regular expression",
"ref": {
"name": "password",
},
"type": "matches",
"types": {
"matches": "password must match /^[a-zA-Z0-9]{3,30}/ regular expression",
},
},
"username": {
"message": "username must be longer than or equal to 3 characters",
"ref": {
"name": "username",
},
"type": "isLength",
"types": {
"isLength": "username must be longer than or equal to 3 characters",
"matches": "username must match /^\\w+$/ regular expression",
},
},
},
"values": {},
}
`;
exports[`classValidatorResolver > should return all the errors from classValidatorResolver when validation fails with \`validateAllFieldCriteria\` set to true and \`mode: sync\` 1`] = `
{
"errors": {
"birthYear": {
"message": "birthYear must not be greater than 2013",
"ref": undefined,
"type": "max",
"types": {
"max": "birthYear must not be greater than 2013",
"min": "birthYear must not be less than 1900",
},
},
"email": {
"message": "email must be an email",
"ref": {
"name": "email",
},
"type": "isEmail",
"types": {
"isEmail": "email must be an email",
},
},
"like": [
{
"name": {
"message": "name must be longer than or equal to 4 characters",
"ref": undefined,
"type": "isLength",
"types": {
"isLength": "name must be longer than or equal to 4 characters",
},
},
},
],
"password": {
"message": "password must match /^[a-zA-Z0-9]{3,30}/ regular expression",
"ref": {
"name": "password",
},
"type": "matches",
"types": {
"matches": "password must match /^[a-zA-Z0-9]{3,30}/ regular expression",
},
},
"username": {
"message": "username must be longer than or equal to 3 characters",
"ref": {
"name": "username",
},
"type": "isLength",
"types": {
"isLength": "username must be longer than or equal to 3 characters",
"matches": "username must match /^\\w+$/ regular expression",
},
},
},
"values": {},
}
`;
exports[`validate data with transformer option 1`] = `
{
"errors": {
"random": {
"message": "All fields must be defined.",
"ref": undefined,
"type": "isDefined",
"types": {
"isDefined": "All fields must be defined.",
"isNumber": "Must be a number",
"max": "Cannot be greater than 255",
"min": "Cannot be lower than 0",
},
},
},
"values": {},
}
`;
exports[`validate data with validator option 1`] = `
{
"errors": {
"random": {
"message": "All fields must be defined.",
"ref": undefined,
"type": "isDefined",
"types": {
"isDefined": "All fields must be defined.",
},
},
},
"values": {},
}
`;

View File

@ -1,199 +0,0 @@
import { Expose, Type } from 'class-transformer';
import * as classValidator from 'class-validator';
import { IsDefined, IsNumber, Max, Min } from 'class-validator';
/* eslint-disable no-console, @typescript-eslint/ban-ts-comment */
import { classValidatorResolver } from '..';
import { Schema, fields, invalidData, validData } from './__fixtures__/data';
const shouldUseNativeValidation = false;
describe('classValidatorResolver', () => {
it('should return values from classValidatorResolver when validation pass', async () => {
const schemaSpy = vi.spyOn(classValidator, 'validate');
const schemaSyncSpy = vi.spyOn(classValidator, 'validateSync');
const result = await classValidatorResolver(Schema)(validData, undefined, {
fields,
shouldUseNativeValidation,
});
expect(schemaSpy).toHaveBeenCalledTimes(1);
expect(schemaSyncSpy).not.toHaveBeenCalled();
expect(result).toEqual({ errors: {}, values: validData });
expect(result.values).toBeInstanceOf(Schema);
});
it('should return values as a raw object from classValidatorResolver when `rawValues` set to true', async () => {
const result = await classValidatorResolver(Schema, undefined, {
raw: true,
})(validData, undefined, {
fields,
shouldUseNativeValidation,
});
expect(result).toEqual({ errors: {}, values: validData });
expect(result.values).not.toBeInstanceOf(Schema);
});
it('should return values from classValidatorResolver with `mode: sync` when validation pass', async () => {
const validateSyncSpy = vi.spyOn(classValidator, 'validateSync');
const validateSpy = vi.spyOn(classValidator, 'validate');
const result = await classValidatorResolver(Schema, undefined, {
mode: 'sync',
})(validData, undefined, { fields, shouldUseNativeValidation });
expect(validateSyncSpy).toHaveBeenCalledTimes(1);
expect(validateSpy).not.toHaveBeenCalled();
expect(result).toEqual({ errors: {}, values: validData });
expect(result.values).toBeInstanceOf(Schema);
});
it('should return a single error from classValidatorResolver when validation fails', async () => {
const result = await classValidatorResolver(Schema)(
invalidData,
undefined,
{
fields,
shouldUseNativeValidation,
},
);
expect(result).toMatchSnapshot();
});
it('should return a single error from classValidatorResolver with `mode: sync` when validation fails', async () => {
const validateSyncSpy = vi.spyOn(classValidator, 'validateSync');
const validateSpy = vi.spyOn(classValidator, 'validate');
const result = await classValidatorResolver(Schema, undefined, {
mode: 'sync',
})(invalidData, undefined, { fields, shouldUseNativeValidation });
expect(validateSyncSpy).toHaveBeenCalledTimes(1);
expect(validateSpy).not.toHaveBeenCalled();
expect(result).toMatchSnapshot();
});
it('should return all the errors from classValidatorResolver when validation fails with `validateAllFieldCriteria` set to true', async () => {
const result = await classValidatorResolver(Schema)(
invalidData,
undefined,
{
fields,
criteriaMode: 'all',
shouldUseNativeValidation,
},
);
expect(result).toMatchSnapshot();
});
it('should return all the errors from classValidatorResolver when validation fails with `validateAllFieldCriteria` set to true and `mode: sync`', async () => {
const result = await classValidatorResolver(Schema, undefined, {
mode: 'sync',
})(invalidData, undefined, {
fields,
criteriaMode: 'all',
shouldUseNativeValidation,
});
expect(result).toMatchSnapshot();
});
});
it('validate data with transformer option', async () => {
class SchemaTest {
@Expose({ groups: ['find', 'create', 'update'] })
@Type(() => Number)
@IsDefined({
message: `All fields must be defined.`,
groups: ['publish'],
})
@IsNumber({}, { message: `Must be a number`, always: true })
@Min(0, { message: `Cannot be lower than 0`, always: true })
@Max(255, { message: `Cannot be greater than 255`, always: true })
random: number;
}
const result = await classValidatorResolver(
SchemaTest,
{ transformer: { groups: ['update'] } },
{
mode: 'sync',
},
)(
// @ts-expect-error - Just for testing purposes
invalidData,
undefined,
{
fields,
criteriaMode: 'all',
shouldUseNativeValidation,
},
);
expect(result).toMatchSnapshot();
});
it('validate data with validator option', async () => {
class SchemaTest {
@Expose({ groups: ['find', 'create', 'update'] })
@Type(() => Number)
@IsDefined({
message: `All fields must be defined.`,
groups: ['publish'],
})
@IsNumber({}, { message: `Must be a number`, always: true })
@Min(0, { message: `Cannot be lower than 0`, always: true })
@Max(255, { message: `Cannot be greater than 255`, always: true })
random: number;
}
const result = await classValidatorResolver(
SchemaTest,
{ validator: { stopAtFirstError: true } },
{
mode: 'sync',
},
)(
// @ts-expect-error - Just for testing purposes
invalidData,
undefined,
{
fields,
criteriaMode: 'all',
shouldUseNativeValidation,
},
);
expect(result).toMatchSnapshot();
});
it('should return from classValidatorResolver with `excludeExtraneousValues` set to true', async () => {
class SchemaTest {
@Expose()
@IsNumber({}, { message: `Must be a number`, always: true })
random: number;
}
const result = await classValidatorResolver(SchemaTest, {
transformer: {
excludeExtraneousValues: true,
},
})(
{
random: 10,
// @ts-expect-error - Just for testing purposes
extraneousField: true,
},
undefined,
{
fields,
shouldUseNativeValidation,
},
);
expect(result).toEqual({ errors: {}, values: { random: 10 } });
expect(result.values).toBeInstanceOf(SchemaTest);
});

View File

@ -1,101 +0,0 @@
import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
import {
ClassConstructor,
ClassTransformOptions,
plainToClass,
} from 'class-transformer';
import {
ValidationError,
ValidatorOptions,
validate,
validateSync,
} from 'class-validator';
import { FieldErrors, Resolver } from 'react-hook-form';
function parseErrorSchema(
errors: ValidationError[],
validateAllFieldCriteria: boolean,
parsedErrors: FieldErrors = {},
path = '',
) {
return errors.reduce((acc, error) => {
const _path = path ? `${path}.${error.property}` : error.property;
if (error.constraints) {
const key = Object.keys(error.constraints)[0];
acc[_path] = {
type: key,
message: error.constraints[key],
};
const _e = acc[_path];
if (validateAllFieldCriteria && _e) {
Object.assign(_e, { types: error.constraints });
}
}
if (error.children && error.children.length) {
parseErrorSchema(error.children, validateAllFieldCriteria, acc, _path);
}
return acc;
}, parsedErrors);
}
/**
* Creates a resolver for react-hook-form using class-validator schema validation
* @param {ClassConstructor<Schema>} schema - The class-validator schema to validate against
* @param {Object} schemaOptions - Additional schema validation options
* @param {Object} resolverOptions - Additional resolver configuration
* @param {string} [resolverOptions.mode='async'] - Validation mode
* @returns {Resolver<Schema>} A resolver function compatible with react-hook-form
* @example
* class Schema {
* @Matches(/^\w+$/)
* @Length(3, 30)
* username: string;
* age: number
* }
*
* useForm({
* resolver: classValidatorResolver(Schema)
* });
*/
export function classValidatorResolver<Schema extends Record<string, any>>(
schema: ClassConstructor<Schema>,
schemaOptions: {
validator?: ValidatorOptions;
transformer?: ClassTransformOptions;
} = {},
resolverOptions: { mode?: 'async' | 'sync'; raw?: boolean } = {},
): Resolver<Schema> {
return async (values, _, options) => {
const { transformer, validator } = schemaOptions;
const data = plainToClass(schema, values, transformer);
const rawErrors = await (resolverOptions.mode === 'sync'
? validateSync
: validate)(data, validator);
if (rawErrors.length) {
return {
values: {},
errors: toNestErrors(
parseErrorSchema(
rawErrors,
!options.shouldUseNativeValidation &&
options.criteriaMode === 'all',
),
options,
),
};
}
options.shouldUseNativeValidation && validateFieldsNatively({}, options);
return {
values: resolverOptions.raw ? Object.assign({}, values) : data,
errors: {},
};
};
}

View File

@ -1 +0,0 @@
export * from './class-validator';

View File

@ -1,17 +0,0 @@
{
"name": "@hookform/resolvers/computed-types",
"amdName": "hookformResolversComputedTypes",
"version": "1.0.0",
"private": true,
"description": "React Hook Form validation resolver: computed-types",
"main": "dist/computed-types.js",
"module": "dist/computed-types.module.js",
"umd:main": "dist/computed-types.umd.js",
"source": "src/index.ts",
"types": "dist/index.d.ts",
"license": "MIT",
"peerDependencies": {
"react-hook-form": "^7.55.0",
"@hookform/resolvers": "^2.0.0"
}
}

View File

@ -1,79 +0,0 @@
import { render, screen } from '@testing-library/react';
import user from '@testing-library/user-event';
import Schema, { Type, string } from 'computed-types';
import React from 'react';
import { useForm } from 'react-hook-form';
import { computedTypesResolver } from '..';
const USERNAME_REQUIRED_MESSAGE = 'username field is required';
const PASSWORD_REQUIRED_MESSAGE = 'password field is required';
const schema = Schema({
username: string.min(2).error(USERNAME_REQUIRED_MESSAGE),
password: string.min(2).error(PASSWORD_REQUIRED_MESSAGE),
});
interface Props {
onSubmit: (data: Type<typeof schema>) => void;
}
function TestComponent({ onSubmit }: Props) {
const { register, handleSubmit } = useForm({
resolver: computedTypesResolver(schema),
shouldUseNativeValidation: true,
});
return (
<form onSubmit={handleSubmit(onSubmit)}>
<input {...register('username')} placeholder="username" />
<input {...register('password')} placeholder="password" />
<button type="submit">submit</button>
</form>
);
}
test("form's native validation with computed-types", async () => {
const handleSubmit = vi.fn();
render(<TestComponent onSubmit={handleSubmit} />);
// username
let usernameField = screen.getByPlaceholderText(
/username/i,
) as HTMLInputElement;
expect(usernameField.validity.valid).toBe(true);
expect(usernameField.validationMessage).toBe('');
// password
let passwordField = screen.getByPlaceholderText(
/password/i,
) as HTMLInputElement;
expect(passwordField.validity.valid).toBe(true);
expect(passwordField.validationMessage).toBe('');
await user.click(screen.getByText(/submit/i));
// username
usernameField = screen.getByPlaceholderText(/username/i) as HTMLInputElement;
expect(usernameField.validity.valid).toBe(false);
expect(usernameField.validationMessage).toBe(USERNAME_REQUIRED_MESSAGE);
// password
passwordField = screen.getByPlaceholderText(/password/i) as HTMLInputElement;
expect(passwordField.validity.valid).toBe(false);
expect(passwordField.validationMessage).toBe(PASSWORD_REQUIRED_MESSAGE);
await user.type(screen.getByPlaceholderText(/username/i), 'joe');
await user.type(screen.getByPlaceholderText(/password/i), 'password');
// username
usernameField = screen.getByPlaceholderText(/username/i) as HTMLInputElement;
expect(usernameField.validity.valid).toBe(true);
expect(usernameField.validationMessage).toBe('');
// password
passwordField = screen.getByPlaceholderText(/password/i) as HTMLInputElement;
expect(passwordField.validity.valid).toBe(true);
expect(passwordField.validationMessage).toBe('');
});

View File

@ -1,57 +0,0 @@
import { render, screen } from '@testing-library/react';
import user from '@testing-library/user-event';
import Schema, { Type, string } from 'computed-types';
import React from 'react';
import { useForm } from 'react-hook-form';
import { computedTypesResolver } from '..';
const schema = Schema({
username: string.min(2).error('username field is required'),
password: string.min(2).error('password field is required'),
address: Schema({
zipCode: string.min(5).max(5).error('zipCode field is required'),
}),
});
function TestComponent({
onSubmit,
}: { onSubmit: (data: Type<typeof schema>) => void }) {
const {
register,
handleSubmit,
formState: { errors },
} = useForm({
resolver: computedTypesResolver(schema), // Useful to check TypeScript regressions
});
return (
<form onSubmit={handleSubmit(onSubmit)}>
<input {...register('username')} />
{errors.username && <span role="alert">{errors.username.message}</span>}
<input {...register('password')} />
{errors.password && <span role="alert">{errors.password.message}</span>}
<input {...register('address.zipCode')} />
{errors.address?.zipCode && (
<span role="alert">{errors.address.zipCode.message}</span>
)}
<button type="submit">submit</button>
</form>
);
}
test("form's validation with computed-types and TypeScript's integration", async () => {
const handleSubmit = vi.fn();
render(<TestComponent onSubmit={handleSubmit} />);
expect(screen.queryAllByRole('alert')).toHaveLength(0);
await user.click(screen.getByText(/submit/i));
expect(screen.getByText(/username field is required/i)).toBeInTheDocument();
expect(screen.getByText(/password field is required/i)).toBeInTheDocument();
expect(screen.getByText(/zipCode field is required/i)).toBeInTheDocument();
expect(handleSubmit).not.toHaveBeenCalled();
});

View File

@ -1,86 +0,0 @@
import Schema, { Type, string, number, array, boolean } from 'computed-types';
import { Field, InternalFieldName } from 'react-hook-form';
export const schema = Schema({
username: string.regexp(/^\w+$/).min(3).max(30),
password: string
.regexp(new RegExp('.*[A-Z].*'), 'One uppercase character')
.regexp(new RegExp('.*[a-z].*'), 'One lowercase character')
.regexp(new RegExp('.*\\d.*'), 'One number')
.regexp(
new RegExp('.*[`~<>?,./!@#$%^&*()\\-_+="\'|{}\\[\\];:\\\\].*'),
'One special character',
)
.min(8, 'Must be at least 8 characters in length'),
repeatPassword: string,
accessToken: Schema.either(string, number).optional(),
birthYear: number.min(1900).max(2013).optional(),
email: string
.regexp(/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/)
.error('Incorrect email'),
tags: array.of(string),
enabled: boolean,
like: array
.of({
id: number,
name: string.min(4).max(4),
})
.optional(),
address: Schema({
city: string.min(3, 'Is required'),
zipCode: string
.min(5, 'Must be 5 characters long')
.max(5, 'Must be 5 characters long'),
}),
});
export const validData: Type<typeof schema> = {
username: 'Doe',
password: 'Password123_',
repeatPassword: 'Password123_',
accessToken: 'accessToken',
birthYear: 2000,
email: 'john@doe.com',
tags: ['tag1', 'tag2'],
enabled: true,
like: [
{
id: 1,
name: 'name',
},
],
address: {
city: 'Awesome city',
zipCode: '12345',
},
};
export const invalidData = {
password: '___',
email: '',
birthYear: 'birthYear',
like: [{ id: 'z' }],
address: {
city: '',
zipCode: '123',
},
} as any as Type<typeof schema>;
export const fields: Record<InternalFieldName, Field['_f']> = {
username: {
ref: { name: 'username' },
name: 'username',
},
password: {
ref: { name: 'password' },
name: 'password',
},
email: {
ref: { name: 'email' },
name: 'email',
},
birthday: {
ref: { name: 'birthday' },
name: 'birthday',
},
};

View File

@ -1,74 +0,0 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`computedTypesResolver > should return a single error from computedTypesResolver when validation fails 1`] = `
{
"errors": {
"address": {
"city": {
"message": "Is required",
"ref": undefined,
"type": "ValidationError",
},
"zipCode": {
"message": "Must be 5 characters long",
"ref": undefined,
"type": "ValidationError",
},
},
"birthYear": {
"message": "Expect value to be "number"",
"ref": undefined,
"type": "ValidationError",
},
"email": {
"message": "Incorrect email",
"ref": {
"name": "email",
},
"type": "ValidationError",
},
"enabled": {
"message": "Expect value to be "boolean"",
"ref": undefined,
"type": "ValidationError",
},
"like": {
"id": {
"message": "Expect value to be "number"",
"ref": undefined,
"type": "ValidationError",
},
"name": {
"message": "Expect value to be "string"",
"ref": undefined,
"type": "ValidationError",
},
},
"password": {
"message": "One uppercase character",
"ref": {
"name": "password",
},
"type": "ValidationError",
},
"repeatPassword": {
"message": "Expect value to be "string"",
"ref": undefined,
"type": "ValidationError",
},
"tags": {
"message": "Expecting value to be an array",
"ref": undefined,
"type": "ValidationError",
},
"username": {
"message": "Expect value to be "string"",
"ref": {
"name": "username",
},
"type": "ValidationError",
},
},
"values": {},
}
`;

View File

@ -1,96 +0,0 @@
import Schema, { number } from 'computed-types';
import { Resolver, SubmitHandler, useForm } from 'react-hook-form';
import { computedTypesResolver } from '..';
import { fields, invalidData, schema, validData } from './__fixtures__/data';
const shouldUseNativeValidation = false;
describe('computedTypesResolver', () => {
it('should return values from computedTypesResolver when validation pass', async () => {
const result = await computedTypesResolver(schema)(validData, undefined, {
fields,
shouldUseNativeValidation,
});
expect(result).toEqual({ errors: {}, values: validData });
});
it('should return a single error from computedTypesResolver when validation fails', async () => {
const result = await computedTypesResolver(schema)(invalidData, undefined, {
fields,
shouldUseNativeValidation,
});
expect(result).toMatchSnapshot();
});
it('should throw any error unrelated to computed-types', async () => {
const schemaWithCustomError = schema.transform(() => {
throw Error('custom error');
});
const promise = computedTypesResolver(schemaWithCustomError)(
validData,
undefined,
{
fields,
shouldUseNativeValidation,
},
);
await expect(promise).rejects.toThrow('custom error');
});
/**
* Type inference tests
*/
it('should correctly infer the output type from a computedTypes schema', () => {
const resolver = computedTypesResolver(Schema({ id: number }));
expectTypeOf(resolver).toEqualTypeOf<
Resolver<{ id: number }, unknown, { id: number }>
>();
});
it('should correctly infer the output type from a computedTypes schema using a transform', () => {
const resolver = computedTypesResolver(
Schema({ id: number.transform((val) => String(val)) }),
);
expectTypeOf(resolver).toEqualTypeOf<
Resolver<{ id: number }, unknown, { id: string }>
>();
});
it('should correctly infer the output type from a computedTypes schema for the handleSubmit function in useForm', () => {
const schema = Schema({ id: number });
const form = useForm({
resolver: computedTypesResolver(schema),
});
expectTypeOf(form.watch('id')).toEqualTypeOf<number>();
expectTypeOf(form.handleSubmit).parameter(0).toEqualTypeOf<
SubmitHandler<{
id: number;
}>
>();
});
it('should correctly infer the output type from a computedTypes schema with a transform for the handleSubmit function in useForm', () => {
const schema = Schema({ id: number.transform((val) => String(val)) });
const form = useForm({
resolver: computedTypesResolver(schema),
});
expectTypeOf(form.watch('id')).toEqualTypeOf<number>();
expectTypeOf(form.handleSubmit).parameter(0).toEqualTypeOf<
SubmitHandler<{
id: string;
}>
>();
});
});

Some files were not shown because too many files have changed in this diff Show More