Merged in fix/improve-logging (pull request #448)
Fix/improve logging Approved-by: Michael Zetterberg
This commit is contained in:
@@ -46,10 +46,10 @@ export async function request<T>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const print = (await import("graphql/language/printer")).print
|
// const print = (await import("graphql/language/printer")).print
|
||||||
const nr = Math.random()
|
// const nr = Math.random()
|
||||||
console.log(`START REQUEST ${nr}`)
|
// console.log(`START REQUEST ${nr}`)
|
||||||
console.time(`OUTGOING REQUEST ${nr}`)
|
// console.time(`OUTGOING REQUEST ${nr}`)
|
||||||
// console.log(`Sending reqeust to ${env.CMS_URL}`)
|
// console.log(`Sending reqeust to ${env.CMS_URL}`)
|
||||||
// console.log(`Query:`, print(query as DocumentNode))
|
// console.log(`Query:`, print(query as DocumentNode))
|
||||||
// console.log(`Variables:`, variables)
|
// console.log(`Variables:`, variables)
|
||||||
@@ -63,7 +63,7 @@ export async function request<T>(
|
|||||||
variables,
|
variables,
|
||||||
})
|
})
|
||||||
|
|
||||||
console.timeEnd(`OUTGOING REQUEST ${nr}`)
|
// console.timeEnd(`OUTGOING REQUEST ${nr}`)
|
||||||
// console.log({ response })
|
// console.log({ response })
|
||||||
|
|
||||||
return { data: response }
|
return { data: response }
|
||||||
|
|||||||
@@ -35,7 +35,10 @@ import { RTEDocument } from "@/types/rte/node"
|
|||||||
export const accountPageQueryRouter = router({
|
export const accountPageQueryRouter = router({
|
||||||
get: contentstackExtendedProcedureUID.query(async ({ ctx }) => {
|
get: contentstackExtendedProcedureUID.query(async ({ ctx }) => {
|
||||||
const { lang, uid } = ctx
|
const { lang, uid } = ctx
|
||||||
|
console.info(
|
||||||
|
"contentstack.accountPage.refs start",
|
||||||
|
JSON.stringify({ query: { lang, uid } })
|
||||||
|
)
|
||||||
const refsResponse = await request<AccountPageRefsDataRaw>(
|
const refsResponse = await request<AccountPageRefsDataRaw>(
|
||||||
GetAccountPageRefs,
|
GetAccountPageRefs,
|
||||||
{
|
{
|
||||||
@@ -48,7 +51,15 @@ export const accountPageQueryRouter = router({
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (!refsResponse.data) {
|
if (!refsResponse.data) {
|
||||||
throw notFound(refsResponse)
|
const notFoundError = notFound(refsResponse)
|
||||||
|
console.error(
|
||||||
|
"contentstack.accountPage.refs not found error",
|
||||||
|
JSON.stringify({
|
||||||
|
query: { lang, uid },
|
||||||
|
error: { code: notFoundError.code },
|
||||||
|
})
|
||||||
|
)
|
||||||
|
throw notFoundError
|
||||||
}
|
}
|
||||||
|
|
||||||
const cleanedData = removeEmptyObjects(refsResponse.data)
|
const cleanedData = removeEmptyObjects(refsResponse.data)
|
||||||
@@ -56,8 +67,13 @@ export const accountPageQueryRouter = router({
|
|||||||
const validatedAccountPageRefs =
|
const validatedAccountPageRefs =
|
||||||
validateAccountPageRefsSchema.safeParse(cleanedData)
|
validateAccountPageRefsSchema.safeParse(cleanedData)
|
||||||
if (!validatedAccountPageRefs.success) {
|
if (!validatedAccountPageRefs.success) {
|
||||||
console.error(`Failed to validate My Page Refs - (uid: ${uid})`)
|
console.error(
|
||||||
console.error(validatedAccountPageRefs.error)
|
"contentstack.accountPage.refs validation error",
|
||||||
|
JSON.stringify({
|
||||||
|
query: { lang, uid },
|
||||||
|
error: validatedAccountPageRefs.error,
|
||||||
|
})
|
||||||
|
)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,7 +83,10 @@ export const accountPageQueryRouter = router({
|
|||||||
generateTags(lang, connections),
|
generateTags(lang, connections),
|
||||||
generateTag(lang, validatedAccountPageRefs.data.account_page.system.uid),
|
generateTag(lang, validatedAccountPageRefs.data.account_page.system.uid),
|
||||||
].flat()
|
].flat()
|
||||||
|
console.info(
|
||||||
|
"contentstack.accountPage start",
|
||||||
|
JSON.stringify({ query: { lang, uid } })
|
||||||
|
)
|
||||||
const response = await request<AccountPageDataRaw>(
|
const response = await request<AccountPageDataRaw>(
|
||||||
GetAccountPage,
|
GetAccountPage,
|
||||||
{
|
{
|
||||||
@@ -78,7 +97,15 @@ export const accountPageQueryRouter = router({
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (!response.data) {
|
if (!response.data) {
|
||||||
throw notFound(response)
|
const notFoundError = notFound(response)
|
||||||
|
console.error(
|
||||||
|
"contentstack.accountPage not found error",
|
||||||
|
JSON.stringify({
|
||||||
|
query: { lang, uid },
|
||||||
|
error: { code: notFoundError.code },
|
||||||
|
})
|
||||||
|
)
|
||||||
|
throw notFoundError
|
||||||
}
|
}
|
||||||
|
|
||||||
const validatedAccountPage = validateAccountPageSchema.safeParse(
|
const validatedAccountPage = validateAccountPageSchema.safeParse(
|
||||||
@@ -86,11 +113,19 @@ export const accountPageQueryRouter = router({
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (!validatedAccountPage.success) {
|
if (!validatedAccountPage.success) {
|
||||||
console.error(`Failed to validate Account Page - (uid: ${uid})`)
|
console.error(
|
||||||
console.error(validatedAccountPage.error)
|
"contentstack.accountPage validation error",
|
||||||
|
JSON.stringify({
|
||||||
|
query: { lang, uid },
|
||||||
|
error: validatedAccountPage.error,
|
||||||
|
})
|
||||||
|
)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
console.info(
|
||||||
|
"contentstack.accountPage success",
|
||||||
|
JSON.stringify({ query: { lang, uid } })
|
||||||
|
)
|
||||||
// TODO: Make returned data nicer
|
// TODO: Make returned data nicer
|
||||||
const content = validatedAccountPage.data.account_page.content.map(
|
const content = validatedAccountPage.data.account_page.content.map(
|
||||||
(block) => {
|
(block) => {
|
||||||
|
|||||||
@@ -9,11 +9,7 @@ import {
|
|||||||
} from "@/lib/graphql/Query/CurrentHeader.graphql"
|
} from "@/lib/graphql/Query/CurrentHeader.graphql"
|
||||||
import { request } from "@/lib/graphql/request"
|
import { request } from "@/lib/graphql/request"
|
||||||
import { notFound } from "@/server/errors/trpc"
|
import { notFound } from "@/server/errors/trpc"
|
||||||
import {
|
import { contentstackBaseProcedure, router } from "@/server/trpc"
|
||||||
contentstackBaseProcedure,
|
|
||||||
publicProcedure,
|
|
||||||
router,
|
|
||||||
} from "@/server/trpc"
|
|
||||||
|
|
||||||
import { generateTag } from "@/utils/generateTag"
|
import { generateTag } from "@/utils/generateTag"
|
||||||
|
|
||||||
@@ -33,13 +29,21 @@ import {
|
|||||||
export const baseQueryRouter = router({
|
export const baseQueryRouter = router({
|
||||||
contact: contentstackBaseProcedure.query(async ({ ctx }) => {
|
contact: contentstackBaseProcedure.query(async ({ ctx }) => {
|
||||||
const { lang } = ctx
|
const { lang } = ctx
|
||||||
|
console.info(
|
||||||
|
"contentstack.config start",
|
||||||
|
JSON.stringify({ query: { lang } })
|
||||||
|
)
|
||||||
const response = await request<ContactConfigData>(GetContactConfig, {
|
const response = await request<ContactConfigData>(GetContactConfig, {
|
||||||
locale: lang,
|
locale: lang,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!response.data) {
|
if (!response.data) {
|
||||||
throw notFound(response)
|
const notFoundError = notFound(response)
|
||||||
|
console.error(
|
||||||
|
"contentstack.config not found error",
|
||||||
|
JSON.stringify({ query: { lang }, error: { code: notFoundError.code } })
|
||||||
|
)
|
||||||
|
throw notFoundError
|
||||||
}
|
}
|
||||||
|
|
||||||
const validatedContactConfigConfig = validateContactConfigSchema.safeParse(
|
const validatedContactConfigConfig = validateContactConfigSchema.safeParse(
|
||||||
@@ -48,21 +52,38 @@ export const baseQueryRouter = router({
|
|||||||
|
|
||||||
if (!validatedContactConfigConfig.success) {
|
if (!validatedContactConfigConfig.success) {
|
||||||
console.error(
|
console.error(
|
||||||
`Failed to validate Contact Config Data - (lang: ${ctx.lang})`
|
"contentstack.config validation error",
|
||||||
|
JSON.stringify({
|
||||||
|
query: { lang },
|
||||||
|
error: validatedContactConfigConfig.error,
|
||||||
|
})
|
||||||
)
|
)
|
||||||
console.error(validatedContactConfigConfig.error)
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
console.info(
|
||||||
|
"contentstack.config success",
|
||||||
|
JSON.stringify({ query: { lang } })
|
||||||
|
)
|
||||||
return validatedContactConfigConfig.data.all_contact_config.items[0]
|
return validatedContactConfigConfig.data.all_contact_config.items[0]
|
||||||
}),
|
}),
|
||||||
header: contentstackBaseProcedure
|
header: contentstackBaseProcedure
|
||||||
.input(langInput)
|
.input(langInput)
|
||||||
.query(async ({ input }) => {
|
.query(async ({ input }) => {
|
||||||
|
console.info(
|
||||||
|
"contentstack.header.ref start",
|
||||||
|
JSON.stringify({ query: { lang: input.lang } })
|
||||||
|
)
|
||||||
const responseRef = await request<HeaderRefDataRaw>(GetCurrentHeaderRef, {
|
const responseRef = await request<HeaderRefDataRaw>(GetCurrentHeaderRef, {
|
||||||
locale: input.lang,
|
locale: input.lang,
|
||||||
})
|
})
|
||||||
|
console.info(
|
||||||
|
"contentstack.header start",
|
||||||
|
JSON.stringify({
|
||||||
|
query: { lang: input.lang },
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
// There's currently no error handling/validation for the responseRef, should it be added?
|
||||||
const response = await request<HeaderDataRaw>(
|
const response = await request<HeaderDataRaw>(
|
||||||
GetCurrentHeader,
|
GetCurrentHeader,
|
||||||
{ locale: input.lang },
|
{ locale: input.lang },
|
||||||
@@ -77,7 +98,17 @@ export const baseQueryRouter = router({
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (!response.data) {
|
if (!response.data) {
|
||||||
throw notFound(response)
|
const notFoundError = notFound(response)
|
||||||
|
console.error(
|
||||||
|
"contentstack.header not found error",
|
||||||
|
JSON.stringify({
|
||||||
|
query: {
|
||||||
|
lang: input.lang,
|
||||||
|
},
|
||||||
|
error: { code: notFoundError.code },
|
||||||
|
})
|
||||||
|
)
|
||||||
|
throw notFoundError
|
||||||
}
|
}
|
||||||
|
|
||||||
const validatedHeaderConfig = validateHeaderConfigSchema.safeParse(
|
const validatedHeaderConfig = validateHeaderConfigSchema.safeParse(
|
||||||
@@ -85,11 +116,23 @@ export const baseQueryRouter = router({
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (!validatedHeaderConfig.success) {
|
if (!validatedHeaderConfig.success) {
|
||||||
console.error(`Failed to validate Header - (lang: ${input.lang})`)
|
console.error(
|
||||||
console.error(validatedHeaderConfig.error)
|
"contentstack.header validation error",
|
||||||
|
JSON.stringify({
|
||||||
|
query: {
|
||||||
|
lang: input.lang,
|
||||||
|
},
|
||||||
|
error: validatedHeaderConfig.error,
|
||||||
|
})
|
||||||
|
)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
console.info(
|
||||||
|
"contentstack.header success",
|
||||||
|
JSON.stringify({
|
||||||
|
query: { lang: input.lang },
|
||||||
|
})
|
||||||
|
)
|
||||||
const logo =
|
const logo =
|
||||||
validatedHeaderConfig.data.all_current_header.items[0].logoConnection
|
validatedHeaderConfig.data.all_current_header.items[0].logoConnection
|
||||||
.edges?.[0]?.node
|
.edges?.[0]?.node
|
||||||
@@ -102,10 +145,22 @@ export const baseQueryRouter = router({
|
|||||||
footer: contentstackBaseProcedure
|
footer: contentstackBaseProcedure
|
||||||
.input(langInput)
|
.input(langInput)
|
||||||
.query(async ({ input }) => {
|
.query(async ({ input }) => {
|
||||||
|
console.info(
|
||||||
|
"contentstack.footer.ref start",
|
||||||
|
JSON.stringify({ query: { lang: input.lang } })
|
||||||
|
)
|
||||||
const responseRef = await request<FooterRefDataRaw>(GetCurrentFooterRef, {
|
const responseRef = await request<FooterRefDataRaw>(GetCurrentFooterRef, {
|
||||||
locale: input.lang,
|
locale: input.lang,
|
||||||
})
|
})
|
||||||
|
// There's currently no error handling/validation for the responseRef, should it be added?
|
||||||
|
console.info(
|
||||||
|
"contentstack.footer start",
|
||||||
|
JSON.stringify({
|
||||||
|
query: {
|
||||||
|
lang: input.lang,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
)
|
||||||
const response = await request<FooterDataRaw>(
|
const response = await request<FooterDataRaw>(
|
||||||
GetCurrentFooter,
|
GetCurrentFooter,
|
||||||
{
|
{
|
||||||
@@ -121,16 +176,38 @@ export const baseQueryRouter = router({
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (!response.data) {
|
||||||
|
const notFoundError = notFound(response)
|
||||||
|
console.error(
|
||||||
|
"contentstack.footer not found error",
|
||||||
|
JSON.stringify({
|
||||||
|
query: {
|
||||||
|
lang: input.lang,
|
||||||
|
},
|
||||||
|
error: { code: notFoundError.code },
|
||||||
|
})
|
||||||
|
)
|
||||||
|
throw notFoundError
|
||||||
|
}
|
||||||
|
|
||||||
const validatedFooterConfig = validateFooterConfigSchema.safeParse(
|
const validatedFooterConfig = validateFooterConfigSchema.safeParse(
|
||||||
response.data
|
response.data
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!validatedFooterConfig.success) {
|
if (!validatedFooterConfig.success) {
|
||||||
console.error(`Failed to validate Footer - (lang: ${input.lang})`)
|
console.error(
|
||||||
console.error(validatedFooterConfig.error)
|
"contentstack.footer validation error",
|
||||||
|
JSON.stringify({
|
||||||
|
query: { lang: input.lang },
|
||||||
|
error: validatedFooterConfig.error,
|
||||||
|
})
|
||||||
|
)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
console.info(
|
||||||
|
"contentstack.footer success",
|
||||||
|
JSON.stringify({ query: { lang: input.lang } })
|
||||||
|
)
|
||||||
return validatedFooterConfig.data.all_current_footer.items[0]
|
return validatedFooterConfig.data.all_current_footer.items[0]
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -8,28 +8,50 @@ import { HotelPage, HotelPageDataRaw, validateHotelPageSchema } from "./output"
|
|||||||
export const hotelPageQueryRouter = router({
|
export const hotelPageQueryRouter = router({
|
||||||
get: contentstackBaseProcedure.query(async ({ ctx }) => {
|
get: contentstackBaseProcedure.query(async ({ ctx }) => {
|
||||||
const { lang, uid } = ctx
|
const { lang, uid } = ctx
|
||||||
|
console.info(
|
||||||
|
"contentstack.hotelPage start",
|
||||||
|
JSON.stringify({
|
||||||
|
query: { lang, uid },
|
||||||
|
})
|
||||||
|
)
|
||||||
const response = await request<HotelPageDataRaw>(GetHotelPage, {
|
const response = await request<HotelPageDataRaw>(GetHotelPage, {
|
||||||
locale: lang,
|
locale: lang,
|
||||||
uid,
|
uid,
|
||||||
})
|
})
|
||||||
if (!response.data) {
|
if (!response.data) {
|
||||||
throw notFound(response)
|
const notFoundError = notFound(response)
|
||||||
|
console.error(
|
||||||
|
"contentstack.hotelPage not found error",
|
||||||
|
JSON.stringify({
|
||||||
|
query: { lang, uid },
|
||||||
|
error: { code: notFoundError.code },
|
||||||
|
})
|
||||||
|
)
|
||||||
|
throw notFoundError
|
||||||
}
|
}
|
||||||
|
|
||||||
const validatedHotelPage = validateHotelPageSchema.safeParse(response.data)
|
const validatedHotelPage = validateHotelPageSchema.safeParse(response.data)
|
||||||
|
|
||||||
if (!validatedHotelPage.success) {
|
if (!validatedHotelPage.success) {
|
||||||
console.error(
|
console.error(
|
||||||
`Failed to validate Hotel Page - (uid: ${uid}, lang: ${lang})`
|
"contentstack.hotelPage validation error",
|
||||||
|
JSON.stringify({
|
||||||
|
query: { lang, uid },
|
||||||
|
error: validatedHotelPage.error,
|
||||||
|
})
|
||||||
)
|
)
|
||||||
console.error(validatedHotelPage.error)
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
const hotelPage = {
|
const hotelPage = {
|
||||||
...validatedHotelPage.data.hotel_page,
|
...validatedHotelPage.data.hotel_page,
|
||||||
} as HotelPage
|
} as HotelPage
|
||||||
|
console.info(
|
||||||
|
"contentstack.hotelPage success",
|
||||||
|
JSON.stringify({
|
||||||
|
query: { lang, uid },
|
||||||
|
})
|
||||||
|
)
|
||||||
return hotelPage
|
return hotelPage
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -131,6 +131,16 @@ export const languageSwitcherQueryRouter = router({
|
|||||||
if (!ctx.uid || !ctx.lang) {
|
if (!ctx.uid || !ctx.lang) {
|
||||||
return { lang: ctx.lang, urls: baseUrls }
|
return { lang: ctx.lang, urls: baseUrls }
|
||||||
}
|
}
|
||||||
|
console.info(
|
||||||
|
"contentstack.languageSwitcher start",
|
||||||
|
JSON.stringify({
|
||||||
|
query: {
|
||||||
|
uid: ctx.uid,
|
||||||
|
lang: ctx.lang,
|
||||||
|
contentType: ctx.contentType,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
)
|
||||||
const res = await getLanguageSwitcher({
|
const res = await getLanguageSwitcher({
|
||||||
contentType: ctx.contentType!,
|
contentType: ctx.contentType!,
|
||||||
uid: ctx.uid,
|
uid: ctx.uid,
|
||||||
@@ -155,12 +165,28 @@ export const languageSwitcherQueryRouter = router({
|
|||||||
|
|
||||||
if (!validatedLanguageSwitcherData.success) {
|
if (!validatedLanguageSwitcherData.success) {
|
||||||
console.error(
|
console.error(
|
||||||
`Failed to validate Language Switcher Data - (contentType: ${ctx.contentType}, lang: ${ctx.lang}, uid: ${ctx.uid})`
|
"contentstack.languageSwitcher validation error",
|
||||||
|
JSON.stringify({
|
||||||
|
query: {
|
||||||
|
uid: ctx.uid,
|
||||||
|
lang: ctx.lang,
|
||||||
|
contentType: ctx.contentType,
|
||||||
|
},
|
||||||
|
error: validatedLanguageSwitcherData.error,
|
||||||
|
})
|
||||||
)
|
)
|
||||||
console.error(validatedLanguageSwitcherData.error)
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
console.info(
|
||||||
|
"contentstack.languageSwitcher success",
|
||||||
|
JSON.stringify({
|
||||||
|
query: {
|
||||||
|
uid: ctx.uid,
|
||||||
|
lang: ctx.lang,
|
||||||
|
contentType: ctx.contentType,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
)
|
||||||
return {
|
return {
|
||||||
lang: ctx.lang,
|
lang: ctx.lang,
|
||||||
urls,
|
urls,
|
||||||
|
|||||||
@@ -37,7 +37,12 @@ import {
|
|||||||
export const loyaltyPageQueryRouter = router({
|
export const loyaltyPageQueryRouter = router({
|
||||||
get: contentstackExtendedProcedureUID.query(async ({ ctx }) => {
|
get: contentstackExtendedProcedureUID.query(async ({ ctx }) => {
|
||||||
const { lang, uid } = ctx
|
const { lang, uid } = ctx
|
||||||
|
console.info(
|
||||||
|
"contentstack.loyaltyPage.refs start",
|
||||||
|
JSON.stringify({
|
||||||
|
query: { lang, uid },
|
||||||
|
})
|
||||||
|
)
|
||||||
const refsResponse = await request<LoyaltyPageRefsDataRaw>(
|
const refsResponse = await request<LoyaltyPageRefsDataRaw>(
|
||||||
GetLoyaltyPageRefs,
|
GetLoyaltyPageRefs,
|
||||||
{
|
{
|
||||||
@@ -50,7 +55,18 @@ export const loyaltyPageQueryRouter = router({
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (!refsResponse.data) {
|
if (!refsResponse.data) {
|
||||||
throw notFound(refsResponse)
|
const notFoundError = notFound(refsResponse)
|
||||||
|
console.error(
|
||||||
|
"contentstack.loyaltyPage.refs not found error",
|
||||||
|
JSON.stringify({
|
||||||
|
query: {
|
||||||
|
lang,
|
||||||
|
uid,
|
||||||
|
},
|
||||||
|
error: { code: notFoundError.code },
|
||||||
|
})
|
||||||
|
)
|
||||||
|
throw notFoundError
|
||||||
}
|
}
|
||||||
|
|
||||||
const cleanedData = removeEmptyObjects(refsResponse.data)
|
const cleanedData = removeEmptyObjects(refsResponse.data)
|
||||||
@@ -59,19 +75,32 @@ export const loyaltyPageQueryRouter = router({
|
|||||||
validateLoyaltyPageRefsSchema.safeParse(cleanedData)
|
validateLoyaltyPageRefsSchema.safeParse(cleanedData)
|
||||||
if (!validatedLoyaltyPageRefs.success) {
|
if (!validatedLoyaltyPageRefs.success) {
|
||||||
console.error(
|
console.error(
|
||||||
`Failed to validate Loyaltypage Refs - (lang: ${lang}, uid: ${uid})`
|
"contentstack.loyaltyPage.refs validation error",
|
||||||
|
JSON.stringify({
|
||||||
|
query: { lang, uid },
|
||||||
|
error: validatedLoyaltyPageRefs.error,
|
||||||
|
})
|
||||||
)
|
)
|
||||||
console.error(validatedLoyaltyPageRefs.error)
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
console.info(
|
||||||
|
"contentstack.loyaltyPage.refs success",
|
||||||
|
JSON.stringify({
|
||||||
|
query: { lang, uid },
|
||||||
|
})
|
||||||
|
)
|
||||||
const connections = getConnections(validatedLoyaltyPageRefs.data)
|
const connections = getConnections(validatedLoyaltyPageRefs.data)
|
||||||
|
|
||||||
const tags = [
|
const tags = [
|
||||||
generateTags(lang, connections),
|
generateTags(lang, connections),
|
||||||
generateTag(lang, validatedLoyaltyPageRefs.data.loyalty_page.system.uid),
|
generateTag(lang, validatedLoyaltyPageRefs.data.loyalty_page.system.uid),
|
||||||
].flat()
|
].flat()
|
||||||
|
console.info(
|
||||||
|
"contentstack.loyaltyPage start",
|
||||||
|
JSON.stringify({
|
||||||
|
query: { lang, uid },
|
||||||
|
})
|
||||||
|
)
|
||||||
const response = await request<any>(
|
const response = await request<any>(
|
||||||
GetLoyaltyPage,
|
GetLoyaltyPage,
|
||||||
{
|
{
|
||||||
@@ -82,7 +111,15 @@ export const loyaltyPageQueryRouter = router({
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (!response.data) {
|
if (!response.data) {
|
||||||
throw notFound(response)
|
const notFoundError = notFound(response)
|
||||||
|
console.error(
|
||||||
|
"contentstack.loyaltyPage not found error",
|
||||||
|
JSON.stringify({
|
||||||
|
query: { lang, uid },
|
||||||
|
error: { code: notFoundError.code },
|
||||||
|
})
|
||||||
|
)
|
||||||
|
throw notFoundError
|
||||||
}
|
}
|
||||||
|
|
||||||
const blocks = response.data.loyalty_page.blocks
|
const blocks = response.data.loyalty_page.blocks
|
||||||
@@ -191,9 +228,12 @@ export const loyaltyPageQueryRouter = router({
|
|||||||
validateLoyaltyPageSchema.safeParse(loyaltyPage)
|
validateLoyaltyPageSchema.safeParse(loyaltyPage)
|
||||||
if (!validatedLoyaltyPage.success) {
|
if (!validatedLoyaltyPage.success) {
|
||||||
console.error(
|
console.error(
|
||||||
`Failed to validate Loyaltypage Data - (lang: ${lang}, uid: ${uid})`
|
"contentstack.loyaltyPage validation error",
|
||||||
|
JSON.stringify({
|
||||||
|
query: { lang, uid },
|
||||||
|
error: validatedLoyaltyPage.error,
|
||||||
|
})
|
||||||
)
|
)
|
||||||
console.error(validatedLoyaltyPage.error)
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,7 +245,10 @@ export const loyaltyPageQueryRouter = router({
|
|||||||
channel: TrackingChannelEnum["scandic-friends"],
|
channel: TrackingChannelEnum["scandic-friends"],
|
||||||
pageType: "loyaltycontentpage",
|
pageType: "loyaltycontentpage",
|
||||||
}
|
}
|
||||||
|
console.info(
|
||||||
|
"contentstack.loyaltyPage success",
|
||||||
|
JSON.stringify({ query: { lang, uid } })
|
||||||
|
)
|
||||||
// Assert LoyaltyPage type to get correct typings for RTE fields
|
// Assert LoyaltyPage type to get correct typings for RTE fields
|
||||||
return {
|
return {
|
||||||
loyaltyPage,
|
loyaltyPage,
|
||||||
|
|||||||
@@ -61,7 +61,10 @@ export function mapMenuItems(menuItems: MenuItems) {
|
|||||||
export const navigationQueryRouter = router({
|
export const navigationQueryRouter = router({
|
||||||
get: contentstackBaseProcedure.query(async function ({ ctx }) {
|
get: contentstackBaseProcedure.query(async function ({ ctx }) {
|
||||||
const { lang } = ctx
|
const { lang } = ctx
|
||||||
|
console.info(
|
||||||
|
"contentstack.myPages.navigation.refs start",
|
||||||
|
JSON.stringify({ query: { lang } })
|
||||||
|
)
|
||||||
const refsResponse = await request<GetNavigationMyPagesRefsData>(
|
const refsResponse = await request<GetNavigationMyPagesRefsData>(
|
||||||
GetNavigationMyPagesRefs,
|
GetNavigationMyPagesRefs,
|
||||||
{ locale: lang },
|
{ locale: lang },
|
||||||
@@ -71,19 +74,37 @@ export const navigationQueryRouter = router({
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (!refsResponse.data) {
|
if (!refsResponse.data) {
|
||||||
throw notFound(refsResponse)
|
const notFoundError = notFound(refsResponse)
|
||||||
|
console.error(
|
||||||
|
"contentstack.myPages.navigation.refs not found error",
|
||||||
|
JSON.stringify({
|
||||||
|
query: {
|
||||||
|
lang,
|
||||||
|
},
|
||||||
|
error: { code: notFoundError.code },
|
||||||
|
})
|
||||||
|
)
|
||||||
|
throw notFoundError
|
||||||
}
|
}
|
||||||
|
|
||||||
const validatedMyPagesNavigationRefs =
|
const validatedMyPagesNavigationRefs =
|
||||||
navigationRefsPayloadSchema.safeParse(refsResponse.data)
|
navigationRefsPayloadSchema.safeParse(refsResponse.data)
|
||||||
if (!validatedMyPagesNavigationRefs.success) {
|
if (!validatedMyPagesNavigationRefs.success) {
|
||||||
console.error(
|
console.error(
|
||||||
`Failed to validate My Pages Navigation Refs - (lang: ${lang}`
|
"contentstack.myPages.navigation.refs validation error",
|
||||||
|
JSON.stringify({
|
||||||
|
query: {
|
||||||
|
lang,
|
||||||
|
},
|
||||||
|
error: validatedMyPagesNavigationRefs.error,
|
||||||
|
})
|
||||||
)
|
)
|
||||||
console.error(validatedMyPagesNavigationRefs.error)
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
console.info(
|
||||||
|
"contentstack.myPages.navigation.refs success",
|
||||||
|
JSON.stringify({ query: { lang } })
|
||||||
|
)
|
||||||
const connections = getConnections(validatedMyPagesNavigationRefs.data)
|
const connections = getConnections(validatedMyPagesNavigationRefs.data)
|
||||||
|
|
||||||
const tags = [
|
const tags = [
|
||||||
@@ -94,7 +115,10 @@ export const navigationQueryRouter = router({
|
|||||||
.system.uid
|
.system.uid
|
||||||
),
|
),
|
||||||
].flat()
|
].flat()
|
||||||
|
console.info(
|
||||||
|
"contentstack.myPages.navigation start",
|
||||||
|
JSON.stringify({ query: { lang } })
|
||||||
|
)
|
||||||
const response = await request<GetNavigationMyPagesData>(
|
const response = await request<GetNavigationMyPagesData>(
|
||||||
GetNavigationMyPages,
|
GetNavigationMyPages,
|
||||||
{ locale: lang },
|
{ locale: lang },
|
||||||
@@ -102,7 +126,14 @@ export const navigationQueryRouter = router({
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (!response.data) {
|
if (!response.data) {
|
||||||
throw notFound(response)
|
const notFoundError = notFound(response)
|
||||||
|
console.error("contentstack.myPages.navigation not found error", {
|
||||||
|
query: {
|
||||||
|
lang,
|
||||||
|
},
|
||||||
|
error: { code: notFoundError.code },
|
||||||
|
})
|
||||||
|
throw notFoundError
|
||||||
}
|
}
|
||||||
|
|
||||||
const validatedMyPagesNavigation = navigationPayloadSchema.safeParse(
|
const validatedMyPagesNavigation = navigationPayloadSchema.safeParse(
|
||||||
@@ -110,9 +141,12 @@ export const navigationQueryRouter = router({
|
|||||||
)
|
)
|
||||||
if (!validatedMyPagesNavigation.success) {
|
if (!validatedMyPagesNavigation.success) {
|
||||||
console.error(
|
console.error(
|
||||||
`Failed to validate My Pages Navigation Data - (lang: ${lang}`
|
"contentstack.myPages.navigation.payload validation error",
|
||||||
|
JSON.stringify({
|
||||||
|
query: { lang },
|
||||||
|
error: validatedMyPagesNavigation.error,
|
||||||
|
})
|
||||||
)
|
)
|
||||||
console.error(validatedMyPagesNavigation.error)
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,12 +161,20 @@ export const navigationQueryRouter = router({
|
|||||||
const validatedNav = getNavigationSchema.safeParse(nav)
|
const validatedNav = getNavigationSchema.safeParse(nav)
|
||||||
if (!validatedNav.success) {
|
if (!validatedNav.success) {
|
||||||
console.error(
|
console.error(
|
||||||
`Failed to validate My Pages Navigation Return Data - (lang: ${lang}`
|
"contentstack.myPages.navigation validation error",
|
||||||
|
JSON.stringify({
|
||||||
|
query: { lang },
|
||||||
|
error: validatedNav.error,
|
||||||
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
console.error(validatedNav.error)
|
console.error(validatedNav.error)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
console.info(
|
||||||
|
"contentstack.myPages.navigation success",
|
||||||
|
JSON.stringify({ query: { lang } })
|
||||||
|
)
|
||||||
return validatedNav.data
|
return validatedNav.data
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -32,6 +32,12 @@ export const hotelQueryRouter = router({
|
|||||||
params.include = include.join(",")
|
params.include = include.join(",")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.info(
|
||||||
|
"api.hotels.hotel start",
|
||||||
|
JSON.stringify({
|
||||||
|
query: { hotelId, params: params.toString() },
|
||||||
|
})
|
||||||
|
)
|
||||||
const apiResponse = await api.get(
|
const apiResponse = await api.get(
|
||||||
`${api.endpoints.v1.hotels}/${hotelId}`,
|
`${api.endpoints.v1.hotels}/${hotelId}`,
|
||||||
{
|
{
|
||||||
@@ -44,16 +50,31 @@ export const hotelQueryRouter = router({
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (!apiResponse.ok) {
|
if (!apiResponse.ok) {
|
||||||
console.info(`API Response Failed - Getting Hotel`)
|
const text = await apiResponse.text()
|
||||||
console.error(apiResponse)
|
console.error(
|
||||||
|
"api.hotels.hotel error",
|
||||||
|
JSON.stringify({
|
||||||
|
query: { hotelId, params: params.toString() },
|
||||||
|
error: {
|
||||||
|
status: apiResponse.status,
|
||||||
|
statusText: apiResponse.statusText,
|
||||||
|
text,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
const apiJson = await apiResponse.json()
|
const apiJson = await apiResponse.json()
|
||||||
const validatedHotelData = getHotelDataSchema.safeParse(apiJson)
|
const validatedHotelData = getHotelDataSchema.safeParse(apiJson)
|
||||||
|
|
||||||
if (!validatedHotelData.success) {
|
if (!validatedHotelData.success) {
|
||||||
console.error(`Get Individual Hotel Data - Verified Data Error`)
|
console.error(
|
||||||
console.error(validatedHotelData.error)
|
"api.hotels.hotel validation error",
|
||||||
|
JSON.stringify({
|
||||||
|
query: { hotelId, params: params.toString() },
|
||||||
|
error: validatedHotelData.error,
|
||||||
|
})
|
||||||
|
)
|
||||||
throw badRequestError()
|
throw badRequestError()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,18 +82,28 @@ export const hotelQueryRouter = router({
|
|||||||
|
|
||||||
const roomCategories = included
|
const roomCategories = included
|
||||||
? included
|
? included
|
||||||
.filter((item) => item.type === "roomcategories")
|
.filter((item) => item.type === "roomcategories")
|
||||||
.map((roomCategory) => {
|
.map((roomCategory) => {
|
||||||
const validatedRoom = roomSchema.safeParse(roomCategory)
|
const validatedRoom = roomSchema.safeParse(roomCategory)
|
||||||
if (!validatedRoom.success) {
|
if (!validatedRoom.success) {
|
||||||
console.error(`Get Room Category Data - Verified Data Error`)
|
console.error(
|
||||||
console.error(validatedRoom.error)
|
"api.hotels.hotel validation error",
|
||||||
throw badRequestError()
|
JSON.stringify({
|
||||||
}
|
query: { hotelId, params: params.toString() },
|
||||||
return validatedRoom.data
|
error: validatedRoom.error,
|
||||||
})
|
})
|
||||||
|
)
|
||||||
|
throw badRequestError()
|
||||||
|
}
|
||||||
|
return validatedRoom.data
|
||||||
|
})
|
||||||
: []
|
: []
|
||||||
|
console.info(
|
||||||
|
"api.hotels.hotel success",
|
||||||
|
JSON.stringify({
|
||||||
|
query: { hotelId, params: params.toString() },
|
||||||
|
})
|
||||||
|
)
|
||||||
return {
|
return {
|
||||||
hotel: validatedHotelData.data.data.attributes,
|
hotel: validatedHotelData.data.data.attributes,
|
||||||
roomCategories: roomCategories,
|
roomCategories: roomCategories,
|
||||||
@@ -88,28 +119,51 @@ export const hotelQueryRouter = router({
|
|||||||
// const apiLang = toApiLang(language)
|
// const apiLang = toApiLang(language)
|
||||||
// params.set("hotelId", hotelId.toString())
|
// params.set("hotelId", hotelId.toString())
|
||||||
// params.set("language", apiLang)
|
// params.set("language", apiLang)
|
||||||
|
console.info("api.hotels.rates start", JSON.stringify({}))
|
||||||
const validatedHotelData = getRatesSchema.safeParse(tempRatesData)
|
const validatedHotelData = getRatesSchema.safeParse(tempRatesData)
|
||||||
|
|
||||||
|
if (!tempRatesData) {
|
||||||
|
console.error("api.hotels.rates error", JSON.stringify({ error: null }))
|
||||||
|
//Can't return null here since consuming component does not handle null yet
|
||||||
|
// return null
|
||||||
|
}
|
||||||
if (!validatedHotelData.success) {
|
if (!validatedHotelData.success) {
|
||||||
console.error(`Get Individual Rates Data - Verified Data Error`)
|
console.error(
|
||||||
console.error(validatedHotelData.error)
|
"api.hotels.rates validation error",
|
||||||
|
JSON.stringify({
|
||||||
|
error: validatedHotelData.error,
|
||||||
|
})
|
||||||
|
)
|
||||||
throw badRequestError()
|
throw badRequestError()
|
||||||
}
|
}
|
||||||
|
console.info("api.hotels.rates success", JSON.stringify({}))
|
||||||
return validatedHotelData.data
|
return validatedHotelData.data
|
||||||
}),
|
}),
|
||||||
getFilters: publicProcedure
|
getFilters: publicProcedure
|
||||||
.input(getFiltersInputSchema)
|
.input(getFiltersInputSchema)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
|
console.info("api.hotels.filters start", JSON.stringify({}))
|
||||||
|
|
||||||
|
if (!tempFilterData) {
|
||||||
|
console.error(
|
||||||
|
"api.hotels.filters error",
|
||||||
|
JSON.stringify({ error: null })
|
||||||
|
)
|
||||||
|
//Can't return null here since consuming component does not handle null yet
|
||||||
|
// return null
|
||||||
|
}
|
||||||
const validateFilterData = getFiltersSchema.safeParse(tempFilterData)
|
const validateFilterData = getFiltersSchema.safeParse(tempFilterData)
|
||||||
|
|
||||||
if (!validateFilterData.success) {
|
if (!validateFilterData.success) {
|
||||||
console.info(`Get Individual Filter Data - Verified Data Error`)
|
console.error(
|
||||||
console.error(validateFilterData.error)
|
"api.hotels.filters validation error",
|
||||||
|
JSON.stringify({
|
||||||
|
error: validateFilterData.error,
|
||||||
|
})
|
||||||
|
)
|
||||||
throw badRequestError()
|
throw badRequestError()
|
||||||
}
|
}
|
||||||
|
console.info("api.hotels.rates success", JSON.stringify({}))
|
||||||
return validateFilterData.data
|
return validateFilterData.data
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -14,6 +14,10 @@ export const userMutationRouter = router({
|
|||||||
ctx,
|
ctx,
|
||||||
input,
|
input,
|
||||||
}) {
|
}) {
|
||||||
|
console.info(
|
||||||
|
"api.user.creditCard.add start",
|
||||||
|
JSON.stringify({ query: { language: input.language } })
|
||||||
|
)
|
||||||
const apiResponse = await api.post(api.endpoints.v1.intiateSaveCard, {
|
const apiResponse = await api.post(api.endpoints.v1.intiateSaveCard, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${ctx.session.token.access_token}`,
|
Authorization: `Bearer ${ctx.session.token.access_token}`,
|
||||||
@@ -26,24 +30,43 @@ export const userMutationRouter = router({
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (!apiResponse.ok) {
|
if (!apiResponse.ok) {
|
||||||
console.info(`API Response Failed - Initiating add Creadit Card flow`)
|
const text = await apiResponse.text()
|
||||||
console.error(apiResponse)
|
console.error(
|
||||||
|
"api.user.creditCard.add error",
|
||||||
|
JSON.stringify({
|
||||||
|
query: { language: input.language },
|
||||||
|
error: {
|
||||||
|
status: apiResponse.status,
|
||||||
|
statusText: apiResponse.statusText,
|
||||||
|
error: text,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
const apiJson = await apiResponse.json()
|
const apiJson = await apiResponse.json()
|
||||||
const verifiedData = initiateSaveCardSchema.safeParse(apiJson)
|
const verifiedData = initiateSaveCardSchema.safeParse(apiJson)
|
||||||
if (!verifiedData.success) {
|
if (!verifiedData.success) {
|
||||||
console.error(`Failed to initiate save card data`)
|
console.error(
|
||||||
console.error(verifiedData.error)
|
"api.user.creditCard.add validation error",
|
||||||
|
JSON.stringify({
|
||||||
|
query: { language: input.language },
|
||||||
|
error: verifiedData.error,
|
||||||
|
})
|
||||||
|
)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
console.info(
|
||||||
|
"api.user.creditCard.add success",
|
||||||
|
JSON.stringify({ query: { language: input.language } })
|
||||||
|
)
|
||||||
return verifiedData.data.data
|
return verifiedData.data.data
|
||||||
}),
|
}),
|
||||||
save: protectedProcedure
|
save: protectedProcedure
|
||||||
.input(saveCreditCardInput)
|
.input(saveCreditCardInput)
|
||||||
.mutation(async function ({ ctx, input }) {
|
.mutation(async function ({ ctx, input }) {
|
||||||
|
console.info("api.user.creditCard.save start", JSON.stringify({}))
|
||||||
const apiResponse = await api.post(
|
const apiResponse = await api.post(
|
||||||
`${api.endpoints.v1.creditCards}/${input.transactionId}`,
|
`${api.endpoints.v1.creditCards}/${input.transactionId}`,
|
||||||
{
|
{
|
||||||
@@ -54,16 +77,29 @@ export const userMutationRouter = router({
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (!apiResponse.ok) {
|
if (!apiResponse.ok) {
|
||||||
console.error(`API Response Failed - Save card`)
|
const text = await apiResponse.text()
|
||||||
console.error(apiResponse)
|
console.error(
|
||||||
|
"api.user.creditCard.save error",
|
||||||
|
JSON.stringify({
|
||||||
|
error: {
|
||||||
|
status: apiResponse.status,
|
||||||
|
statusText: apiResponse.statusText,
|
||||||
|
text,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
console.info("api.user.creditCard.save success", JSON.stringify({}))
|
||||||
return true
|
return true
|
||||||
}),
|
}),
|
||||||
delete: protectedProcedure
|
delete: protectedProcedure
|
||||||
.input(deleteCreditCardInput)
|
.input(deleteCreditCardInput)
|
||||||
.mutation(async function ({ ctx, input }) {
|
.mutation(async function ({ ctx, input }) {
|
||||||
|
console.info(
|
||||||
|
"api.user.creditCard.delete start",
|
||||||
|
JSON.stringify({ query: {} })
|
||||||
|
)
|
||||||
const apiResponse = await api.remove(
|
const apiResponse = await api.remove(
|
||||||
`${api.endpoints.v1.creditCards}/${input.creditCardId}`,
|
`${api.endpoints.v1.creditCards}/${input.creditCardId}`,
|
||||||
{
|
{
|
||||||
@@ -74,11 +110,21 @@ export const userMutationRouter = router({
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (!apiResponse.ok) {
|
if (!apiResponse.ok) {
|
||||||
console.error(`API Response Failed - Delete credit card`)
|
const text = await apiResponse.text()
|
||||||
console.error(apiResponse)
|
console.error(
|
||||||
|
"api.user.creditCard.delete error",
|
||||||
|
JSON.stringify({
|
||||||
|
error: {
|
||||||
|
status: apiResponse.status,
|
||||||
|
statusText: apiResponse.statusText,
|
||||||
|
text,
|
||||||
|
},
|
||||||
|
query: {},
|
||||||
|
})
|
||||||
|
)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
console.info("api.user.creditCard.delete success", JSON.stringify({}))
|
||||||
return true
|
return true
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ async function getVerifiedUser({ session }: { session: Session }) {
|
|||||||
if (session.token.expires_at && session.token.expires_at < now) {
|
if (session.token.expires_at && session.token.expires_at < now) {
|
||||||
return { error: true, cause: "token_expired" } as const
|
return { error: true, cause: "token_expired" } as const
|
||||||
}
|
}
|
||||||
|
console.info("api.user.profile start", JSON.stringify({}))
|
||||||
const apiResponse = await api.get(api.endpoints.v1.profile, {
|
const apiResponse = await api.get(api.endpoints.v1.profile, {
|
||||||
cache: "no-store",
|
cache: "no-store",
|
||||||
headers: {
|
headers: {
|
||||||
@@ -51,6 +51,17 @@ async function getVerifiedUser({ session }: { session: Session }) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (!apiResponse.ok) {
|
if (!apiResponse.ok) {
|
||||||
|
const text = await apiResponse.text()
|
||||||
|
console.error(
|
||||||
|
"api.user.profile error",
|
||||||
|
JSON.stringify({
|
||||||
|
error: {
|
||||||
|
status: apiResponse.status,
|
||||||
|
statusText: apiResponse.statusText,
|
||||||
|
text,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
)
|
||||||
if (apiResponse.status === 401) {
|
if (apiResponse.status === 401) {
|
||||||
return { error: true, cause: "unauthorized" } as const
|
return { error: true, cause: "unauthorized" } as const
|
||||||
} else if (apiResponse.status === 403) {
|
} else if (apiResponse.status === 403) {
|
||||||
@@ -67,19 +78,16 @@ async function getVerifiedUser({ session }: { session: Session }) {
|
|||||||
|
|
||||||
const apiJson = await apiResponse.json()
|
const apiJson = await apiResponse.json()
|
||||||
if (!apiJson.data?.attributes) {
|
if (!apiJson.data?.attributes) {
|
||||||
console.error(`User has no data - (user: ${JSON.stringify(session.user)})`)
|
console.error("api.user.profile data error", JSON.stringify({})) // not passing the data to avoid logging sensitive data
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
const verifiedData = getUserSchema.safeParse(apiJson.data.attributes)
|
const verifiedData = getUserSchema.safeParse(apiJson.data.attributes)
|
||||||
if (!verifiedData.success) {
|
if (!verifiedData.success) {
|
||||||
console.error(
|
console.error("api.user.profile validation error", JSON.stringify({})) // not passing the data to avoid logging sensitive data
|
||||||
`Failed to validate User - (User: ${JSON.stringify(session.user)})`
|
|
||||||
)
|
|
||||||
console.error(verifiedData.error)
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
console.info("api.user.profile success", JSON.stringify({}))
|
||||||
return verifiedData
|
return verifiedData
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,6 +117,7 @@ async function updateStaysBookingUrl(
|
|||||||
lang: Lang
|
lang: Lang
|
||||||
) {
|
) {
|
||||||
// Tenporary API call needed till we have user name in ctx session data
|
// Tenporary API call needed till we have user name in ctx session data
|
||||||
|
console.info("api.user.profile start", JSON.stringify({}))
|
||||||
const apiResponse = await api.get(api.endpoints.v1.profile, {
|
const apiResponse = await api.get(api.endpoints.v1.profile, {
|
||||||
cache: "no-store",
|
cache: "no-store",
|
||||||
headers: {
|
headers: {
|
||||||
@@ -145,6 +154,7 @@ async function updateStaysBookingUrl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (apiResponse.ok) {
|
if (apiResponse.ok) {
|
||||||
|
console.info("api.user.profile success", JSON.stringify({}))
|
||||||
const apiJson = await apiResponse.json()
|
const apiJson = await apiResponse.json()
|
||||||
if (apiJson.data?.attributes) {
|
if (apiJson.data?.attributes) {
|
||||||
return data.map((d) => {
|
return data.map((d) => {
|
||||||
@@ -170,6 +180,8 @@ async function updateStaysBookingUrl(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
console.info("api.user.profile error", JSON.stringify({ error: apiResponse }))
|
||||||
|
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -279,6 +291,10 @@ export const userQueryRouter = router({
|
|||||||
const params = new URLSearchParams()
|
const params = new URLSearchParams()
|
||||||
params.set("limit", "1")
|
params.set("limit", "1")
|
||||||
|
|
||||||
|
console.info(
|
||||||
|
"api.booking.stays.past start",
|
||||||
|
JSON.stringify({ query: { params } })
|
||||||
|
)
|
||||||
const previousStaysResponse = await api.get(
|
const previousStaysResponse = await api.get(
|
||||||
api.endpoints.v1.previousStays,
|
api.endpoints.v1.previousStays,
|
||||||
{
|
{
|
||||||
@@ -291,9 +307,14 @@ export const userQueryRouter = router({
|
|||||||
|
|
||||||
if (!previousStaysResponse.ok) {
|
if (!previousStaysResponse.ok) {
|
||||||
console.error(
|
console.error(
|
||||||
`API Response Failed - Getting Previous Stays for tracking user`
|
"api.booking.stays.past error",
|
||||||
|
JSON.stringify({
|
||||||
|
error: {
|
||||||
|
status: previousStaysResponse.status,
|
||||||
|
statusText: previousStaysResponse.statusText,
|
||||||
|
},
|
||||||
|
})
|
||||||
)
|
)
|
||||||
console.error(previousStaysResponse)
|
|
||||||
return notLoggedInUserTrackingData
|
return notLoggedInUserTrackingData
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -301,10 +322,13 @@ export const userQueryRouter = router({
|
|||||||
const verifiedPreviousStaysData =
|
const verifiedPreviousStaysData =
|
||||||
getStaysSchema.safeParse(previousStaysApiJson)
|
getStaysSchema.safeParse(previousStaysApiJson)
|
||||||
if (!verifiedPreviousStaysData.success) {
|
if (!verifiedPreviousStaysData.success) {
|
||||||
console.error(`Failed to validate Previous Stays Data for tracking user`)
|
console.error(
|
||||||
console.error(verifiedPreviousStaysData.error)
|
"api.booking.stays.past validation error, ",
|
||||||
|
JSON.stringify({ error: verifiedPreviousStaysData.error })
|
||||||
|
)
|
||||||
return notLoggedInUserTrackingData
|
return notLoggedInUserTrackingData
|
||||||
}
|
}
|
||||||
|
console.info("api.booking.stays.past success", JSON.stringify({}))
|
||||||
|
|
||||||
const membership = getMembership(verifiedUserData.data.memberships)
|
const membership = getMembership(verifiedUserData.data.memberships)
|
||||||
|
|
||||||
@@ -317,7 +341,6 @@ export const userQueryRouter = router({
|
|||||||
totalPointsAvailableToSpend: membership?.currentPoints,
|
totalPointsAvailableToSpend: membership?.currentPoints,
|
||||||
loginAction: "login success",
|
loginAction: "login success",
|
||||||
}
|
}
|
||||||
|
|
||||||
return loggedInUserTrackingData
|
return loggedInUserTrackingData
|
||||||
}),
|
}),
|
||||||
benefits: router({
|
benefits: router({
|
||||||
@@ -340,6 +363,10 @@ export const userQueryRouter = router({
|
|||||||
if (cursor) {
|
if (cursor) {
|
||||||
params.offset = cursor
|
params.offset = cursor
|
||||||
}
|
}
|
||||||
|
console.info(
|
||||||
|
"api.booking.stays.past start",
|
||||||
|
JSON.stringify({ query: { params: params.toString() } })
|
||||||
|
)
|
||||||
|
|
||||||
const apiResponse = await api.get(
|
const apiResponse = await api.get(
|
||||||
api.endpoints.v1.previousStays,
|
api.endpoints.v1.previousStays,
|
||||||
@@ -362,9 +389,18 @@ export const userQueryRouter = router({
|
|||||||
// default:
|
// default:
|
||||||
// throw internalServerError(apiResponse)
|
// throw internalServerError(apiResponse)
|
||||||
// }
|
// }
|
||||||
console.error(`API Response Failed - Getting Previous Stays`)
|
const text = await apiResponse.text()
|
||||||
console.error(`User: (${JSON.stringify(ctx.session.user)})`)
|
console.error(
|
||||||
console.error(apiResponse)
|
"api.booking.stays.past error ",
|
||||||
|
JSON.stringify({
|
||||||
|
query: { params: params.toString() },
|
||||||
|
error: {
|
||||||
|
status: apiResponse.status,
|
||||||
|
statusText: apiResponse.statusText,
|
||||||
|
text,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -372,12 +408,20 @@ export const userQueryRouter = router({
|
|||||||
|
|
||||||
const verifiedData = getStaysSchema.safeParse(apiJson)
|
const verifiedData = getStaysSchema.safeParse(apiJson)
|
||||||
if (!verifiedData.success) {
|
if (!verifiedData.success) {
|
||||||
console.error(`Failed to validate Previous Stays Data`)
|
console.error(
|
||||||
console.error(`User: (${JSON.stringify(ctx.session.user)})`)
|
"api.booking.stays.past validation error ",
|
||||||
console.error(verifiedData.error)
|
JSON.stringify({
|
||||||
|
query: { params: params.toString() },
|
||||||
|
error: verifiedData.error,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
console.info(
|
||||||
|
"api.booking.stays.past success",
|
||||||
|
JSON.stringify({ query: { params: params.toString() } })
|
||||||
|
)
|
||||||
const nextCursor =
|
const nextCursor =
|
||||||
verifiedData.data.links &&
|
verifiedData.data.links &&
|
||||||
verifiedData.data.links.offset < verifiedData.data.links.totalCount
|
verifiedData.data.links.offset < verifiedData.data.links.totalCount
|
||||||
@@ -405,7 +449,10 @@ export const userQueryRouter = router({
|
|||||||
if (cursor) {
|
if (cursor) {
|
||||||
params.offset = cursor
|
params.offset = cursor
|
||||||
}
|
}
|
||||||
|
console.info(
|
||||||
|
"api.booking.stays.future start",
|
||||||
|
JSON.stringify({ query: { params: params.toString() } })
|
||||||
|
)
|
||||||
const apiResponse = await api.get(
|
const apiResponse = await api.get(
|
||||||
api.endpoints.v1.upcomingStays,
|
api.endpoints.v1.upcomingStays,
|
||||||
{
|
{
|
||||||
@@ -427,21 +474,36 @@ export const userQueryRouter = router({
|
|||||||
// default:
|
// default:
|
||||||
// throw internalServerError(apiResponse)
|
// throw internalServerError(apiResponse)
|
||||||
// }
|
// }
|
||||||
console.error(`API Response Failed - Getting Upcoming Stays`)
|
const text = await apiResponse.text()
|
||||||
console.error(`User: (${JSON.stringify(ctx.session.user)})`)
|
console.error(
|
||||||
console.error(apiResponse)
|
"api.booking.stays.future error ",
|
||||||
|
JSON.stringify({
|
||||||
|
query: { params: params.toString() },
|
||||||
|
error: {
|
||||||
|
status: apiResponse.status,
|
||||||
|
statusText: apiResponse.statusText,
|
||||||
|
text,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
const apiJson = await apiResponse.json()
|
const apiJson = await apiResponse.json()
|
||||||
const verifiedData = getStaysSchema.safeParse(apiJson)
|
const verifiedData = getStaysSchema.safeParse(apiJson)
|
||||||
if (!verifiedData.success) {
|
if (!verifiedData.success) {
|
||||||
console.error(`Failed to validate Upcoming Stays Data`)
|
console.error(
|
||||||
console.error(`User: (${JSON.stringify(ctx.session.user)})`)
|
"api.booking.stays.future validation error ",
|
||||||
console.error(verifiedData.error)
|
JSON.stringify({
|
||||||
|
query: { params: params.toString() },
|
||||||
|
error: verifiedData.error,
|
||||||
|
})
|
||||||
|
)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
console.info("api.booking.stays.future success", {
|
||||||
|
query: { params: params.toString() },
|
||||||
|
})
|
||||||
const nextCursor =
|
const nextCursor =
|
||||||
verifiedData.data.links &&
|
verifiedData.data.links &&
|
||||||
verifiedData.data.links.offset < verifiedData.data.links.totalCount
|
verifiedData.data.links.offset < verifiedData.data.links.totalCount
|
||||||
@@ -465,6 +527,10 @@ export const userQueryRouter = router({
|
|||||||
.input(friendTransactionsInput)
|
.input(friendTransactionsInput)
|
||||||
.query(async ({ ctx, input }) => {
|
.query(async ({ ctx, input }) => {
|
||||||
const { limit, page } = input
|
const { limit, page } = input
|
||||||
|
console.info(
|
||||||
|
"api.transaction.friendTransactions start",
|
||||||
|
JSON.stringify({})
|
||||||
|
)
|
||||||
const apiResponse = await api.get(api.endpoints.v1.friendTransactions, {
|
const apiResponse = await api.get(api.endpoints.v1.friendTransactions, {
|
||||||
cache: undefined, // override defaultOptions
|
cache: undefined, // override defaultOptions
|
||||||
headers: {
|
headers: {
|
||||||
@@ -484,21 +550,34 @@ export const userQueryRouter = router({
|
|||||||
// default:
|
// default:
|
||||||
// throw internalServerError()
|
// throw internalServerError()
|
||||||
// }
|
// }
|
||||||
console.error(`API Response Failed - Getting Friend Transactions`)
|
const text = await apiResponse.text()
|
||||||
console.error(`User: (${JSON.stringify(ctx.session.user)})`)
|
console.error(
|
||||||
console.error(apiResponse)
|
"api.transaction.friendTransactions error ",
|
||||||
|
JSON.stringify({
|
||||||
|
error: {
|
||||||
|
status: apiResponse.status,
|
||||||
|
statusText: apiResponse.statusText,
|
||||||
|
text,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
const apiJson = await apiResponse.json()
|
const apiJson = await apiResponse.json()
|
||||||
const verifiedData = getFriendTransactionsSchema.safeParse(apiJson)
|
const verifiedData = getFriendTransactionsSchema.safeParse(apiJson)
|
||||||
if (!verifiedData.success) {
|
if (!verifiedData.success) {
|
||||||
console.error(`Failed to validate Friend Transactions Data`)
|
console.error(
|
||||||
console.error(`User: (${JSON.stringify(ctx.session.user)})`)
|
"api.transaction.friendTransactions validation error ",
|
||||||
console.error(verifiedData.error)
|
JSON.stringify({ error: verifiedData.error })
|
||||||
|
)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.info(
|
||||||
|
"api.transaction.friendTransactions success",
|
||||||
|
JSON.stringify({})
|
||||||
|
)
|
||||||
const updatedData = await updateStaysBookingUrl(
|
const updatedData = await updateStaysBookingUrl(
|
||||||
verifiedData.data.data,
|
verifiedData.data.data,
|
||||||
ctx.session.token.access_token,
|
ctx.session.token.access_token,
|
||||||
@@ -565,6 +644,7 @@ export const userQueryRouter = router({
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
creditCards: protectedProcedure.query(async function ({ ctx }) {
|
creditCards: protectedProcedure.query(async function ({ ctx }) {
|
||||||
|
console.info("api.profile.creditCards start", JSON.stringify({}))
|
||||||
const apiResponse = await api.get(api.endpoints.v1.creditCards, {
|
const apiResponse = await api.get(api.endpoints.v1.creditCards, {
|
||||||
cache: "no-store",
|
cache: "no-store",
|
||||||
headers: {
|
headers: {
|
||||||
@@ -573,25 +653,35 @@ export const userQueryRouter = router({
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (!apiResponse.ok) {
|
if (!apiResponse.ok) {
|
||||||
console.error(`API Response Failed - Getting Creadit Cards`)
|
const text = await apiResponse.text()
|
||||||
console.error(`User: (${JSON.stringify(ctx.session.user)})`)
|
console.error(
|
||||||
console.error(apiResponse)
|
"api.profile.creditCards error ",
|
||||||
|
JSON.stringify({
|
||||||
|
error: {
|
||||||
|
status: apiResponse.status,
|
||||||
|
statusText: apiResponse.statusText,
|
||||||
|
text,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
const apiJson = await apiResponse.json()
|
const apiJson = await apiResponse.json()
|
||||||
const verifiedData = creditCardsSchema.safeParse(apiJson)
|
const verifiedData = creditCardsSchema.safeParse(apiJson)
|
||||||
if (!verifiedData.success) {
|
if (!verifiedData.success) {
|
||||||
console.error(`Failed to validate Credit Cards Data`)
|
console.error(
|
||||||
console.error(`User: (${JSON.stringify(ctx.session.user)})`)
|
"api.profile.creditCards validation error ",
|
||||||
console.error(verifiedData.error)
|
JSON.stringify({ error: verifiedData.error })
|
||||||
|
)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
console.info("api.profile.creditCards success", JSON.stringify({}))
|
||||||
return verifiedData.data.data
|
return verifiedData.data.data
|
||||||
}),
|
}),
|
||||||
|
|
||||||
membershipCards: protectedProcedure.query(async function ({ ctx }) {
|
membershipCards: protectedProcedure.query(async function ({ ctx }) {
|
||||||
|
console.info("api.profile start", JSON.stringify({}))
|
||||||
const apiResponse = await api.get(api.endpoints.v1.profile, {
|
const apiResponse = await api.get(api.endpoints.v1.profile, {
|
||||||
cache: "no-store",
|
cache: "no-store",
|
||||||
headers: {
|
headers: {
|
||||||
@@ -610,9 +700,17 @@ export const userQueryRouter = router({
|
|||||||
// default:
|
// default:
|
||||||
// throw internalServerError()
|
// throw internalServerError()
|
||||||
// }
|
// }
|
||||||
console.error(`API Response Failed - Getting Membership Cards`)
|
const text = await apiResponse.text()
|
||||||
console.error(`User: (${JSON.stringify(ctx.session.user)})`)
|
console.log(
|
||||||
console.error(apiResponse)
|
"api.profile error",
|
||||||
|
JSON.stringify({
|
||||||
|
error: {
|
||||||
|
status: apiResponse.status,
|
||||||
|
statusText: apiResponse.statusText,
|
||||||
|
text,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const apiJson = await apiResponse.json()
|
const apiJson = await apiResponse.json()
|
||||||
@@ -622,11 +720,13 @@ export const userQueryRouter = router({
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (!verifiedData.success) {
|
if (!verifiedData.success) {
|
||||||
console.error(`Failed to validate Memberships Cards Data`)
|
console.error(
|
||||||
console.error(`User: (${JSON.stringify(ctx.session.user)})`)
|
"api.profile validation error",
|
||||||
console.error(verifiedData.error)
|
JSON.stringify({ error: verifiedData })
|
||||||
|
)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
console.info("api.profile success", JSON.stringify({}))
|
||||||
const cards = getMembershipCards(verifiedData.data)
|
const cards = getMembershipCards(verifiedData.data)
|
||||||
|
|
||||||
return cards
|
return cards
|
||||||
|
|||||||
Reference in New Issue
Block a user