diff --git a/.env.example b/.env.example index 66709accc..7d15205a7 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,6 @@ AEM_GRAPHQL_ENDPOINT = "test.com" +# Code suggests this is optional but it is actually not because of changes in the structure of the response +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" diff --git a/.github/workflows/dast.yml b/.github/workflows/dast.yml index 1098b7426..4e1c6eba3 100644 --- a/.github/workflows/dast.yml +++ b/.github/workflows/dast.yml @@ -19,16 +19,18 @@ jobs: CI: true - name: Docker Build - run: docker build --build-arg AEM_GRAPHQL_ENDPOINT=${{secrets.AEM_GRAPHQL_ENDPOINT}} -t secure-client-hub . + run: docker build --build-arg AEM_GRAPHQL_ENDPOINT=${{secrets.AEM_GRAPHQL_ENDPOINT}} AEM_GRAPHQL_FOLDER=${{secrets.AEM_GRAPHQL_FOLDER}} -t secure-client-hub . env: CI: true AEM_GRAPHQL_ENDPOINT: ${{secrets.AEM_GRAPHQL_ENDPOINT}} + AEM_GRAPHQL_FOLDER: ${{secrets.AEM_GRAPHQL_FOLDER}} - name: Docker run run: docker run -d -p 3000:3000 secure-client-hub env: CI: true AEM_GRAPHQL_ENDPOINT: ${{secrets.AEM_GRAPHQL_ENDPOINT}} + AEM_GRAPHQL_FOLDER: ${{secrets.AEM_GRAPHQL_FOLDER}} - name: OWASP ZAP FULL Scan uses: zaproxy/action-full-scan@v0.9.0 diff --git a/.github/workflows/default-tests.yml b/.github/workflows/default-tests.yml index 0bb894247..69d27131c 100644 --- a/.github/workflows/default-tests.yml +++ b/.github/workflows/default-tests.yml @@ -78,6 +78,7 @@ jobs: env: CI: true AEM_GRAPHQL_ENDPOINT: ${{secrets.AEM_GRAPHQL_ENDPOINT}} + AEM_GRAPHQL_FOLDER: ${{secrets.AEM_GRAPHQL_FOLDER}} AUTH_DISABLED: true - name: Cypress end-to-end 🧪 @@ -86,6 +87,7 @@ jobs: CI: true NODE_ENV: production AEM_GRAPHQL_ENDPOINT: ${{secrets.AEM_GRAPHQL_ENDPOINT}} + AEM_GRAPHQL_FOLDER: ${{secrets.AEM_GRAPHQL_FOLDER}} NEXTAUTH_SECRET: ${{secrets.NEXTAUTH_SECRET}} NEXTAUTH_URL: ${{secrets.NEXTAUTH_URL}} CLIENT_SECRET: ${{secrets.CLIENT_SECRET}} diff --git a/Dockerfile b/Dockerfile index 070b68fcc..b96de0409 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,6 +17,8 @@ ARG LOGGING_LEVEL=info ENV LOGGING_LEVEL=$LOGGING_LEVEL ARG AEM_GRAPHQL_ENDPOINT=https://www.canada.ca/graphql/execute.json/decd-endc/ ENV AEM_GRAPHQL_ENDPOINT=$AEM_GRAPHQL_ENDPOINT +ARG AEM_GRAPHQL_FOLDER +ENV AEM_GRAPHQL_FOLDER=$AEM_GRAPHQL_FOLDER ARG AUTH_ECAS_BASE_URL ENV AUTH_ECAS_BASE_URL=$AUTH_ECAS_BASE_URL ARG MSCA_BASE_URL @@ -99,6 +101,8 @@ ARG LOGGING_LEVEL=info ENV LOGGING_LEVEL=$LOGGING_LEVEL ARG AEM_GRAPHQL_ENDPOINT ENV AEM_GRAPHQL_ENDPOINT=$AEM_GRAPHQL_ENDPOINT +ARG AEM_GRAPHQL_FOLDER +ENV AEM_GRAPHQL_FOLDER=$AEM_GRAPHQL_FOLDER ARG MSCA_BASE_URL ENV MSCA_BASE_URL=$MSCA_BASE_URL ARG MSCA_EQ_BASE_URL diff --git a/graphql/mappers/auth-modals.ts b/graphql/mappers/auth-modals.ts index 81f10b808..1422f707c 100644 --- a/graphql/mappers/auth-modals.ts +++ b/graphql/mappers/auth-modals.ts @@ -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 @@ -38,10 +39,10 @@ interface GetSchAuthModalsV1 { scLinkTextEn: string scLinkTextFr: string }> - } + }> } youHaveBeenSignedOut: { - item: { + items: Array<{ _path: string scId: string scHeadingEn: string @@ -71,7 +72,7 @@ interface GetSchAuthModalsV1 { scDestinationURLEn?: string scDestinationURLFr?: string }> - } + }> } } } @@ -80,12 +81,11 @@ const getCachedContent = () => { return cachified({ key: `content-auth-modals`, cache, - getFreshValue: async () => { - const response = await fetch( - `${process.env.AEM_GRAPHQL_ENDPOINT}getSchAuthModalsV1`, - ) + getFreshValue: async (): Promise => { + 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, }) @@ -93,8 +93,8 @@ const getCachedContent = () => { export async function getAuthModalsContent(): Promise { 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: { diff --git a/graphql/mappers/contact-us-pages-dynamic.ts b/graphql/mappers/contact-us-pages-dynamic.ts index 17021f465..803d6032b 100644 --- a/graphql/mappers/contact-us-pages-dynamic.ts +++ b/graphql/mappers/contact-us-pages-dynamic.ts @@ -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: { @@ -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 => { + 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, }) @@ -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 @@ -202,7 +201,7 @@ export async function getContactUsPage(id: string) { button: destination.scButtonType, } } - } + }, )[0] ?? {}), } } else { @@ -280,7 +279,7 @@ export async function getContactUsPage(id: string) { button: destination.scButtonType, } } - } + }, )[0] ?? {}), } } else { diff --git a/graphql/mappers/contact-us.ts b/graphql/mappers/contact-us.ts index e1aa068a2..b610485e4 100644 --- a/graphql/mappers/contact-us.ts +++ b/graphql/mappers/contact-us.ts @@ -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 @@ -61,9 +62,8 @@ interface GetSchContactUsV1 { scLinkTextAssistiveFr?: string scDestinationURLEn?: string scDestinationURLFr?: string - schBetaPopUp?: boolean }> - } + }> } } } @@ -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 => { + 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, }) @@ -104,7 +103,7 @@ 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, @@ -112,8 +111,8 @@ export async function getContactUsContent() { } }, ), - 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: [ { @@ -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, @@ -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, @@ -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, @@ -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, @@ -164,13 +159,12 @@ 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, @@ -178,8 +172,8 @@ export async function getContactUsContent() { } }, ), - 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: [ { @@ -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, @@ -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, @@ -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, @@ -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, @@ -230,7 +220,6 @@ export async function getContactUsContent() { linkDescription: sinContactFragment?.scDescriptionFr?.json ? sinContactFragment.scDescriptionFr.json[0].content[0].value : '', - schBetaPopup: sinContactFragment?.schBetaPopUp, }, ], }, @@ -238,9 +227,9 @@ export async function getContactUsContent() { 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 ) diff --git a/graphql/mappers/decision-reviews.ts b/graphql/mappers/decision-reviews.ts index 1452cf28c..ec67de742 100644 --- a/graphql/mappers/decision-reviews.ts +++ b/graphql/mappers/decision-reviews.ts @@ -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 @@ -38,7 +38,7 @@ interface GetSchDecisionReviewsV1 { schURLType?: string }> }> - } + }> } } } @@ -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 => { + 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, }) @@ -75,7 +74,7 @@ export async function getDecisionReviewsContent(): Promise { return { link: level.scPageNameEn, @@ -84,8 +83,8 @@ export async function getDecisionReviewsContent(): Promise { return { link: level.scPageNameFr, @@ -127,8 +126,8 @@ export async function getDecisionReviewsContent(): Promise { return ( - res?.data.schPageV1ByPath.item.scFragments.find( + res?.data.schPageV1List.items[0].scFragments.find( ({ scId }) => scId === id, ) ?? null ) diff --git a/graphql/mappers/my-dashboard.ts b/graphql/mappers/my-dashboard.ts index 5b96536d7..fff434514 100644 --- a/graphql/mappers/my-dashboard.ts +++ b/graphql/mappers/my-dashboard.ts @@ -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 GetSchMyDashboardV2 { +interface GetSchMyDashboardV3 { data: { - schPageV1ByPath: { - item: { + schPageV1List: { + items: Array<{ _path: string scPageNameEn: string scPageNameFr: string @@ -76,7 +76,7 @@ interface GetSchMyDashboardV2 { }> }> }> - } + }> } } } @@ -85,12 +85,11 @@ const getCachedContent = () => { return cachified({ key: `content-dashboard`, cache, - getFreshValue: async () => { - const response = await fetch( - `${process.env.AEM_GRAPHQL_ENDPOINT}getSchMyDashboardV2`, - ) + getFreshValue: async (): Promise => { + const targetUri = buildAemUri('getSchMyDashboardV3') + const response = await fetch(targetUri) if (!response.ok) return null - return (await response.json()) as GetSchMyDashboardV2 + return await response.json() }, ttl, }) @@ -98,12 +97,12 @@ const getCachedContent = () => { export async function getMyDashboardContent(): Promise { const response = await getCachedContent() - const pageAlertContent = response?.data.schPageV1ByPath.item.schAlerts + const pageAlertContent = response?.data.schPageV1List.items[0].schAlerts const mappedHome = { en: { - 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, pageAlerts: pageAlertContent?.map((pageAlert) => { return { id: pageAlert.scId, @@ -112,7 +111,7 @@ export async function getMyDashboardContent(): Promise { type: pageAlert.scAlertType, } }), - cards: response?.data.schPageV1ByPath.item.scFragments + cards: response?.data.schPageV1List.items[0].scFragments .find(({ scId }) => scId === 'dashboard-cards') ?.scItems?.map((fragment) => { return { @@ -145,17 +144,17 @@ export async function getMyDashboardContent(): Promise { } }), exitBeta: { - title: response?.data.schPageV1ByPath.item.scFragments.find( + title: response?.data.schPageV1List.items[0].scFragments.find( ({ scId }) => scId === 'exit-beta-version', )?.scTitleEn, - link: response?.data.schPageV1ByPath.item.scFragments.find( + link: response?.data.schPageV1List.items[0].scFragments.find( ({ scId }) => scId === 'exit-beta-version', )?.scDestinationURLEn, }, }, fr: { - 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, pageAlerts: pageAlertContent?.map((pageAlert) => { return { id: pageAlert.scId, @@ -164,7 +163,7 @@ export async function getMyDashboardContent(): Promise { type: pageAlert.scAlertType, } }), - cards: response?.data.schPageV1ByPath.item.scFragments + cards: response?.data.schPageV1List.items[0].scFragments .find(({ scId }) => scId === 'dashboard-cards') ?.scItems?.map((fragment) => { if (!fragment.scId) return @@ -198,10 +197,10 @@ export async function getMyDashboardContent(): Promise { } }), exitBeta: { - title: response?.data.schPageV1ByPath.item.scFragments.find( + title: response?.data.schPageV1List.items[0].scFragments.find( ({ scId }) => scId === 'exit-beta-version', )?.scTitleFr, - link: response?.data.schPageV1ByPath.item.scFragments.find( + link: response?.data.schPageV1List.items[0].scFragments.find( ({ scId }) => scId === 'exit-beta-version', )?.scDestinationURLFr, }, diff --git a/graphql/mappers/profile.ts b/graphql/mappers/profile.ts index 5a31e1ddd..d66d90d41 100644 --- a/graphql/mappers/profile.ts +++ b/graphql/mappers/profile.ts @@ -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 GetSchProfileV1 { +interface GetSchProfileV2 { data: { - schPageV1ByPath: { - item: { + schPageV1List: { + items: Array<{ _path: string scTitleEn: string scTitleFr: string @@ -61,7 +61,7 @@ interface GetSchProfileV1 { scDestinationURLEn?: string scDestinationURLFr?: string }> - } + }> } } } @@ -70,12 +70,11 @@ const getCachedContent = () => { return cachified({ key: `content-profile`, cache, - getFreshValue: async () => { - const response = await fetch( - `${process.env.AEM_GRAPHQL_ENDPOINT}getSchProfileV1`, - ) + getFreshValue: async (): Promise => { + const targetUri = buildAemUri('getSchProfileV2') + const response = await fetch(targetUri) if (!response.ok) return null - return (await response.json()) as GetSchProfileV1 + return await response.json() }, ttl, }) @@ -104,7 +103,7 @@ export async function getProfileContent(): Promise { const mappedProfile = { en: { breadcrumb: - response?.data.schPageV1ByPath.item.scBreadcrumbParentPages.map( + response?.data.schPageV1List.items[0].scBreadcrumbParentPages.map( (level) => { return { link: level.scPageNameEn, @@ -112,9 +111,9 @@ export async function getProfileContent(): Promise { } }, ), - pageName: response?.data.schPageV1ByPath.item.scTitleEn, + pageName: response?.data.schPageV1List.items[0].scTitleEn, heading: profileIntroFragment?.scContentEn?.json[0].content[0].value, - list: response?.data.schPageV1ByPath.item.scFragments + list: response?.data.schPageV1List.items[0].scFragments .map((element) => { if ( element.scId === 'ei-profile-list' || @@ -156,7 +155,7 @@ export async function getProfileContent(): Promise { }, fr: { breadcrumb: - response?.data.schPageV1ByPath.item.scBreadcrumbParentPages.map( + response?.data.schPageV1List.items[0].scBreadcrumbParentPages.map( (level) => { return { link: level.scPageNameFr, @@ -164,9 +163,9 @@ export async function getProfileContent(): Promise { } }, ), - pageName: response?.data.schPageV1ByPath.item.scTitleFr, + pageName: response?.data.schPageV1List.items[0].scTitleFr, heading: profileIntroFragment?.scContentFr?.json[0].content[0].value, - list: response?.data.schPageV1ByPath.item.scFragments + list: response?.data.schPageV1List.items[0].scFragments .map((element) => { if ( element.scId === 'ei-profile-list' || @@ -210,9 +209,9 @@ export async function getProfileContent(): Promise { return mappedProfile } -const findFragmentByScId = (res: GetSchProfileV1 | null, id: string) => { +const findFragmentByScId = (res: GetSchProfileV2 | null, id: string) => { return ( - res?.data.schPageV1ByPath.item.scFragments.find( + res?.data.schPageV1List.items[0].scFragments.find( ({ scId }) => scId === id, ) ?? null ) diff --git a/graphql/mappers/security-settings.ts b/graphql/mappers/security-settings.ts index 3ffbf464f..578cdaf6c 100644 --- a/graphql/mappers/security-settings.ts +++ b/graphql/mappers/security-settings.ts @@ -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 GetSchSecuritySettingsV1 { +interface GetSchSecuritySettingsV2 { data: { - schPageV1ByPath: { - item: { + schPageV1List: { + items: Array<{ _path: string scPageNameEn: string scPageNameFr: string @@ -38,7 +38,7 @@ interface GetSchSecuritySettingsV1 { nodeType: string content: Array<{ nodeType: string - value?: string + value: string data?: { href: string } @@ -85,7 +85,7 @@ interface GetSchSecuritySettingsV1 { scTitleEn?: string scTitleFr?: string }> - } + }> } } } @@ -94,12 +94,11 @@ const getCachedContent = () => { return cachified({ key: `content-security-settings`, cache, - getFreshValue: async () => { - const response = await fetch( - `${process.env.AEM_GRAPHQL_ENDPOINT}getSchSecuritySettingsV1`, - ) + getFreshValue: async (): Promise => { + const targetUri = buildAemUri('getSchSecuritySettingsV2') + const response = await fetch(targetUri) if (!response.ok) return null - return (await response.json()) as GetSchSecuritySettingsV1 + return await response.json() }, ttl, }) @@ -125,12 +124,14 @@ export async function getSecuritySettingsContent(): Promise scId === 'security-questions') ?? null + )?.scFragments?.find( + ({ scId }: { scId: string }) => scId === 'security-questions', + ) ?? null const mappedSecurity = { en: { breadcrumb: - response?.data.schPageV1ByPath.item.scBreadcrumbParentPages.map( + response?.data.schPageV1List.items[0].scBreadcrumbParentPages.map( (level) => { return { link: level.scPageNameEn, @@ -138,13 +139,15 @@ export async function getSecuritySettingsContent(): Promise value ?? null, + ({ value }: { value: string }) => { + return value || null + }, ), link: '/profile', id: 'profile', @@ -162,7 +165,7 @@ export async function getSecuritySettingsContent(): Promise { return { link: level.scPageNameFr, @@ -170,14 +173,16 @@ export async function getSecuritySettingsContent(): Promise { - return element.value || null - }), + subText: frLookingForFragment?.json[1].content.map( + ({ value }: { value: string }) => { + return value || null + }, + ), link: '/fr/profil', id: 'profile', }, @@ -197,11 +202,11 @@ export async function getSecuritySettingsContent(): Promise { return ( - res?.data.schPageV1ByPath.item.scFragments.find( + res?.data.schPageV1List.items[0].scFragments.find( ({ scId }) => scId === id, ) ?? null ) diff --git a/helmfile/overrides/secure-client-hub/dev/secure-client-hub.yaml.gotmpl b/helmfile/overrides/secure-client-hub/dev/secure-client-hub.yaml.gotmpl index 51676453b..4eac61195 100644 --- a/helmfile/overrides/secure-client-hub/dev/secure-client-hub.yaml.gotmpl +++ b/helmfile/overrides/secure-client-hub/dev/secure-client-hub.yaml.gotmpl @@ -28,6 +28,8 @@ extraEnv: value: {{ .Environment.Name }} - name: AEM_GRAPHQL_ENDPOINT value: {{ env "AEM_GRAPHQL_ENDPOINT" | quote }} + - name: AEM_GRAPHQL_FOLDER + value: {{ env "AEM_GRAPHQL_FOLDER" | quote }} - name: MSCA_BASE_URL value: {{ env "MSCA_BASE_URL" }} - name: MSCA_EQ_BASE_URL diff --git a/helmfile/overrides/secure-client-hub/prod/secure-client-hub.yaml.gotmpl b/helmfile/overrides/secure-client-hub/prod/secure-client-hub.yaml.gotmpl index 394205f31..ec096c033 100644 --- a/helmfile/overrides/secure-client-hub/prod/secure-client-hub.yaml.gotmpl +++ b/helmfile/overrides/secure-client-hub/prod/secure-client-hub.yaml.gotmpl @@ -28,6 +28,8 @@ extraEnv: value: {{ .Environment.Name }} - name: AEM_GRAPHQL_ENDPOINT value: {{ env "AEM_GRAPHQL_ENDPOINT" | quote }} + - name: AEM_GRAPHQL_FOLDER + value: {{ env "AEM_GRAPHQL_FOLDER" | quote }} - name: MSCA_BASE_URL value: {{ env "MSCA_BASE_URL" }} - name: MSCA_EQ_BASE_URL diff --git a/lib/links.ts b/lib/links.ts index afa1b8a94..fe2a18414 100644 --- a/lib/links.ts +++ b/lib/links.ts @@ -15,3 +15,15 @@ export function buildLink(linkType: string | undefined, link: string) { return link } } + +export function buildAemUri(endpointName: string) { + if (process.env.AEM_GRAPHQL_FOLDER !== undefined) { + return ( + process.env.AEM_GRAPHQL_ENDPOINT + + endpointName + + '%3BfolderName=' + + encodeURIComponent(process.env.AEM_GRAPHQL_FOLDER) + ) + } + return process.env.AEM_GRAPHQL_ENDPOINT + endpointName +}