Skip to content

Commit

Permalink
Merge pull request #783 from DTS-STN/typescript-conversion
Browse files Browse the repository at this point in the history
Allow AEM folder to be specified
  • Loading branch information
Charles-Pham authored Dec 20, 2024
2 parents 7ed55bf + bba713f commit e515e95
Show file tree
Hide file tree
Showing 14 changed files with 147 additions and 131 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/dast.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/default-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 🧪
Expand All @@ -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}}
Expand Down
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
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
Loading

0 comments on commit e515e95

Please sign in to comment.