Skip to content

Commit

Permalink
Merge branch 'main' into style/storybook_format_files
Browse files Browse the repository at this point in the history
  • Loading branch information
seanes authored Mar 4, 2024
2 parents edb43bb + 08cd7d2 commit 112dbcc
Show file tree
Hide file tree
Showing 46 changed files with 4,296 additions and 235 deletions.
69 changes: 36 additions & 33 deletions biome.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
{
"$schema": "https://biomejs.dev/schemas/1.5.3/schema.json",
"organizeImports": {
"enabled": true
},
"formatter": {
"enabled": true,
"lineWidth": 120,
"lineEnding": "lf",
"ignore": [],
"indentStyle": "space",
"indentWidth": 2
},
"javascript": {
"formatter": {
"arrowParentheses":"always",
"quoteStyle": "single",
"jsxQuoteStyle": "double",
"semicolons": "always",
"trailingComma": "all",
"quoteProperties": "asNeeded",
"bracketSpacing": true,
"bracketSameLine": false
}
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
},
"files": {
"ignore": [".azure", ".github", "node_modules"]
}
"$schema": "https://biomejs.dev/schemas/1.5.3/schema.json",
"organizeImports": {
"enabled": true
},
"formatter": {
"enabled": true,
"lineWidth": 120,
"lineEnding": "lf",
"ignore": [],
"indentStyle": "space",
"indentWidth": 2
},
"javascript": {
"formatter": {
"arrowParentheses": "always",
"quoteStyle": "single",
"jsxQuoteStyle": "double",
"semicolons": "always",
"trailingComma": "all",
"quoteProperties": "asNeeded",
"bracketSpacing": true,
"bracketSameLine": false
}
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"style": {
"noUnusedTemplateLiteral": "off"
}
}
},
"files": {
"ignore": [".azure", ".github", "node_modules"]
}
}
8 changes: 2 additions & 6 deletions packages/bff-frontend-poc/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
{
"ignorePatterns": ["yarn/**", "yarn.lock", "*.css", "*.bicep","*.ps1"],
"extends": [
"plugin:import/typescript",
"plugin:react/recommended",
"plugin:react-hooks/recommended"
],
"ignorePatterns": ["yarn/**", "yarn.lock", "*.css", "*.bicep", "*.ps1"],
"extends": ["plugin:import/typescript", "plugin:react/recommended", "plugin:react-hooks/recommended"],
"plugins": ["jsx-a11y", "react", "react-hooks", "@typescript-eslint"],
"parser": "@typescript-eslint/parser",
"rules": {
Expand Down
3 changes: 1 addition & 2 deletions packages/bff-frontend-poc/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import React from 'react';
import { RouterProvider } from 'react-router-dom';
import { routes } from './routes/routes';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';

const queryClient = new QueryClient();

export const App = () => {
return (
<QueryClientProvider client={queryClient}>
{/* <ReactQueryDevtools initialIsOpen={false} /> */}
<RouterProvider router={routes} />
</QueryClientProvider>
);
Expand Down
8 changes: 4 additions & 4 deletions packages/bff-frontend-poc/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from "react";
import { App } from "./App";
import { createRoot } from "react-dom/client";
import React from 'react';
import { createRoot } from 'react-dom/client';
import { App } from './App';

const container = document.getElementById("root") as HTMLElement;
const container = document.getElementById('root') as HTMLElement;
const root = createRoot(container);

root.render(<App />);
3 changes: 1 addition & 2 deletions packages/bff-frontend-poc/src/mockData/dialogMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ export const dialogMock = {
httpMethod: 'POST',
requestSchema:
'https://digdir.apps.tt02.altinn.no/digdir/super-simple-service/api/jsonschema/mainform-20231015',
responseSchema:
'https://docs.altinn.studio/swagger/altinn-app-v1.json#/components/schemas/DataElement',
responseSchema: 'https://docs.altinn.studio/swagger/altinn-app-v1.json#/components/schemas/DataElement',
deprecated: false,
},
],
Expand Down
4 changes: 2 additions & 2 deletions packages/bff-frontend-poc/src/queries/useTestQuery.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { UseQueryResult, useQuery } from '@tanstack/react-query';
import axios from 'axios';
import { AltinnError, TestResult } from '../types/global';
import { QueryKey } from '../types/QueryKey';
import { UseQueryResult, useQuery } from '@tanstack/react-query';
import { AltinnError, TestResult } from '../types/global';

export const useTestQuery = (name?: string): UseQueryResult<TestResult | null, AltinnError> => {
const requestUrl = '/auth/protected';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import axios from 'axios';
import React from 'react';
import classes from './PageLayout.module.css';
import { Link } from 'react-router-dom';
import axios from 'axios';
import { useTestQuery } from '../../queries/useTestQuery';
import { dialogMock } from '../../mockData/dialogMock';
import { useTestQuery } from '../../queries/useTestQuery';
import classes from './PageLayout.module.css';

const instance = axios.create({
baseURL: '/api/', // This path will be proxied in development
Expand All @@ -26,16 +26,15 @@ export const PageLayout = () => {
{/* <p>{testData?.message}</p> */}
<Link to={`test`}>Go to React Router Test Page</Link>
<button
type="button"
onClick={() =>
fetch('http://localhost:3000/auth/protected', {
method: 'GET', // or 'POST'
credentials: 'include', // This is important for cookies
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
// Other headers can go here
},
// No body for GET requests
})
.then((response) => response.json())
.then((d) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ErrorMessage } from '../components/ErrorMessage';
export const RouterErrorMessage = (): JSX.Element => {
const error = useRouteError();
return (
<ErrorMessage title='Error' message='Something went wrong...'>
<ErrorMessage title="Error" message="Something went wrong...">
{(error as Error)?.message || (error as { statusText?: string })?.statusText}
</ErrorMessage>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { TestPage } from './TestPage';
*/

test.skip('renders TestPage component with a link to the root', () => {
/*
/*
render(
<MemoryRouter initialEntries={['/']}>
<TestPage />
Expand Down
2 changes: 1 addition & 1 deletion packages/bff/src/Dtos/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./HelloWorldDto";
export * from './HelloWorldDto';
31 changes: 12 additions & 19 deletions packages/bff/src/config/passport.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Issuer, Strategy as OpenIDStrategy, TokenSet } from 'openid-client';
import './env';
import { IDPortenProfile } from '../types/types';
import { Profile } from '../entities/Profile';
import { ProfileRepository, SessionRepository } from '..';
import passport from 'passport';
import { readCookie } from '../util/sessionUtils';
import { ProfileRepository, SessionRepository } from '..';
import { Profile } from '../entities/Profile';
import { SessionData } from '../entities/SessionData';
import { IDPortenProfile } from '../types/types';
import { readCookie } from '../util/sessionUtils';
import './env';

export const initPassport = async () => {
if (!SessionRepository) throw new Error('SessionRepository not initialized');
Expand All @@ -15,11 +15,9 @@ export const initPassport = async () => {
process.exit(1);
}

const idportenIssuer = await Issuer.discover(process.env.ISSUER_URL).then(
async (idportenIssuer) => {
return idportenIssuer;
}
);
const idportenIssuer = await Issuer.discover(process.env.ISSUER_URL).then(async (idportenIssuer) => {
return idportenIssuer;
});

const client = new idportenIssuer.Client({
client_id: process.env.CLIENT_ID!,
Expand Down Expand Up @@ -55,12 +53,7 @@ export const initPassport = async () => {
sessionId = session?.id;
}
if (!sessionId) {
const session = await createSession(
sid as string,
tokenSet,
user,
postLoginRedirectUrl
);
const session = await createSession(sid as string, tokenSet, user, postLoginRedirectUrl);
sessionId = session?.id;
}

Expand All @@ -77,8 +70,8 @@ export const initPassport = async () => {
console.error("authenticate('oidc') error: ", error);
return done(error);
}
}
)
},
),
);

passport.serializeUser((user: any, done) => {
Expand Down Expand Up @@ -117,7 +110,7 @@ const createSession = async (
idportenSessionId: string,
tokenSet: TokenSet,
user: Profile,
postLoginRedirectUrl: string
postLoginRedirectUrl: string,
) => {
const {
id_token: idToken,
Expand Down
14 changes: 7 additions & 7 deletions packages/bff/src/controllers/authenticationController.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Request, Response } from 'express';
import { Session } from 'express-session';
import passport from 'passport';
import { deleteCookie, readCookie, setCookie } from '../util/sessionUtils';
import { SessionData } from '../entities/SessionData';
import { SessionRepository } from '..';
import '../config/env';
import { Session } from 'express-session';
import { SessionData } from '../entities/SessionData';
import { deleteCookie, readCookie, setCookie } from '../util/sessionUtils';

interface CustomSession extends Session, Partial<SessionData> {
returnTo?: string;
Expand Down Expand Up @@ -40,7 +40,7 @@ const login = async (req: Express.Request, res: Response, next: any) => {
passport.authenticate('oidc')(req, res, next);
};

const logout = async function (req: any, res: any, next: any) {
const logout = async (req: any, res: any, next: any) => {
const sessionCookie = readCookie(req);

const currentSession: SessionData | null = await SessionRepository!.findOneBy({
Expand All @@ -53,15 +53,15 @@ const logout = async function (req: any, res: any, next: any) {
if (currentSession && logoutUri && logoutRedirectUri) {
const logoutRedirectUrl = `${logoutUri}?post_logout_redirect_uri=${logoutRedirectUri}&id_token_hint=${currentSession.idToken}`;

req.logout(function (err: Error) {
req.logout((err: Error) => {
if (err) {
console.error('Logout Error:', err);
return next(err);
}

if (req.session) {
deleteCookie(res);
req.session.destroy(function (err: Error) {
req.session.destroy((err: Error) => {
if (err) {
console.error('Error destroying session:', err);
return next(err);
Expand Down Expand Up @@ -90,7 +90,7 @@ const protectedEndpoint = async (req: CustomRequest, res: Response) => {
const callback = async (req: CustomRequest, res: any) => {
try {
let userRequestedUrl = req.user?.postLoginRedirectUrl;
let currentSessionId = req.user?.currentSessionId;
const currentSessionId = req.user?.currentSessionId;
let currentSession;

if (currentSessionId) {
Expand Down
2 changes: 1 addition & 1 deletion packages/bff/src/controllers/helloWorld.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Request, Response } from 'express';
import { HelloWorldDto } from '../Dtos';
import { StartUpRepository, bffVersion } from '..';
import { HelloWorldDto } from '../Dtos';
const process = require('process');

async function getMostRecentStartUp() {
Expand Down
2 changes: 1 addition & 1 deletion packages/bff/src/data-source.local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'reflect-metadata';
import { DataSource, DataSourceOptions } from 'typeorm';
import './config/env';

export let connectionOptions: DataSourceOptions = {
export const connectionOptions: DataSourceOptions = {
type: 'postgres',
host: process.env.DB_HOST || 'localhost',
port: parseInt(process.env.DB_PORT || '5430'),
Expand Down
14 changes: 5 additions & 9 deletions packages/bff/src/entities/Profile.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import {
Entity,
Column,
CreateDateColumn,
UpdateDateColumn,
PrimaryColumn,
OneToMany,
} from 'typeorm';
import { Column, CreateDateColumn, Entity, OneToMany, PrimaryColumn, UpdateDateColumn } from 'typeorm';
import { SessionData } from './SessionData';

@Entity()
Expand All @@ -28,6 +21,9 @@ export class Profile {
@UpdateDateColumn()
updatedAt: Date;

@OneToMany(() => SessionData, (session) => session.profile)
@OneToMany(
() => SessionData,
(session) => session.profile,
)
sessions: SessionData[];
}
14 changes: 5 additions & 9 deletions packages/bff/src/entities/SessionData.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import {
Entity,
PrimaryGeneratedColumn,
Column,
CreateDateColumn,
UpdateDateColumn,
ManyToOne,
} from 'typeorm';
import { Column, CreateDateColumn, Entity, ManyToOne, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm';
import { Profile } from './Profile';

@Entity()
Expand Down Expand Up @@ -43,6 +36,9 @@ export class SessionData {
@Column('simple-json', { nullable: true })
sessionData: any;

@ManyToOne(() => Profile, (profile) => profile.sessions)
@ManyToOne(
() => Profile,
(profile) => profile.sessions,
)
profile: Profile;
}
9 changes: 1 addition & 8 deletions packages/bff/src/entities/StartUp.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import {
Entity,
PrimaryGeneratedColumn,
Column,
CreateDateColumn,
UpdateDateColumn,
DeleteDateColumn,
} from 'typeorm';
import { Column, CreateDateColumn, DeleteDateColumn, Entity, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm';

@Entity()
export class StartUp {
Expand Down
Loading

0 comments on commit 112dbcc

Please sign in to comment.