Skip to content

Commit

Permalink
Merge branch 'dev' into twic
Browse files Browse the repository at this point in the history
  • Loading branch information
jackstenglein committed Jul 22, 2024
2 parents 545c429 + a2ccdbd commit cd98da3
Show file tree
Hide file tree
Showing 20 changed files with 241 additions and 79 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ jobs:
env:
AWS_COGNITO_USERNAME: ${{ secrets.AWS_COGNITO_USERNAME }}
AWS_COGNITO_PASSWORD: ${{ secrets.AWS_COGNITO_PASSWORD }}
AWS_COGNITO_REGION: 'us-east-1'
AWS_COGNITO_USER_POOL_ID: 'us-east-1_apywr6kwu'
AWS_COGNITO_USER_POOL_WEB_CLIENT_ID: '76en8knncv8bfpfgbheua6j6k'
AWS_COGNITO_DOMAIN: 'user-pool-domain-dev-chess-dojo-scheduler.auth.us-east-1.amazoncognito.com'

- name: Save Cypress Screenshots
uses: actions/upload-artifact@v4
Expand Down
32 changes: 29 additions & 3 deletions backend/pgnService/explorer/getPosition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {

const dynamo = new DynamoDBClient({ region: 'us-east-1' });
const explorerTable = process.env.stage + '-explorer';
const mastersTable = 'prod-masters-explorer';

/**
* Gets an ExplorerPosition for the provided FEN.
Expand All @@ -37,6 +38,7 @@ export const handler: APIGatewayProxyHandlerV2 = async (event) => {

const results = await Promise.all([
fetchFromDojo(normalizedFen),
fetchFromMasters(normalizedFen),
fetchFromLichess(normalizedFen),
fetchFromTablebase(normalizedFen),
fetchFollower(normalizedFen, event),
Expand All @@ -47,9 +49,10 @@ export const handler: APIGatewayProxyHandlerV2 = async (event) => {
body: JSON.stringify({
normalizedFen,
dojo: results[0],
lichess: results[1],
tablebase: results[2],
follower: results[3],
masters: results[1],
lichess: results[2],
tablebase: results[3],
follower: results[4],
}),
};
} catch (err) {
Expand Down Expand Up @@ -81,6 +84,29 @@ async function fetchFromDojo(fen: string): Promise<ExplorerPosition | null> {
return position as ExplorerPosition;
}

/**
* Fetches the ExplorerPosition associated with the given FEN from the Dojo masters database.
* @param fen The normalized FEN to fetch.
* @returns An ExplorerPosition for the provided FEN.
*/
async function fetchFromMasters(fen: string): Promise<ExplorerPosition | null> {
const getItemOutput = await dynamo.send(
new GetItemCommand({
Key: {
normalizedFen: { S: fen },
id: { S: 'POSITION' },
},
TableName: mastersTable,
}),
);
if (!getItemOutput.Item) {
return null;
}

const position = unmarshall(getItemOutput.Item);
return position as ExplorerPosition;
}

/**
* Fetches the data from the Lichess API for the provided FEN.
* @param fen The FEN to fetch from Lichess.
Expand Down
8 changes: 4 additions & 4 deletions backend/pgnService/explorer/listGames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ExplorerGame } from './types';

const dynamo = new DynamoDBClient({ region: 'us-east-1' });
const explorerTable = process.env.stage + '-explorer';
const mastersTable = 'prod-masters-explorer';

/**
* Returns a list of games with the provided FEN. The FEN is normalized before searching for games.
Expand All @@ -31,18 +32,17 @@ export const handler: APIGatewayProxyHandlerV2 = async (event) => {

const queryOutput = await dynamo.send(
new QueryCommand({
KeyConditionExpression: `#fen = :fen AND #id BETWEEN :minId AND :maxId`,
KeyConditionExpression: `#fen = :fen AND begins_with ( #id, :id )`,
ExpressionAttributeNames: {
'#fen': 'normalizedFen',
'#id': 'id',
},
ExpressionAttributeValues: {
':fen': { S: normalizedFen },
':minId': { S: masters ? 'GAME#masters' : 'GAME#' },
':maxId': { S: masters ? 'GAME#z' : 'GAME#masters' },
':id': { S: 'GAME#' },
},
ExclusiveStartKey: startKey ? JSON.parse(startKey) : undefined,
TableName: explorerTable,
TableName: masters ? mastersTable : explorerTable,
}),
);

Expand Down
8 changes: 6 additions & 2 deletions backend/pgnService/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ functions:
- Effect: Allow
Action:
- dynamodb:GetItem
Resource: !GetAtt ExplorerTable.Arn
Resource:
- !GetAtt ExplorerTable.Arn
- arn:aws:dynamodb:${aws:region}:${aws:accountId}:table/prod-masters-explorer

listGamesByPosition:
handler: explorer/listGames.handler
Expand All @@ -96,7 +98,9 @@ functions:
- Effect: Allow
Action:
- dynamodb:Query
Resource: !GetAtt ExplorerTable.Arn
Resource:
- !GetAtt ExplorerTable.Arn
- arn:aws:dynamodb:${aws:region}:${aws:accountId}:table/prod-masters-explorer

followPosition:
handler: explorer/followPosition.handler
Expand Down
11 changes: 7 additions & 4 deletions frontend/.env.beta
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Auth variables
# Auth
NEXT_PUBLIC_AUTH_REGION=us-east-1
NEXT_PUBLIC_AUTH_USER_POOL_ID=us-east-1_0revSxCzf
NEXT_PUBLIC_AUTH_USER_POOL_WEB_CLIENT_ID=1dfi5rar7a2fr5samugigrmise
Expand All @@ -8,11 +8,14 @@ NEXT_PUBLIC_AUTH_OAUTH_REDIRECT_SIGN_IN=https://beta.chessdojo.club
NEXT_PUBLIC_AUTH_OAUTH_REDIRECT_SIGN_OUT=https://beta.chessdojo.club
NEXT_PUBLIC_AUTH_OAUTH_RESPONSE_TYPE=code

# API variables
# API
NEXT_PUBLIC_API_BASE_URL=https://g4shdaq6ug.execute-api.us-east-1.amazonaws.com

# Media variables
# Media
NEXT_PUBLIC_MEDIA_PICTURES_BUCKET=https://chess-dojo-prod-pictures.s3.amazonaws.com

# Stripe variables
# Stripe
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_live_51OB6imGilmvijaecicnOhS1rqgX6VofcmTgi4n3TdhYoPgutx4W8HnUch6iQE7GL62fngez6mL471YWiZSrUhbJI007MlHx5CM

# Site
NEXT_PUBLIC_BASE_URL=https://beta.chessdojo.club
11 changes: 7 additions & 4 deletions frontend/.env.development
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Auth variables
# Auth
NEXT_PUBLIC_AUTH_REGION=us-east-1
NEXT_PUBLIC_AUTH_USER_POOL_ID=us-east-1_apywr6kwu
NEXT_PUBLIC_AUTH_USER_POOL_WEB_CLIENT_ID=76en8knncv8bfpfgbheua6j6k
Expand All @@ -8,11 +8,14 @@ NEXT_PUBLIC_AUTH_OAUTH_REDIRECT_SIGN_IN=http://localhost:3000
NEXT_PUBLIC_AUTH_OAUTH_REDIRECT_SIGN_OUT=http://localhost:3000
NEXT_PUBLIC_AUTH_OAUTH_RESPONSE_TYPE=code

# API variables
# API
NEXT_PUBLIC_API_BASE_URL=https://c2qamdaw08.execute-api.us-east-1.amazonaws.com

# Media variables
# Media
NEXT_PUBLIC_MEDIA_PICTURES_BUCKET=https://chess-dojo-dev-pictures.s3.amazonaws.com

# Stripe variables
# Stripe
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_51OB6imGilmvijaecMJqdvLJdu89BcghnjU7eOIoCwlBl8DeV6i2XojJOaZ36lamZMuVjO7aorXtl90OcdtAstFfF0022uf0sdp

# Site
NEXT_PUBLIC_BASE_URL=http://localhost:3000
11 changes: 7 additions & 4 deletions frontend/.env.production
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Auth variables
# Auth
NEXT_PUBLIC_AUTH_REGION=us-east-1
NEXT_PUBLIC_AUTH_USER_POOL_ID=us-east-1_0revSxCzf
NEXT_PUBLIC_AUTH_USER_POOL_WEB_CLIENT_ID=1dfi5rar7a2fr5samugigrmise
Expand All @@ -8,11 +8,14 @@ NEXT_PUBLIC_AUTH_OAUTH_REDIRECT_SIGN_IN=https://www.chessdojo.club
NEXT_PUBLIC_AUTH_OAUTH_REDIRECT_SIGN_OUT=https://www.chessdojo.club
NEXT_PUBLIC_AUTH_OAUTH_RESPONSE_TYPE=code

# API variables
# API
NEXT_PUBLIC_API_BASE_URL=https://g4shdaq6ug.execute-api.us-east-1.amazonaws.com

# Media variables
# Media
NEXT_PUBLIC_MEDIA_PICTURES_BUCKET=https://chess-dojo-prod-pictures.s3.amazonaws.com

# Stripe variables
# Stripe
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_live_51OB6imGilmvijaecicnOhS1rqgX6VofcmTgi4n3TdhYoPgutx4W8HnUch6iQE7GL62fngez6mL471YWiZSrUhbJI007MlHx5CM

# Site
NEXT_PUBLIC_BASE_URL=https://www.chessdojo.club
13 changes: 8 additions & 5 deletions frontend/.env.test
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
# Auth variables
# Auth
NEXT_PUBLIC_AUTH_REGION: us-east-1
NEXT_PUBLIC_AUTH_USER_POOL_ID: us-east-1_apywr6kwu
NEXT_PUBLIC_AUTH_USER_POOL_WEB_CLIENT_ID: 76en8knncv8bfpfgbheua6j6k
NEXT_PUBLIC_AUTH_OAUTH_DOMAIN: authdev.chessdojo.club
NEXT_PUBLIC_AUTH_OAUTH_DOMAIN: user-pool-domain-dev-chess-dojo-scheduler.auth.us-east-1.amazoncognito.com
NEXT_PUBLIC_AUTH_OAUTH_SCOPES: profile,email,openid
NEXT_PUBLIC_AUTH_OAUTH_REDIRECT_SIGN_IN: http://localhost:3000
NEXT_PUBLIC_AUTH_OAUTH_REDIRECT_SIGN_OUT: http://localhost:3000
NEXT_PUBLIC_AUTH_OAUTH_RESPONSE_TYPE: code

# API variables
# API
NEXT_PUBLIC_API_BASE_URL: https://c2qamdaw08.execute-api.us-east-1.amazonaws.com

# Media variables
# Media
NEXT_PUBLIC_MEDIA_PICTURES_BUCKET: https://chess-dojo-dev-pictures.s3.amazonaws.com

# Stripe variables
# Stripe
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY: pk_test_51OB6imGilmvijaecMJqdvLJdu89BcghnjU7eOIoCwlBl8DeV6i2XojJOaZ36lamZMuVjO7aorXtl90OcdtAstFfF0022uf0sdp

# Site
NEXT_PUBLIC_BASE_URL=http://localhost:3000
23 changes: 17 additions & 6 deletions frontend/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { defineConfig } from 'cypress';
import dotenv from 'dotenv';
import { EnvSchema } from './cypress/env';

dotenv.config({
path: ['.env.test.local', '.env.local', '.env.test', '.env'],
});

const env = process.env;

export default defineConfig({
projectId: 'ut1fmk',

Expand All @@ -13,11 +20,15 @@ export default defineConfig({
apiBaseUrl: 'https://c2qamdaw08.execute-api.us-east-1.amazonaws.com',
numCohorts: 23,

cognito_username: process.env.AWS_COGNITO_USERNAME,
cognito_password: process.env.AWS_COGNITO_PASSWORD,
cognito_region: process.env.AWS_COGNITO_REGION,
cognito_user_pool_id: process.env.AWS_COGNITO_USER_POOL_ID,
cognito_user_pool_web_client_id: process.env.AWS_COGNITO_USER_POOL_WEB_CLIENT_ID,
cognito_domain: process.env.AWS_COGNITO_DOMAIN,
cognito_username: env.AWS_COGNITO_USERNAME,
cognito_password: env.AWS_COGNITO_PASSWORD,
cognito_region: env.NEXT_PUBLIC_AUTH_REGION,
cognito_user_pool_id:
env.AWS_COGNITO_USER_POOL_ID ?? env.NEXT_PUBLIC_AUTH_USER_POOL_ID,
cognito_user_pool_web_client_id:
env.AWS_COGNITO_USER_POOL_WEB_CLIENT_ID ??
env.NEXT_PUBLIC_AUTH_USER_POOL_WEB_CLIENT_ID,
cognito_domain:
env.AWS_COGNITO_DOMAIN ?? process.env.NEXT_PUBLIC_AUTH_OAUTH_DOMAIN,
}),
});
5 changes: 5 additions & 0 deletions frontend/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ const nextConfig = {
hostname: 'chess-dojo-images.s3.amazonaws.com',
pathname: '**',
},
{
protocol: 'https',
hostname: 'raw.githubusercontent.com',
pathname: '/jalpp/DojoIcons/**',
},
],
},
};
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/api/explorerApi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ export interface GetExplorerPositionResult {
/** The data from the Dojo database. */
dojo: ExplorerPosition | null;

/** The data from the Dojo masters database. */
masters: ExplorerPosition | null;

/** The data from the Lichess database. */
lichess: LichessExplorerPosition | null;

Expand Down
7 changes: 0 additions & 7 deletions frontend/src/app/(legacy)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import { Layout } from '@/legacy/Layout';
import { Metadata } from 'next';

export const metadata: Metadata = {
title: 'ChessDojo',
description:
'View the scoreboard, schedule meetings and more for the ChessDojo Training Program',
};

export default function RootLayout({ children }: { children: React.ReactNode }) {
return <Layout>{children}</Layout>;
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/app/(scoreboard)/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Layout } from '@/legacy/Layout';

export default function RootLayout({ children }: { children: React.ReactNode }) {
return <Layout>{children}</Layout>;
}
9 changes: 9 additions & 0 deletions frontend/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import { getConfig } from '@/config';
import { Metadata } from 'next';
import './globals.css';

export const metadata: Metadata = {
metadataBase: getConfig().baseUrl,
title: 'ChessDojo Training Program',
description:
'The ChessDojo Training Program offers structured training plans for all levels 0-2500, along with an active and supportive community',
};

export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang='en' suppressHydrationWarning>
Expand Down
Binary file added frontend/src/app/opengraph-image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 10 additions & 2 deletions frontend/src/board/pgn/explorer/Explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const Explorer = () => {
follower: f,
normalizedFen: f.normalizedFen,
dojo: null,
masters: null,
lichess: null,
tablebase: null,
});
Expand All @@ -77,7 +78,14 @@ const Explorer = () => {
);
};

