Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow AEM folder to be specified #783

Merged
merged 5 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
AEM_GRAPHQL_ENDPOINT = "test.com"
AEM_GRAPHQL_FOLDER = "test_folder/path"
LOGGING_LEVEL = " info or debug"
MSCA_BASE_URL = "MSCA base url"
MSCA_EQ_BASE_URL = "MSCA base url with eq extension"
Expand Down
24 changes: 12 additions & 12 deletions graphql/mappers/auth-modals.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { cachified } from 'cachified'
import { lruCache as cache, defaultTtl as ttl } from '../../lib/cache-utils'
import { buildAemUri } from '../../lib/links'

interface GetSchAuthModalsV1 {
interface GetSchAuthModalsV2 {
data: {
staySignedIn: {
item: {
items: Array<{
_path: string
scId: string
scHeadingEn: string
Expand Down Expand Up @@ -38,10 +39,10 @@ interface GetSchAuthModalsV1 {
scLinkTextEn: string
scLinkTextFr: string
}>
}
}>
}
youHaveBeenSignedOut: {
item: {
items: Array<{
_path: string
scId: string
scHeadingEn: string
Expand Down Expand Up @@ -71,7 +72,7 @@ interface GetSchAuthModalsV1 {
scDestinationURLEn?: string
scDestinationURLFr?: string
}>
}
}>
}
}
}
Expand All @@ -80,21 +81,20 @@ const getCachedContent = () => {
return cachified({
key: `content-auth-modals`,
cache,
getFreshValue: async () => {
const response = await fetch(
`${process.env.AEM_GRAPHQL_ENDPOINT}getSchAuthModalsV1`,
)
getFreshValue: async (): Promise<GetSchAuthModalsV2 | null> => {
const targetUri = buildAemUri('getSchAuthModalsV2')
const response = await fetch(targetUri)
if (!response.ok) return null
return (await response.json()) as GetSchAuthModalsV1
return await response.json()
},
ttl,
})
}

export async function getAuthModalsContent(): Promise<AuthModalsContent> {
const response = await getCachedContent()
const resSignedOutContent = response?.data.youHaveBeenSignedOut.item
const resStaySignedIn = response?.data.staySignedIn.item
const resSignedOutContent = response?.data.youHaveBeenSignedOut.items[0]
const resStaySignedIn = response?.data.staySignedIn.items[0]

const mappedPopupSignedOut = {
en: {
Expand Down
17 changes: 8 additions & 9 deletions graphql/mappers/contact-us-pages-dynamic.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { cachified } from 'cachified'
import { lruCache as cache, defaultTtl as ttl } from '../../lib/cache-utils'
import { buildAemUri } from '../../lib/links'

interface GetSchContactUsDynamicV1 {
data: {
Expand Down Expand Up @@ -120,13 +121,11 @@ const getCachedContent = () => {
return cachified({
key: `content-dynamic-contact-us`,
cache,
getFreshValue: async () => {
const response = await fetch(
`${process.env.AEM_GRAPHQL_ENDPOINT}getSchContactUsDynamicV1`
)

getFreshValue: async (): Promise<GetSchContactUsDynamicV1 | null> => {
const targetUri = buildAemUri('getSchContactUsDynamicV1')
const response = await fetch(targetUri)
if (!response.ok) return null
return (await response.json()) as GetSchContactUsDynamicV1
return await response.json()
},
ttl,
})
Expand All @@ -143,7 +142,7 @@ export type GetContactUsPageReturnType = Awaited<
export async function getContactUsPage(id: string) {
const response = await getCachedContent()
const queryData = response?.data.schPageV1List.items.find(
({ scId }) => scId === id
({ scId }) => scId === id,
)

// Fail fast if a non-existent page is queried
Expand Down Expand Up @@ -202,7 +201,7 @@ export async function getContactUsPage(id: string) {
button: destination.scButtonType,
}
}
}
},
)[0] ?? {}),
}
} else {
Expand Down Expand Up @@ -280,7 +279,7 @@ export async function getContactUsPage(id: string) {
button: destination.scButtonType,
}
}
}
},
)[0] ?? {}),
}
} else {
Expand Down
45 changes: 17 additions & 28 deletions graphql/mappers/contact-us.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { cachified } from 'cachified'
import { lruCache as cache, defaultTtl as ttl } from '../../lib/cache-utils'
import { buildAemUri } from '../../lib/links'

interface GetSchContactUsV1 {
interface GetSchContactUsV2 {
data: {
schPageV1ByPath: {
item: {
schPageV1List: {
items: Array<{
_path: string
scPageNameEn: string
scPageNameFr: string
Expand Down Expand Up @@ -61,9 +62,8 @@ interface GetSchContactUsV1 {
scLinkTextAssistiveFr?: string
scDestinationURLEn?: string
scDestinationURLFr?: string
schBetaPopUp?: boolean
}>
}
}>
}
}
}
Expand All @@ -72,12 +72,11 @@ const getCachedContent = () => {
return cachified({
key: `content-contact-landing-page`,
cache,
getFreshValue: async () => {
const response = await fetch(
`${process.env.AEM_GRAPHQL_ENDPOINT}getSchContactUsV1`,
)
getFreshValue: async (): Promise<GetSchContactUsV2 | null> => {
const targetUri = buildAemUri('getSchContactUsV2')
const response = await fetch(targetUri)
if (!response.ok) return null
return (await response.json()) as GetSchContactUsV1
return await response.json()
},
ttl,
})
Expand All @@ -104,16 +103,16 @@ export async function getContactUsContent() {
const mappedSecurity = {
en: {
breadcrumb:
response?.data.schPageV1ByPath.item.scBreadcrumbParentPages.map(
response?.data.schPageV1List.items[0].scBreadcrumbParentPages.map(
(level) => {
return {
link: level.scPageNameEn,
text: level.scTitleEn,
}
},
),
pageName: response?.data.schPageV1ByPath.item.scPageNameEn,
heading: response?.data.schPageV1ByPath.item.scTitleEn,
pageName: response?.data.schPageV1List.items[0].scPageNameEn,
heading: response?.data.schPageV1List.items[0].scTitleEn,
subHeading: introFragment?.scContentEn?.json[0].content[0].value,
links: [
{
Expand All @@ -124,7 +123,6 @@ export async function getContactUsContent() {
linkDescription: cdcpContactFragment?.scDescriptionEn?.json
? cdcpContactFragment.scDescriptionEn.json[0].content[0].value
: '',
schBetaPopup: cdcpContactFragment?.schBetaPopUp,
},
{
linkId: eiContactFragment?.scId,
Expand All @@ -134,7 +132,6 @@ export async function getContactUsContent() {
linkDescription: eiContactFragment?.scDescriptionEn?.json
? eiContactFragment.scDescriptionEn.json[0].content[0].value
: '',
schBetaPopup: eiContactFragment?.schBetaPopUp,
},
{
linkId: cppContactFragment?.scId,
Expand All @@ -144,7 +141,6 @@ export async function getContactUsContent() {
linkDescription: cppContactFragment?.scDescriptionEn?.json
? cppContactFragment.scDescriptionEn.json[0].content[0].value
: '',
schBetaPopup: cppContactFragment?.schBetaPopUp,
},
{
linkId: oasContactFragment?.scId,
Expand All @@ -154,7 +150,6 @@ export async function getContactUsContent() {
linkDescription: oasContactFragment?.scDescriptionEn?.json
? oasContactFragment.scDescriptionEn.json[0].content[0].value
: '',
schBetaPopup: oasContactFragment?.schBetaPopUp,
},
{
linkId: sinContactFragment?.scId,
Expand All @@ -164,22 +159,21 @@ export async function getContactUsContent() {
linkDescription: sinContactFragment?.scDescriptionEn?.json
? sinContactFragment.scDescriptionEn.json[0].content[0].value
: '',
schBetaPopup: sinContactFragment?.schBetaPopUp,
},
],
},
fr: {
breadcrumb:
response?.data.schPageV1ByPath.item.scBreadcrumbParentPages.map(
response?.data.schPageV1List.items[0].scBreadcrumbParentPages.map(
(level) => {
return {
link: level.scPageNameFr,
text: level.scTitleFr,
}
},
),
pageName: response?.data.schPageV1ByPath.item.scPageNameFr,
heading: response?.data.schPageV1ByPath.item.scTitleFr,
pageName: response?.data.schPageV1List.items[0].scPageNameFr,
heading: response?.data.schPageV1List.items[0].scTitleFr,
subHeading: introFragment?.scContentFr?.json[0].content[0].value,
links: [
{
Expand All @@ -190,7 +184,6 @@ export async function getContactUsContent() {
linkDescription: cdcpContactFragment?.scDescriptionFr?.json
? cdcpContactFragment.scDescriptionFr.json[0].content[0].value
: '',
schBetaPopup: cdcpContactFragment?.schBetaPopUp,
},
{
linkId: eiContactFragment?.scId,
Expand All @@ -200,7 +193,6 @@ export async function getContactUsContent() {
linkDescription: eiContactFragment?.scDescriptionFr?.json
? eiContactFragment.scDescriptionFr.json[0].content[0].value
: '',
schBetaPopup: eiContactFragment?.schBetaPopUp,
},
{
linkId: cppContactFragment?.scId,
Expand All @@ -210,7 +202,6 @@ export async function getContactUsContent() {
linkDescription: cppContactFragment?.scDescriptionFr?.json
? cppContactFragment.scDescriptionFr.json[0].content[0].value
: '',
schBetaPopup: cppContactFragment?.schBetaPopUp,
},
{
linkId: oasContactFragment?.scId,
Expand All @@ -220,7 +211,6 @@ export async function getContactUsContent() {
linkDescription: oasContactFragment?.scDescriptionFr?.json
? oasContactFragment.scDescriptionFr.json[0].content[0].value
: '',
schBetaPopup: oasContactFragment?.schBetaPopUp,
},
{
linkId: sinContactFragment?.scId,
Expand All @@ -230,17 +220,16 @@ export async function getContactUsContent() {
linkDescription: sinContactFragment?.scDescriptionFr?.json
? sinContactFragment.scDescriptionFr.json[0].content[0].value
: '',
schBetaPopup: sinContactFragment?.schBetaPopUp,
},
],
},
}
return mappedSecurity
}

const findFragmentByScId = (res: GetSchContactUsV1 | null, id: string) => {
const findFragmentByScId = (res: GetSchContactUsV2 | null, id: string) => {
return (
res?.data.schPageV1ByPath.item.scFragments.find(
res?.data.schPageV1List.items[0].scFragments.find(
({ scId }) => scId === id,
) ?? null
)
Expand Down
35 changes: 17 additions & 18 deletions graphql/mappers/decision-reviews.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { buildLink } from '../../lib/links'
import { buildAemUri, buildLink } from '../../lib/links'
import { cachified } from 'cachified'
import { lruCache as cache, defaultTtl as ttl } from '../../lib/cache-utils'

interface GetSchDecisionReviewsV1 {
interface GetSchDecisionReviewsV2 {
data: {
schPageV1ByPath: {
item: {
schPageV1List: {
items: Array<{
_path: string
scPageNameEn: string
scPageNameFr: string
Expand Down Expand Up @@ -38,7 +38,7 @@ interface GetSchDecisionReviewsV1 {
schURLType?: string
}>
}>
}
}>
}
}
}
Expand All @@ -47,12 +47,11 @@ const getCachedContent = () => {
return cachified({
key: `content-decision-reviews`,
cache,
getFreshValue: async () => {
const response = await fetch(
`${process.env.AEM_GRAPHQL_ENDPOINT}getSchDecisionReviewsV1`,
)
getFreshValue: async (): Promise<GetSchDecisionReviewsV2 | null> => {
const targetUri = buildAemUri('getSchDecisionReviewsV2')
const response = await fetch(targetUri)
if (!response.ok) return null
return (await response.json()) as GetSchDecisionReviewsV1
return await response.json()
},
ttl,
})
Expand All @@ -75,7 +74,7 @@ export async function getDecisionReviewsContent(): Promise<DecisionReviewContent
en: {
id: 'request-review-decision',
breadcrumb:
response?.data.schPageV1ByPath.item.scBreadcrumbParentPages.map(
response?.data.schPageV1List.items[0].scBreadcrumbParentPages.map(
(level) => {
return {
link: level.scPageNameEn,
Expand All @@ -84,8 +83,8 @@ export async function getDecisionReviewsContent(): Promise<DecisionReviewContent
}
},
),
pageName: response?.data.schPageV1ByPath.item.scPageNameEn,
heading: response?.data.schPageV1ByPath.item.scTitleEn,
pageName: response?.data.schPageV1List.items[0].scPageNameEn,
heading: response?.data.schPageV1List.items[0].scTitleEn,
content: [
{
content: askFragment?.scContentEn.markdown,
Expand Down Expand Up @@ -118,7 +117,7 @@ export async function getDecisionReviewsContent(): Promise<DecisionReviewContent
fr: {
id: 'demande-revision',
breadcrumb:
response?.data.schPageV1ByPath.item.scBreadcrumbParentPages.map(
response?.data.schPageV1List.items[0].scBreadcrumbParentPages.map(
(level) => {
return {
link: level.scPageNameFr,
Expand All @@ -127,8 +126,8 @@ export async function getDecisionReviewsContent(): Promise<DecisionReviewContent
}
},
),
pageName: response?.data.schPageV1ByPath.item.scPageNameFr,
heading: response?.data.schPageV1ByPath.item.scTitleFr,
pageName: response?.data.schPageV1List.items[0].scPageNameFr,
heading: response?.data.schPageV1List.items[0].scTitleFr,
content: [
{
content: askFragment?.scContentFr.markdown,
Expand Down Expand Up @@ -163,11 +162,11 @@ export async function getDecisionReviewsContent(): Promise<DecisionReviewContent
}

const findFragmentByScId = (
res: GetSchDecisionReviewsV1 | null,
res: GetSchDecisionReviewsV2 | null,
id: string,
) => {
return (
res?.data.schPageV1ByPath.item.scFragments.find(
res?.data.schPageV1List.items[0].scFragments.find(
({ scId }) => scId === id,
) ?? null
)
Expand Down
Loading
Loading