Skip to content

Commit

Permalink
Merge branch 'main' into DDFBRA-201-go-anonym-og-indlogget-bruger-kan…
Browse files Browse the repository at this point in the history
…-prove-lydbog
  • Loading branch information
ThomasGross committed Nov 27, 2024
2 parents aaa3593 + 7db9ba9 commit 0e1edc3
Show file tree
Hide file tree
Showing 41 changed files with 491 additions and 203 deletions.
13 changes: 7 additions & 6 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
NEXT_PUBLIC_GRAPHQL_SCHEMA_ENDPOINT_DPL_CMS=http://dapple-cms.docker/graphql
NEXT_PUBLIC_GRAPHQL_BASIC_TOKEN_DPL_CMS=Z3JhcGhxbF9jb25zdW1lcjp0ZXN0

NEXT_PUBLIC_GRAPHQL_SCHEMA_ENDPOINT_FBI=https://temp.fbi-api.dbc.dk/ereolgo/graphql
// WILL BE REPLACED WITH DYNAMIC TOKEN
NEXT_PUBLIC_LIBRARY_TOKEN=XXX

UNILOGIN_SESSION_SECRET=XXX
UNILOGIN_API_URL=https://et-broker.unilogin.dk
UNILOGIN_WELKNOWN_URL=https://et-broker.unilogin.dk/auth/realms/broker/.well-known/openid-configuration
UNILOGIN_CLIENT_ID=XXX
UNILOGIN_CLIENT_SECRET=XXXX
NEXT_PUBLIC_APP_URL=http://localhost:3000
UNILOGIN_CLIENT_ID=https://stg.ereolengo.itkdev.dk/
UNILOGIN_CLIENT_SECRET=XXX
UNILOGIN_SESSION_SECRET=XXX

NEXT_PUBLIC_APP_URL=https://localhost:3000
13 changes: 7 additions & 6 deletions .env.test
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
NEXT_PUBLIC_GRAPHQL_SCHEMA_ENDPOINT_DPL_CMS=http://dapple-cms.docker/graphql
NEXT_PUBLIC_GRAPHQL_BASIC_TOKEN_DPL_CMS=Z3JhcGhxbF9jb25zdW1lcjp0ZXN0

NEXT_PUBLIC_GRAPHQL_SCHEMA_ENDPOINT_FBI=https://temp.fbi-api.dbc.dk/ereolgo/graphql
// WILL BE REPLACED WITH DYNAMIC TOKEN
NEXT_PUBLIC_LIBRARY_TOKEN=XXX

UNILOGIN_SESSION_SECRET=XXX
UNILOGIN_API_URL=https://et-broker.unilogin.dk
UNILOGIN_WELKNOWN_URL=https://et-broker.unilogin.dk/auth/realms/broker/.well-known/openid-configuration
UNILOGIN_CLIENT_ID=XXX
UNILOGIN_CLIENT_SECRET=XXXX
UNILOGIN_CLIENT_ID=https://stg.ereolengo.itkdev.dk/
UNILOGIN_CLIENT_SECRET=XXX
UNILOGIN_SESSION_SECRET=XXX

NEXT_PUBLIC_APP_URL=https://hellboy.the-movie.com
LAGOON_AUTOGENERATED_ROUTES=https://nginx.acme.com,https://node.acme.com,https://varnish.acme.com
UNILOGIN_WELLKNOWN_URL=https://hi-i-am-well-known-url.com
23 changes: 23 additions & 0 deletions .github/workflows/publish-source.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,25 @@ jobs:
else
echo ::set-output name=IS_RELEASE_TAG::false
fi
- uses: actions/setup-node@v4
if: ${{ steps.detect_tag.outputs.IS_RELEASE_TAG == 'true' }}
with:
node-version-file: ".nvmrc"

- name: Install dependencies
if: ${{ steps.detect_tag.outputs.IS_RELEASE_TAG == 'true' }}
run: yarn install --frozen-lockfile

- name: Run CI checks
if: ${{ steps.detect_tag.outputs.IS_RELEASE_TAG == 'true' }}
run: |
yarn ci-check
if [ $? -ne 0 ]; then
echo "Code quality checks failed"
exit 1
fi
# Extract version from tag.
- name: Get version
id: get_version
Expand All @@ -41,3 +60,7 @@ jobs:
env:
CR_PAT: ${{ secrets.GITHUB_TOKEN }}
RELEASE_TAG: ${{ steps.get_version.outputs.RELEASE_TAG }}