const { dojo, lichess, tablebase, follower } = position || {};
const { dojo, masters, lichess, tablebase, follower } = position || {};

const selectedPosition =
tab === ExplorerDatabaseType.Dojo
? dojo
: tab === ExplorerDatabaseType.Masters
? masters
: lichess;

return (
<CardContent>
Expand Down Expand Up @@ -134,7 +142,7 @@ const Explorer = () => {
<Database
type={tab}
fen={fen}
position={tab === ExplorerDatabaseType.Lichess ? lichess : dojo}
position={selectedPosition}
request={request}
minCohort={minCohort}
maxCohort={maxCohort}
Expand Down
29 changes: 6 additions & 23 deletions frontend/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,13 @@ export const EnvSchema = z.object({
stripe: z.object({
publishableKey: z.string(),
}),
baseUrl: z
.string()
.url()
.transform((v) => new URL(v)),
});

export interface Config {
auth: {
region: 'us-east-1';
userPoolId: string;
userPoolWebClientId: string;
oauth: {
domain: string;
scope: string[];
redirectSignIn: string;
redirectSignOut: string;
responseType: 'code';
};
};
api: {
baseUrl: string;
};
media: {
picturesBucket: string;
};
stripe: {
publishableKey: string;
};
}
export type Config = z.infer<typeof EnvSchema>;

export function getConfig(): Config {
return EnvSchema.parse({
Expand All @@ -74,5 +56,6 @@ export function getConfig(): Config {
stripe: {
publishableKey: process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY,
},
baseUrl: process.env.NEXT_PUBLIC_BASE_URL,
});
}
Loading

0 comments on commit cd98da3

Please sign in to comment.