From 5f8ac8cdebdf6bad17867dea6da1aa3a6c02ae05 Mon Sep 17 00:00:00 2001 From: Anton Gunnarsson Date: Thu, 26 Jun 2025 12:40:45 +0000 Subject: [PATCH] Merged in feat/sw-2861-move-autocomplete-router-to-trpc-package (pull request #2417) feat(SW-2861): Move autocomplete router to trpc package * Apply lint rules * Use direct imports from trpc package * Add lint-staged config to trpc * Move lang enum to common * Restructure trpc package folder structure * WIP first step * update internal imports in trpc * Fix most errors in scandic-web Just 100 left... * Move Props type out of trpc * Fix CategorizedFilters types * Move more schemas in hotel router * Fix deps * fix getNonContentstackUrls * Fix import error * Fix entry error handling * Fix generateMetadata metrics * Fix alertType enum * Fix duplicated types * lint:fix * Merge branch 'master' into feat/sw-2863-move-contentstack-router-to-trpc-package * Fix broken imports * Move booking router to trpc package * Move partners router to trpc package * Move autocomplete router to trpc package * Merge branch 'master' into feat/sw-2861-move-autocomplete-router-to-trpc-package Approved-by: Linus Flood --- .../Search/SearchList/List/ListItem/index.tsx | 3 +- .../Search/SearchList/List/index.tsx | 3 +- .../FormContent/Search/index.tsx | 4 +- .../Accordions/Breakfast.tsx | 3 +- apps/scandic-web/hooks/useSearchHistory.ts | 2 +- .../lib/trpc/memoizedRequests/index.ts | 3 +- apps/scandic-web/server/index.ts | 2 +- apps/scandic-web/server/utils.ts | 4 -- .../warmup/wamupAutoCompleteLocations.ts | 3 +- apps/scandic-web/types/components/search.ts | 3 +- packages/common/package.json | 1 + packages/common/utils/isDefined.ts | 3 ++ packages/trpc/.env.test | 0 .../lib}/routers/autocomplete/destinations.ts | 17 +++---- .../trpc/lib}/routers/autocomplete/index.ts | 3 +- .../trpc/lib}/routers/autocomplete/schema.ts | 0 .../util/filterAndCategorizeAutoComplete.ts | 0 .../util/filterAutoCompleteLocations.test.ts | 4 +- .../util/filterAutoCompleteLocations.ts | 0 .../autocomplete/util/getSearchTokens.test.ts | 26 +++++----- .../autocomplete/util/getSearchTokens.ts | 2 +- .../util/mapLocationToAutoCompleteLocation.ts | 3 +- .../autocomplete/util/normalizeAumlauts.ts | 0 packages/trpc/lib/routers/hotels/query.ts | 50 ++++++++++--------- .../trpc/lib/types/deepPartial.ts | 0 packages/trpc/package.json | 10 +++- packages/trpc/vitest-setup.ts | 3 ++ packages/trpc/vitest.config.js | 7 +++ yarn.lock | 3 ++ 29 files changed, 92 insertions(+), 70 deletions(-) create mode 100644 packages/common/utils/isDefined.ts create mode 100644 packages/trpc/.env.test rename {apps/scandic-web/server => packages/trpc/lib}/routers/autocomplete/destinations.ts (90%) rename {apps/scandic-web/server => packages/trpc/lib}/routers/autocomplete/index.ts (77%) rename {apps/scandic-web/server => packages/trpc/lib}/routers/autocomplete/schema.ts (100%) rename {apps/scandic-web/server => packages/trpc/lib}/routers/autocomplete/util/filterAndCategorizeAutoComplete.ts (100%) rename {apps/scandic-web/server => packages/trpc/lib}/routers/autocomplete/util/filterAutoCompleteLocations.test.ts (98%) rename {apps/scandic-web/server => packages/trpc/lib}/routers/autocomplete/util/filterAutoCompleteLocations.ts (100%) rename {apps/scandic-web/server => packages/trpc/lib}/routers/autocomplete/util/getSearchTokens.test.ts (78%) rename {apps/scandic-web/server => packages/trpc/lib}/routers/autocomplete/util/getSearchTokens.ts (89%) rename {apps/scandic-web/server => packages/trpc/lib}/routers/autocomplete/util/mapLocationToAutoCompleteLocation.ts (90%) rename {apps/scandic-web/server => packages/trpc/lib}/routers/autocomplete/util/normalizeAumlauts.ts (100%) rename apps/scandic-web/types/DeepPartial.ts => packages/trpc/lib/types/deepPartial.ts (100%) create mode 100644 packages/trpc/vitest-setup.ts create mode 100644 packages/trpc/vitest.config.js diff --git a/apps/scandic-web/components/Forms/BookingWidget/FormContent/Search/SearchList/List/ListItem/index.tsx b/apps/scandic-web/components/Forms/BookingWidget/FormContent/Search/SearchList/List/ListItem/index.tsx index ad79b69dc..f43515792 100644 --- a/apps/scandic-web/components/Forms/BookingWidget/FormContent/Search/SearchList/List/ListItem/index.tsx +++ b/apps/scandic-web/components/Forms/BookingWidget/FormContent/Search/SearchList/List/ListItem/index.tsx @@ -3,8 +3,9 @@ import Body from "@/components/TempDesignSystem/Text/Body" import { listItemVariants } from "./variants" +import type { AutoCompleteLocation } from "@scandic-hotels/trpc/routers/autocomplete/schema" + import type { SearchListProps } from "@/types/components/search" -import type { AutoCompleteLocation } from "@/server/routers/autocomplete/schema" export interface ListItemProps extends Pick { diff --git a/apps/scandic-web/components/Forms/BookingWidget/FormContent/Search/SearchList/List/index.tsx b/apps/scandic-web/components/Forms/BookingWidget/FormContent/Search/SearchList/List/index.tsx index 4d85273b2..cd71d4af4 100644 --- a/apps/scandic-web/components/Forms/BookingWidget/FormContent/Search/SearchList/List/index.tsx +++ b/apps/scandic-web/components/Forms/BookingWidget/FormContent/Search/SearchList/List/index.tsx @@ -5,8 +5,9 @@ import ListItem, { ListItemSkeleton } from "./ListItem" import styles from "./list.module.css" +import type { AutoCompleteLocation } from "@scandic-hotels/trpc/routers/autocomplete/schema" + import type { SearchListProps } from "@/types/components/search" -import type { AutoCompleteLocation } from "@/server/routers/autocomplete/schema" interface ListProps extends Pick { diff --git a/apps/scandic-web/components/Forms/BookingWidget/FormContent/Search/index.tsx b/apps/scandic-web/components/Forms/BookingWidget/FormContent/Search/index.tsx index e52ff9ea4..931ebe562 100644 --- a/apps/scandic-web/components/Forms/BookingWidget/FormContent/Search/index.tsx +++ b/apps/scandic-web/components/Forms/BookingWidget/FormContent/Search/index.tsx @@ -10,8 +10,6 @@ import { Button } from "@scandic-hotels/design-system/Button" import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon" import { Typography } from "@scandic-hotels/design-system/Typography" -import { type AutoCompleteLocation } from "@/server/routers/autocomplete/schema" - import SkeletonShimmer from "@/components/SkeletonShimmer" import { useSearchHistory } from "@/hooks/useSearchHistory" @@ -20,6 +18,8 @@ import SearchList from "./SearchList" import styles from "./search.module.css" +import type { AutoCompleteLocation } from "@scandic-hotels/trpc/routers/autocomplete/schema" + interface SearchProps { autoFocus?: boolean alwaysShowResults?: boolean diff --git a/apps/scandic-web/components/SidePeeks/AmenitiesSidepeekContent/Accordions/Breakfast.tsx b/apps/scandic-web/components/SidePeeks/AmenitiesSidepeekContent/Accordions/Breakfast.tsx index c5611f8b9..70543b960 100644 --- a/apps/scandic-web/components/SidePeeks/AmenitiesSidepeekContent/Accordions/Breakfast.tsx +++ b/apps/scandic-web/components/SidePeeks/AmenitiesSidepeekContent/Accordions/Breakfast.tsx @@ -2,11 +2,10 @@ import { useIntl } from "react-intl" +import { isDefined } from "@scandic-hotels/common/utils/isDefined" import { Typography } from "@scandic-hotels/design-system/Typography" import { HotelTypeEnum } from "@scandic-hotels/trpc/enums/hotelType" -import { isDefined } from "@/server/utils" - import { IconName } from "@/components/Icons/iconName" import OpeningHours from "@/components/OpeningHours" import AccordionItem from "@/components/TempDesignSystem/Accordion/AccordionItem" diff --git a/apps/scandic-web/hooks/useSearchHistory.ts b/apps/scandic-web/hooks/useSearchHistory.ts index 5f7b1d971..7ac4a8cd4 100644 --- a/apps/scandic-web/hooks/useSearchHistory.ts +++ b/apps/scandic-web/hooks/useSearchHistory.ts @@ -3,7 +3,7 @@ import { useCallback, useEffect, useState } from "react" import { type AutoCompleteLocation, autoCompleteLocationSchema, -} from "@/server/routers/autocomplete/schema" +} from "@scandic-hotels/trpc/routers/autocomplete/schema" import useLang from "@/hooks/useLang" diff --git a/apps/scandic-web/lib/trpc/memoizedRequests/index.ts b/apps/scandic-web/lib/trpc/memoizedRequests/index.ts index 88c7aa5ab..9623db3b7 100644 --- a/apps/scandic-web/lib/trpc/memoizedRequests/index.ts +++ b/apps/scandic-web/lib/trpc/memoizedRequests/index.ts @@ -1,7 +1,8 @@ import { redirect } from "next/navigation" -import { isDefined } from "@/server/utils" +import { isDefined } from "@scandic-hotels/common/utils/isDefined" +// import { isDefined } from "@/server/utils" import { getLang } from "@/i18n/serverContext" import { cache } from "@/utils/cache" diff --git a/apps/scandic-web/server/index.ts b/apps/scandic-web/server/index.ts index 9c577f232..ffa5be05c 100644 --- a/apps/scandic-web/server/index.ts +++ b/apps/scandic-web/server/index.ts @@ -1,10 +1,10 @@ /** Routers */ import { router } from "@scandic-hotels/trpc" +import { autocompleteRouter } from "@scandic-hotels/trpc/routers/autocomplete" import { contentstackRouter } from "@scandic-hotels/trpc/routers/contentstack" import { hotelsRouter } from "@scandic-hotels/trpc/routers/hotels" import { partnerRouter } from "@scandic-hotels/trpc/routers/partners" -import { autocompleteRouter } from "./routers/autocomplete" import { bookingRouter } from "./routers/booking" import { navigationRouter } from "./routers/navigation" import { userRouter } from "./routers/user" diff --git a/apps/scandic-web/server/utils.ts b/apps/scandic-web/server/utils.ts index 4ff740f4f..aac338427 100644 --- a/apps/scandic-web/server/utils.ts +++ b/apps/scandic-web/server/utils.ts @@ -2,10 +2,6 @@ import { NextRequest } from "next/server" import { env } from "@/env/server" -export function isDefined(argument: T | undefined | null): argument is T { - return argument !== undefined && argument !== null -} - /** * Use this function when you want to create URLs that are public facing, for * example for redirects or redirectTo query parameters. diff --git a/apps/scandic-web/services/warmup/wamupAutoCompleteLocations.ts b/apps/scandic-web/services/warmup/wamupAutoCompleteLocations.ts index 485a726d2..7766fd507 100644 --- a/apps/scandic-web/services/warmup/wamupAutoCompleteLocations.ts +++ b/apps/scandic-web/services/warmup/wamupAutoCompleteLocations.ts @@ -1,6 +1,5 @@ import { getServiceToken } from "@scandic-hotels/common/tokenManager" - -import { getAutoCompleteDestinationsData } from "@/server/routers/autocomplete/destinations" +import { getAutoCompleteDestinationsData } from "@scandic-hotels/trpc/routers/autocomplete/destinations" import type { Lang } from "@scandic-hotels/common/constants/language" diff --git a/apps/scandic-web/types/components/search.ts b/apps/scandic-web/types/components/search.ts index ba9ce99e0..82da8fd30 100644 --- a/apps/scandic-web/types/components/search.ts +++ b/apps/scandic-web/types/components/search.ts @@ -1,8 +1,9 @@ +import type { AutoCompleteLocation } from "@scandic-hotels/trpc/routers/autocomplete/schema" import type { VariantProps } from "class-variance-authority" import type { PropGetters } from "downshift" import type { dialogVariants } from "@/components/Forms/BookingWidget/FormContent/Search/SearchList/Dialog/variants" -import type { AutoCompleteLocation } from "@/server/routers/autocomplete/schema" +// import type { AutoCompleteLocation } from "@/server/routers/autocomplete/schema" export interface SearchProps { handlePressEnter: () => void diff --git a/packages/common/package.json b/packages/common/package.json index ffd031d41..2a9a9b843 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -21,6 +21,7 @@ "./utils/url": "./utils/url.ts", "./utils/languages": "./utils/languages.ts", "./utils/chunk": "./utils/chunk.ts", + "./utils/isDefined": "./utils/isDefined.ts", "./utils/zod/stringValidator": "./utils/zod/stringValidator.ts", "./utils/zod/numberValidator": "./utils/zod/numberValidator.ts", "./utils/zod/arrayValidator": "./utils/zod/arrayValidator.ts", diff --git a/packages/common/utils/isDefined.ts b/packages/common/utils/isDefined.ts new file mode 100644 index 000000000..74f4b7ab4 --- /dev/null +++ b/packages/common/utils/isDefined.ts @@ -0,0 +1,3 @@ +export function isDefined(argument: T | undefined | null): argument is T { + return argument !== undefined && argument !== null +} diff --git a/packages/trpc/.env.test b/packages/trpc/.env.test new file mode 100644 index 000000000..e69de29bb diff --git a/apps/scandic-web/server/routers/autocomplete/destinations.ts b/packages/trpc/lib/routers/autocomplete/destinations.ts similarity index 90% rename from apps/scandic-web/server/routers/autocomplete/destinations.ts rename to packages/trpc/lib/routers/autocomplete/destinations.ts index 79af27a25..b9c81ab6d 100644 --- a/apps/scandic-web/server/routers/autocomplete/destinations.ts +++ b/packages/trpc/lib/routers/autocomplete/destinations.ts @@ -2,20 +2,19 @@ import { z } from "zod" import { Lang } from "@scandic-hotels/common/constants/language" import { getCacheClient } from "@scandic-hotels/common/dataCache" +import { isDefined } from "@scandic-hotels/common/utils/isDefined" import { safeTry } from "@scandic-hotels/common/utils/safeTry" -import { safeProtectedServiceProcedure } from "@scandic-hotels/trpc/procedures" -import { getCityPageUrls } from "@scandic-hotels/trpc/routers/contentstack/destinationCityPage/utils" -import { getCountryPageUrls } from "@scandic-hotels/trpc/routers/contentstack/destinationCountryPage/utils" -import { getHotelPageUrls } from "@scandic-hotels/trpc/routers/contentstack/hotelPage/utils" + +import { safeProtectedServiceProcedure } from "../../procedures" +import { getCityPageUrls } from "../../routers/contentstack/destinationCityPage/utils" +import { getCountryPageUrls } from "../../routers/contentstack/destinationCountryPage/utils" +import { getHotelPageUrls } from "../../routers/contentstack/hotelPage/utils" import { getCitiesByCountry, getCountries, getLocations, -} from "@scandic-hotels/trpc/routers/hotels/utils" -import { ApiCountry, type Country } from "@scandic-hotels/trpc/types/country" - -import { isDefined } from "@/server/utils" - +} from "../../routers/hotels/utils" +import { ApiCountry, type Country } from "../../types/country" import { filterAndCategorizeAutoComplete } from "./util/filterAndCategorizeAutoComplete" import { mapLocationToAutoCompleteLocation } from "./util/mapLocationToAutoCompleteLocation" diff --git a/apps/scandic-web/server/routers/autocomplete/index.ts b/packages/trpc/lib/routers/autocomplete/index.ts similarity index 77% rename from apps/scandic-web/server/routers/autocomplete/index.ts rename to packages/trpc/lib/routers/autocomplete/index.ts index ff940c4c1..ab9f2a97e 100644 --- a/apps/scandic-web/server/routers/autocomplete/index.ts +++ b/packages/trpc/lib/routers/autocomplete/index.ts @@ -1,5 +1,4 @@ -import { router } from "@scandic-hotels/trpc" - +import { router } from "../.." import { getDestinationsAutoCompleteRoute } from "./destinations" export const autocompleteRouter = router({ diff --git a/apps/scandic-web/server/routers/autocomplete/schema.ts b/packages/trpc/lib/routers/autocomplete/schema.ts similarity index 100% rename from apps/scandic-web/server/routers/autocomplete/schema.ts rename to packages/trpc/lib/routers/autocomplete/schema.ts diff --git a/apps/scandic-web/server/routers/autocomplete/util/filterAndCategorizeAutoComplete.ts b/packages/trpc/lib/routers/autocomplete/util/filterAndCategorizeAutoComplete.ts similarity index 100% rename from apps/scandic-web/server/routers/autocomplete/util/filterAndCategorizeAutoComplete.ts rename to packages/trpc/lib/routers/autocomplete/util/filterAndCategorizeAutoComplete.ts diff --git a/apps/scandic-web/server/routers/autocomplete/util/filterAutoCompleteLocations.test.ts b/packages/trpc/lib/routers/autocomplete/util/filterAutoCompleteLocations.test.ts similarity index 98% rename from apps/scandic-web/server/routers/autocomplete/util/filterAutoCompleteLocations.test.ts rename to packages/trpc/lib/routers/autocomplete/util/filterAutoCompleteLocations.test.ts index 204f4a84c..a2cc3ebd0 100644 --- a/apps/scandic-web/server/routers/autocomplete/util/filterAutoCompleteLocations.test.ts +++ b/packages/trpc/lib/routers/autocomplete/util/filterAutoCompleteLocations.test.ts @@ -1,8 +1,8 @@ -import { describe, expect, it } from "@jest/globals" +import { describe, expect, it } from "vitest" import { filterAutoCompleteLocations } from "./filterAutoCompleteLocations" -import type { DeepPartial } from "@/types/DeepPartial" +import type { DeepPartial } from "../../../types/deepPartial" import type { AutoCompleteLocation } from "../schema" describe("rankAutoCompleteLocations", () => { diff --git a/apps/scandic-web/server/routers/autocomplete/util/filterAutoCompleteLocations.ts b/packages/trpc/lib/routers/autocomplete/util/filterAutoCompleteLocations.ts similarity index 100% rename from apps/scandic-web/server/routers/autocomplete/util/filterAutoCompleteLocations.ts rename to packages/trpc/lib/routers/autocomplete/util/filterAutoCompleteLocations.ts diff --git a/apps/scandic-web/server/routers/autocomplete/util/getSearchTokens.test.ts b/packages/trpc/lib/routers/autocomplete/util/getSearchTokens.test.ts similarity index 78% rename from apps/scandic-web/server/routers/autocomplete/util/getSearchTokens.test.ts rename to packages/trpc/lib/routers/autocomplete/util/getSearchTokens.test.ts index 8ea6b7ff8..7a90e4e8d 100644 --- a/apps/scandic-web/server/routers/autocomplete/util/getSearchTokens.test.ts +++ b/packages/trpc/lib/routers/autocomplete/util/getSearchTokens.test.ts @@ -1,10 +1,10 @@ -import { describe, expect, it } from "@jest/globals" +import { describe, expect, it } from "vitest" import { getSearchTokens } from "./getSearchTokens" import type { Location } from "@scandic-hotels/trpc/types/locations" -import type { DeepPartial } from "@/types/DeepPartial" +import type { DeepPartial } from "../../../types/deepPartial" describe("getSearchTokens", () => { it("should return lowercased tokens for a hotel location", () => { @@ -28,16 +28,18 @@ describe("getSearchTokens", () => { } const result = getSearchTokens(location as Location) - expect(result).toEqual([ - "ångström", - "café", - "münchen", - "frånce", - "angstrom", - "cafe", - "munchen", - "france", - ]) + expect(result.toSorted()).toEqual( + [ + "ångström", + "café", + "münchen", + "frånce", + "angstrom", + "cafe", + "munchen", + "france", + ].toSorted() + ) }) it("should filter out empty or falsey tokens", () => { diff --git a/apps/scandic-web/server/routers/autocomplete/util/getSearchTokens.ts b/packages/trpc/lib/routers/autocomplete/util/getSearchTokens.ts similarity index 89% rename from apps/scandic-web/server/routers/autocomplete/util/getSearchTokens.ts rename to packages/trpc/lib/routers/autocomplete/util/getSearchTokens.ts index 31b603a51..1ca2e0d4e 100644 --- a/apps/scandic-web/server/routers/autocomplete/util/getSearchTokens.ts +++ b/packages/trpc/lib/routers/autocomplete/util/getSearchTokens.ts @@ -1,6 +1,6 @@ import { normalizeAumlauts } from "./normalizeAumlauts" -import type { Location } from "@scandic-hotels/trpc/types/locations" +import type { Location } from "../../../types/locations" export function getSearchTokens(location: Location) { const tokens = [ diff --git a/apps/scandic-web/server/routers/autocomplete/util/mapLocationToAutoCompleteLocation.ts b/packages/trpc/lib/routers/autocomplete/util/mapLocationToAutoCompleteLocation.ts similarity index 90% rename from apps/scandic-web/server/routers/autocomplete/util/mapLocationToAutoCompleteLocation.ts rename to packages/trpc/lib/routers/autocomplete/util/mapLocationToAutoCompleteLocation.ts index f75bfeb24..a42a5dcfd 100644 --- a/apps/scandic-web/server/routers/autocomplete/util/mapLocationToAutoCompleteLocation.ts +++ b/packages/trpc/lib/routers/autocomplete/util/mapLocationToAutoCompleteLocation.ts @@ -1,7 +1,6 @@ import { getSearchTokens } from "./getSearchTokens" -import type { Location } from "@scandic-hotels/trpc/types/locations" - +import type { Location } from "../../../types/locations" import type { AutoCompleteLocation } from "../schema" export function mapLocationToAutoCompleteLocation( diff --git a/apps/scandic-web/server/routers/autocomplete/util/normalizeAumlauts.ts b/packages/trpc/lib/routers/autocomplete/util/normalizeAumlauts.ts similarity index 100% rename from apps/scandic-web/server/routers/autocomplete/util/normalizeAumlauts.ts rename to packages/trpc/lib/routers/autocomplete/util/normalizeAumlauts.ts diff --git a/packages/trpc/lib/routers/hotels/query.ts b/packages/trpc/lib/routers/hotels/query.ts index f91494458..5295a2323 100644 --- a/packages/trpc/lib/routers/hotels/query.ts +++ b/packages/trpc/lib/routers/hotels/query.ts @@ -2,6 +2,24 @@ import { Lang } from "@scandic-hotels/common/constants/language" import { getCacheClient } from "@scandic-hotels/common/dataCache" import { dt } from "@scandic-hotels/common/dt" import { createCounter } from "@scandic-hotels/common/telemetry" + +import { env } from "../../../env/server" +import { router } from "../.." +import * as api from "../../api" +import { REDEMPTION } from "../../constants/booking" +import { BreakfastPackageEnum } from "../../enums/breakfast" +import { RateEnum } from "../../enums/rate" +import { RateTypeEnum } from "../../enums/rateType" +import { AvailabilityEnum } from "../../enums/selectHotel" +import { badRequestError, unauthorizedError } from "../../errors" +import { + contentStackBaseWithServiceProcedure, + publicProcedure, + safeProtectedServiceProcedure, + serviceProcedure, +} from "../../procedures" +import { getCityPageUrls } from "../../routers/contentstack/destinationCityPage/utils" +import { getHotelPageUrls } from "../../routers/contentstack/hotelPage/utils" import { ancillaryPackageInputSchema, breakfastPackageInputSchema, @@ -23,46 +41,30 @@ import { roomPackagesInputSchema, selectRateRoomAvailabilityInputSchema, selectRateRoomsAvailabilityInputSchema, -} from "@scandic-hotels/trpc/routers/hotels/input" +} from "../../routers/hotels/input" import { ancillaryPackagesSchema, breakfastPackagesSchema, getNearbyHotelIdsSchema, -} from "@scandic-hotels/trpc/routers/hotels/output" -import { additionalDataSchema } from "@scandic-hotels/trpc/routers/hotels/schemas/hotel/include/additionalData" - -import { env } from "../../../env/server" -import { router } from "../.." -import * as api from "../../api" -import { REDEMPTION } from "../../constants/booking" -import { BreakfastPackageEnum } from "../../enums/breakfast" -import { RateEnum } from "../../enums/rate" -import { RateTypeEnum } from "../../enums/rateType" -import { AvailabilityEnum } from "../../enums/selectHotel" -import { badRequestError, unauthorizedError } from "../../errors" -import { - contentStackBaseWithServiceProcedure, - publicProcedure, - safeProtectedServiceProcedure, - serviceProcedure, -} from "../../procedures" -import { getCityPageUrls } from "../../routers/contentstack/destinationCityPage/utils" -import { getHotelPageUrls } from "../../routers/contentstack/hotelPage/utils" +} from "../../routers/hotels/output" +import { additionalDataSchema } from "../../routers/hotels/schemas/hotel/include/additionalData" import { toApiLang } from "../../utils" import { getVerifiedUser } from "../user/utils" import { meetingRoomsSchema } from "./schemas/meetingRoom" import { - getBedTypes, getCitiesByCountry, getCountries, getHotel, getHotelIdsByCityId, getHotelIdsByCityIdentifier, getHotelIdsByCountry, - getHotelsAvailabilityByCity, - getHotelsAvailabilityByHotelIds, getHotelsByHotelIds, getLocations, +} from "./utils" +import { + getBedTypes, + getHotelsAvailabilityByCity, + getHotelsAvailabilityByHotelIds, getPackages, getRoomsAvailability, getSelectedRoomAvailability, diff --git a/apps/scandic-web/types/DeepPartial.ts b/packages/trpc/lib/types/deepPartial.ts similarity index 100% rename from apps/scandic-web/types/DeepPartial.ts rename to packages/trpc/lib/types/deepPartial.ts diff --git a/packages/trpc/package.json b/packages/trpc/package.json index 737513730..a0b101580 100644 --- a/packages/trpc/package.json +++ b/packages/trpc/package.json @@ -6,7 +6,9 @@ "scripts": { "check-types": "tsc --noEmit", "lint": "eslint . --max-warnings 0 && tsc --noEmit", - "lint:fix": "eslint . --fix && tsc --noEmit" + "lint:fix": "eslint . --fix && tsc --noEmit", + "test": "vitest run", + "test:watch": "vitest" }, "exports": { ".": "./lib/index.ts", @@ -24,6 +26,7 @@ "./routers/booking/*": "./lib/routers/booking/*.ts", "./routers/user/*": "./lib/routers/user/*.ts", "./routers/partners/*": "./lib/routers/partners/*.ts", + "./routers/autocomplete/*": "./lib/routers/autocomplete/*.ts", "./enums/*": "./lib/enums/*.ts", "./types/*": "./lib/types/*.ts", "./constants/*": "./lib/constants/*.ts", @@ -46,6 +49,7 @@ "dayjs": "^1.11.13", "deepmerge": "^4.3.1", "fetch-retry": "^6.0.0", + "fuse.js": "^7.1.0", "graphql": "^16.11.0", "graphql-request": "^7.1.2", "json-stable-stringify-without-jsonify": "^1.0.1", @@ -68,9 +72,11 @@ "@types/react": "19.1.0", "@typescript-eslint/eslint-plugin": "^8.32.0", "@typescript-eslint/parser": "^8.32.0", + "dotenv": "^16.5.0", "eslint": "^9", "eslint-plugin-import": "^2.31.0", "eslint-plugin-simple-import-sort": "^12.1.1", - "typescript": "5.8.3" + "typescript": "5.8.3", + "vitest": "^3.2.3" } } diff --git a/packages/trpc/vitest-setup.ts b/packages/trpc/vitest-setup.ts new file mode 100644 index 000000000..ce8f4053c --- /dev/null +++ b/packages/trpc/vitest-setup.ts @@ -0,0 +1,3 @@ +import { config } from "dotenv" + +config({ path: "./.env.test" }) diff --git a/packages/trpc/vitest.config.js b/packages/trpc/vitest.config.js new file mode 100644 index 000000000..a8270b4e2 --- /dev/null +++ b/packages/trpc/vitest.config.js @@ -0,0 +1,7 @@ +export default { + test: { + globals: true, + environment: "jsdom", + setupFiles: ["./vitest-setup.ts"], + }, +} diff --git a/yarn.lock b/yarn.lock index d420980fc..f8d11c2c6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7254,10 +7254,12 @@ __metadata: "@typescript-eslint/parser": "npm:^8.32.0" dayjs: "npm:^1.11.13" deepmerge: "npm:^4.3.1" + dotenv: "npm:^16.5.0" eslint: "npm:^9" eslint-plugin-import: "npm:^2.31.0" eslint-plugin-simple-import-sort: "npm:^12.1.1" fetch-retry: "npm:^6.0.0" + fuse.js: "npm:^7.1.0" graphql: "npm:^16.11.0" graphql-request: "npm:^7.1.2" json-stable-stringify-without-jsonify: "npm:^1.0.1" @@ -7266,6 +7268,7 @@ __metadata: slugify: "npm:^1.6.6" superjson: "npm:^2.2.2" typescript: "npm:5.8.3" + vitest: "npm:^3.2.3" zod: "npm:^3.24.4" peerDependencies: next: ^15