- name: Adding summary
run: |
echo "Source image was successfully build (version: ${{ github.ref }}) 🚀😎" >> $GITHUB_STEP_SUMMARY
33 changes: 25 additions & 8 deletions __tests__/config.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
import { renderHook, waitFor } from "@testing-library/react"
import { describe } from "node:test"
import { expect, test } from "vitest"

import goConfig from "@/lib/config/config"
import MissingConfigurationError from "@/lib/config/errors/MissingConfigurationError"
import goConfig from "@/lib/config/goConfig"
import useGoConfig from "@/lib/config/useGoConfig"

test("That an error is thrown if we ask for unknown config", async () => {
// @ts-ignore
expect(() => goConfig("unknown.thingy")).toThrowError(MissingConfigurationError)
})
describe("Config test suite", () => {
test("That an error is thrown if we ask for unknown config", async () => {
// @ts-ignore
expect(() => goConfig("unknown.thingy")).toThrowError(MissingConfigurationError)
})

test("That the env variable NEXT_PUBLIC_APP_URL has precedence over LAGOON_AUTOGENERATED_ROUTES", async () => {
const appUrl = goConfig("app.url")
expect(appUrl).toBe("https://hellboy.the-movie.com")
})

test("That the client hook returns configuration as expected", async () => {
const { result } = renderHook(() =>
useGoConfig(["service.unilogin.wellknown.url", "search.item.limit"])
)

test("That the env variable NEXT_PUBLIC_APP_URL has precedence over LAGOON_AUTOGENERATED_ROUTES", async () => {
const appUrl = goConfig("app.url")
expect(appUrl).toBe("https://hellboy.the-movie.com")
await waitFor(() => {})
expect(result.current).toEqual({
"search.item.limit": 12,
"service.unilogin.wellknown.url": "https://hi-i-am-well-known-url.com",
})
})
})
4 changes: 2 additions & 2 deletions __tests__/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import {
getSearchQueryArguments,
} from "@/components/pages/searchPageLayout/helper"
import { getFacetMachineNames, getFacetTranslation } from "@/components/shared/searchFilters/helper"
import goConfig from "@/lib/config/config"
import goConfig from "@/lib/config/goConfig"
import { FacetFieldEnum } from "@/lib/graphql/generated/fbi/graphql"

vi.mock(import("@/lib/config/config"), async importOriginal => {
vi.mock(import("@/lib/config/goConfig"), async importOriginal => {
const actual = await importOriginal()
return {
...actual,
Expand Down
11 changes: 8 additions & 3 deletions __tests__/url.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
import { expect, test } from "vitest"

import goConfig from "@/lib/config/config"

Check failure on line 3 in __tests__/url.test.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find module '@/lib/config/config' or its corresponding type declarations.

import { resolveUrl } from "../lib/helpers/helper.routes"

test("That resolveUrl can return a work url", async () => {
const workUrl = resolveUrl({ routeParams: { work: "work", wid: 123 } })
expect(workUrl).toBe("/work/123")
const appUrl = goConfig("app.url")
expect(workUrl).toBe(`${appUrl}/work/123`)
})

test("That resolveUrl can return a work url with a manifestation type", async () => {
const workUrl = resolveUrl({
routeParams: { work: "work", wid: 123 },
queryParams: { audio: "true" },
})
expect(workUrl).toBe("/work/123?audio=true")
const appUrl = goConfig("app.url")
expect(workUrl).toBe(`${appUrl}/work/123?audio=true`)
})

test("That resolveUrl can return a search url", async () => {
const workUrl = resolveUrl({ routeParams: { search: "search" }, queryParams: { q: "test" } })
expect(workUrl).toBe("/search?q=test")
const appUrl = goConfig("app.url")
expect(workUrl).toBe(`${appUrl}/search?q=test`)
})
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion app/auth/callback/unilogin/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { sealData } from "iron-session"
import { NextRequest, NextResponse } from "next/server"
import * as client from "openid-client"

import goConfig from "@/lib/config/config"
import goConfig from "@/lib/config/goConfig"
import { getUniloginClientConfig } from "@/lib/session/oauth/uniloginClient"
import { getSession, sessionOptions, setTokensOnSession } from "@/lib/session/session"
import { TTokenSet } from "@/lib/types/session"
Expand Down
2 changes: 1 addition & 1 deletion app/auth/login/unilogin/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as client from "openid-client"

import goConfig from "@/lib/config/config"
import goConfig from "@/lib/config/goConfig"
import { getUniloginClientConfig } from "@/lib/session/oauth/uniloginClient"
import { getSession } from "@/lib/session/session"

Expand Down
8 changes: 4 additions & 4 deletions app/auth/logout/route.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { cookies } from "next/headers"
import * as client from "openid-client"

import goConfig from "@/lib/config/config"
import goConfig from "@/lib/config/goConfig"
import { getUniloginClientConfig } from "@/lib/session/oauth/uniloginClient"
import { getSession } from "@/lib/session/session"

export async function GET() {
const session = await getSession()
const config = await getUniloginClientConfig()
const appUrl = new URL(goConfig("app.url"))
const appUrl = new URL(String(goConfig("app.url")))

session.destroy()

// TODO: Distinguish between session types here.
const id_token = cookies().get("go-session:id_token")?.value
// TODO: Is this where we want to redirect to if id token cannot be resolved?
if (!id_token) {
return Response.redirect(goConfig("app.url"))
return Response.redirect(appUrl)
}
const endSessionEndpoint = config.serverMetadata().end_session_endpoint

Expand All @@ -31,5 +31,5 @@ export async function GET() {
// End session in Unilogin SSO.
await fetch(endSessionUrl)

return Response.redirect(`${appUrl}?reload-session=true`)
return Response.redirect(`${appUrl.toString()}?reload-session=true`)
}
4 changes: 2 additions & 2 deletions app/auth/token/refresh/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { NextRequest, NextResponse } from "next/server"
import * as client from "openid-client"
import { z } from "zod"

import goConfig from "@/lib/config/config"
import goConfig from "@/lib/config/goConfig"
import { getUniloginClientConfig } from "@/lib/session/oauth/uniloginClient"
import { getSession, setTokensOnSession } from "@/lib/session/session"
import { TTokenSet } from "@/lib/types/session"
Expand All @@ -14,7 +14,7 @@ const sessionTokenSchema = z.object({
})

export async function GET(request: NextRequest, response: NextResponse) {
const appUrl = goConfig<string>("app.url")
const appUrl = String(goConfig("app.url"))
const config = await getUniloginClientConfig()
// TODO: Fix refresh token flow with new openid-client.

Expand Down
4 changes: 4 additions & 0 deletions app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import Image from "next/image"

import goConfig from "@/lib/config/goConfig"

const wellknownUrl = goConfig("service.unilogin.wellknown.url")
export default async function Home() {
return (
<div
className="grid min-h-screen grid-rows-[20px_1fr_20px] items-center justify-items-center gap-16 p-8 pb-20
font-[family-name:var(--font-geist-sans)] sm:p-20">
<main className="row-start-2 flex flex-col items-center gap-8 sm:items-start">
<pre>Wellknown url: {wellknownUrl}</pre>
<Image
className="dark:invert"
src="https://nextjs.org/icons/next.svg"
Expand Down
2 changes: 1 addition & 1 deletion app/search/fetchSearchResult.server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { QueryClient } from "@tanstack/react-query"

import { getFacetMachineNames } from "@/components/shared/searchFilters/helper"
import goConfig from "@/lib/config/config"
import goConfig from "@/lib/config/goConfig"
import {
useSearchFacetsQuery,
useSearchWithPaginationQuery,
Expand Down
42 changes: 38 additions & 4 deletions codegen.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { CodegenConfig } from "@graphql-codegen/cli"

import goConfig from "./lib/config/config"
import goConfig from "./lib/config/goConfig"

const { loadEnvConfig } = require("@next/env")

Expand All @@ -9,11 +9,45 @@ loadEnvConfig(process.cwd())
const config: CodegenConfig = {
overwrite: true,
generates: {
"lib/graphql/generated/dpl-cms/graphql.tsx": {
documents: "**/*.dpl-cms.graphql",
// TODO: Make this configurable
schema: {
[`${process.env.NEXT_PUBLIC_GRAPHQL_SCHEMA_ENDPOINT_DPL_CMS}`]: {
headers: {
Authorization: `Basic ${process.env.GRAPHQL_SCHEMA_ENDPOINT_BASIC_TOKEN_DPL_CMS}`,
},
},
},
plugins: ["typescript", "typescript-operations", "typescript-react-query"],
config: {
futureProofEnums: true,
withHooks: true,
defaultScalarType: "unknown",
reactQueryVersion: 5,
exposeFetcher: true,
exposeQueryKeys: true,
addSuspenseQuery: true,
namingConvention: {
typeNames: "change-case-all#pascalCase",
transformUnderscore: true,
},
fetcher: "@/lib/graphql/fetchers/dpl-cms.fetcher#fetcher",
},
hooks: {
afterOneFileWrite: ["yarn eslint --fix"],
},
},
// "lib/graphql/generated/dpl-cms/graphql.schema.json": {
// // TODO: Make this configurable
// schema: "http://dapple-cms.docker/graphql",
// plugins: ["introspection"],
// },
"lib/graphql/generated/fbi/graphql.tsx": {
documents: "**/*.fbi.graphql",
schema: [
{
[goConfig<string>("service.fbi.graphql.endpoint")]: {
[String(goConfig("service.fbi.graphql.endpoint"))]: {
headers: {
Authorization: `Bearer ${goConfig("token.adgangsplatformen.library")}`,
},
Expand All @@ -22,8 +56,8 @@ const config: CodegenConfig = {
],
plugins: ["typescript", "typescript-operations", "typescript-react-query"],
config: {
// futureProofEnums: true,
// withHooks: true,
futureProofEnums: true,
withHooks: true,
defaultScalarType: "unknown",
reactQueryVersion: 5,
exposeFetcher: true,
Expand Down
15 changes: 7 additions & 8 deletions components/pages/searchPageLayout/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { useSelector } from "@xstate/react"
import { ReadonlyURLSearchParams } from "next/navigation"

import { getFacetMachineNames } from "@/components/shared/searchFilters/helper"
import goConfig from "@/lib/config/config"
import { TConfigSearchFacets } from "@/lib/config/resolvers/search"
import goConfig from "@/lib/config/goConfig"
import { SearchFiltersInput, SearchWithPaginationQuery } from "@/lib/graphql/generated/fbi/graphql"
import { TFilters } from "@/lib/machines/search/types"
import useSearchMachineActor from "@/lib/machines/search/useSearchMachineActor"
Expand All @@ -18,29 +17,29 @@ export const getSearchQueryArguments = ({
currentPage: number
facetFilters: SearchFiltersInput
}) => {
const limit = goConfig<number>("search.item.limit")
const limit = goConfig("search.item.limit")
return {
q: { all: q },
offset: currentPage * limit,
limit: limit,
filters: {
branchId: goConfig<`${number}`[]>("search.branch.ids"),
branchId: goConfig("search.branch.ids"),
...facetFilters,
},
}
}

export const getFacetsForSearchRequest = (searchParams: ReadonlyURLSearchParams) => {
const facets = goConfig<TConfigSearchFacets>("search.facets")
const facets = goConfig("search.facets")
const facetsMachineNames = getFacetMachineNames()

return facetsMachineNames.reduce(
(acc: TFilters, machineName) => {
const values = searchParams.getAll(facets[machineName].filter)
const values = searchParams.getAll(facets[machineName as keyof typeof facets].filter)
if (values.length > 0) {
return {
...acc,
[facets[machineName].filter]: [...values],
[facets[machineName as keyof typeof facets].filter]: [...values],
}
}
return acc
Expand All @@ -52,7 +51,7 @@ export const getFacetsForSearchRequest = (searchParams: ReadonlyURLSearchParams)
export const getNextPageParamsFunc = (
currentPage: number
): GetNextPageParamFunction<number, SearchWithPaginationQuery> => {
const limit = goConfig<number>("search.item.limit")
const limit = goConfig("search.item.limit")

return ({ search: { hitcount } }) => {
const totalPages = Math.ceil(hitcount / limit)
Expand Down
1 change: 1 addition & 0 deletions components/pages/workPageLayout/WorkPageLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function WorkPageLayout({ wid }: { wid: string }) {
queryFn: useGetMaterialQuery.fetcher({ wid }),
})

// TODO: Handle potential error states
const manifestations = data?.work?.manifestations.all

const identifier = manifestations?.[0].identifiers?.[0].value || ""
Expand Down
Loading

0 comments on commit 0e1edc3

Please sign in to comment.