Skip to content

Commit 7c84820

Browse files
authored
Merge branch 'dev' into refactor/user-platform-accounts
2 parents 3457b58 + 5492bf1 commit 7c84820

File tree

197 files changed

+8336
-2740
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

197 files changed

+8336
-2740
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,5 @@ core/config/development.json.bak
120120
core/config/main.json
121121

122122
core/config/staging.json
123+
124+
clients/web/schema.graphql

aUsefulTmuxScript.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/zsh
2+
3+
SESSIONNAME="sprocket"
4+
tmux has-session -t $SESSIONNAME &> /dev/null
5+
6+
if [ $? != 0 ]
7+
then
8+
tmux new-session -s $SESSIONNAME -n script -d
9+
tmux split-window -h
10+
tmux selectp -t 0
11+
tmux send-keys 'npm run build --workspaces --if-present' C-m
12+
tmux split-window -v
13+
tmux selectp -t 1
14+
tmux send-keys 'cd $PWD/core' C-m
15+
tmux send-keys 'sleep 120; npm run dev;' C-m
16+
tmux selectp -t 2
17+
tmux send-keys 'cd $PWD/clients/web' C-m 'reset' C-m
18+
tmux send-keys 'export PUBLIC_GQL_URL=http://localhost:3001; sleep 240; npm run dev' C-m
19+
tmux split-window -v
20+
tmux selectp -t 3
21+
tmux send-keys 'cd $PWD/common' C-m 'reset' C-m
22+
tmux selectp -t 0
23+
fi
24+
25+
tmux attach -t $SESSIONNAME

clients/discord-bot/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"homepage": "https://github.com/SprocketBot/service-template#readme",
2929
"dependencies": {
3030
"@nestjs/common": "^8.2.3",
31-
"@nestjs/core": "^8.2.3",
31+
"@nestjs/core": "^9.0.5",
3232
"@nestjs/microservices": "^8.2.3",
3333
"@sprocketbot/common": "^0.2.13",
3434
"bufferutil": "^4.0.5",

clients/discord-bot/src/commands/administrator-commands/administrator-commands.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {CoreModule, EventsModule} from "@sprocketbot/common";
44
import {DiscordModule} from "../../discord/discord.module";
55
import {EmbedModule} from "../../embed/embed.module";
66
import {CommandsModule} from "../../marshal";
7+
import {DatabaseSyncMarshal} from "./database-sync.marshal";
78
// import {CommandDecoratorTestMarshal} from "./command-decorator-test.marshal";
89
// import {DebugCommandsMarshal} from "./debug-commands.marshal";
910
import {DeveloperCommandsMarshal} from "./developer-commands.marshal";
@@ -21,6 +22,7 @@ import {DeveloperCommandsMarshal} from "./developer-commands.marshal";
2122
// SprocketConfigurationMarshal,
2223
// CommandDecoratorTestMarshal,
2324
DeveloperCommandsMarshal,
25+
DatabaseSyncMarshal,
2426
],
2527
})
2628
export class AdministratorCommandsModule {}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import {Logger} from "@nestjs/common";
2+
import {CoreEndpoint, ResponseStatus} from "@sprocketbot/common";
3+
import {Message} from "discord.js";
4+
5+
import {Command, Marshal} from "../../marshal";
6+
7+
export class DatabaseSyncMarshal extends Marshal {
8+
private readonly logger = new Logger(DatabaseSyncMarshal.name);
9+
10+
@Command({
11+
name: "syncNames",
12+
args: [],
13+
docs: "Sync all player names in the main MLE server.",
14+
})
15+
async syncNames(m: Message): Promise<void> {
16+
if (
17+
![
18+
"353194025995730945", // Adi
19+
"105408136285818880", // Hyper
20+
"423850557334093827", // Hoos
21+
"470703275163779084", // Achilles
22+
"243430304319143936", // Kunics
23+
].includes(m.author.id)
24+
)
25+
return;
26+
27+
await m.reply("Starting sync...");
28+
29+
const serverId = "172404472637685760"; // MLE Main
30+
const server = await this.botClient.guilds.fetch(serverId);
31+
await server.members.fetch();
32+
33+
for (const member of server.members.cache.values()) {
34+
const nicknameRequest = await this.coreService.send(CoreEndpoint.GetNicknameByDiscordUser, {
35+
discordId: member.id,
36+
});
37+
if (nicknameRequest.status === ResponseStatus.ERROR) {
38+
this.logger.log(`Failed to get nickname for ${member.id}`);
39+
continue;
40+
}
41+
42+
if (member.nickname === nicknameRequest.data) continue;
43+
44+
await member.setNickname(nicknameRequest.data).catch(err => {
45+
this.logger.error(err);
46+
});
47+
}
48+
49+
await m.reply("Sync complete!");
50+
}
51+
}

clients/image-generation-frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"lint:check": "eslint src"
1515
},
1616
"devDependencies": {
17-
"@sveltejs/kit": "^1.0.0-next.156",
17+
"@sveltejs/kit": "^1.15.2",
1818
"@types/amqplib": "^0.8.2",
1919
"autoprefixer": "^10.3.3",
2020
"postcss": "^8.3.6",

clients/web/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ node_modules
66
.env
77
.env.*
88
!.env.example
9+
10+
$houdini

clients/web/.graphqlrc.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
projects:
2+
default:
3+
schema:
4+
- ./schema.graphql
5+
- ./$houdini/graphql/schema.graphql
6+
documents:
7+
- '**/*.gql'
8+
- '**/*.svelte'
9+
- ./$houdini/graphql/documents.gql

clients/web/Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
ARG BASE_IMAGE
2+
FROM $BASE_IMAGE AS test_image
3+
ENTRYPOINT npm run test --workspace=clients/web
4+
5+
FROM $BASE_IMAGE AS app_image
6+
RUN DISABLE_CONFIG=true npm run gen-sdl --workspace=core
7+
RUN cp /app/core/schema.graphql /app/clients/web/schema.graphql
8+
RUN npm run build --workspace=clients/web
9+
ENTRYPOINT node /app/clients/web/build/index.js

clients/web/histoire.config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import {defineConfig} from "histoire";
2-
import {HstSvelte} from "@histoire/plugin-svelte";
1+
import { defineConfig } from "histoire";
2+
import { HstSvelte } from "@histoire/plugin-svelte";
33
import path from "path";
44

5-
import {palette} from "./src/lib/palette";
6-
const {primary, gray} = palette;
5+
import { palette } from "./src/lib/palette";
6+
const { primary, gray } = palette;
77

88
export default defineConfig({
99
plugins: [HstSvelte()],

clients/web/houdini.config.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/// <references types="houdini-svelte">
2+
3+
/** @type {import('houdini').ConfigFile} */
4+
const config = {
5+
"watchSchema": {
6+
url(env) {
7+
return `${env.PUBLIC_GQL_URL}/graphql`
8+
}
9+
},
10+
"plugins": {
11+
"houdini-svelte": {},
12+
},
13+
scalars: {
14+
DateTime: { type: Date.name }
15+
}
16+
}
17+
18+
export default config

clients/web/package.json

Lines changed: 61 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,63 @@
11
{
2-
"name": "web",
3-
"version": "0.0.1",
4-
"private": true,
5-
"scripts": {
6-
"dev": "vite dev",
7-
"build": "vite build",
8-
"preview": "vite preview",
9-
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
10-
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
11-
"lint": "eslint src --fix",
12-
"format": "prettier src --write",
13-
"story:dev": "histoire dev",
14-
"story:build": "histoire build",
15-
"story:preview": "histoire preview"
16-
},
17-
"devDependencies": {
18-
"@histoire/plugin-svelte": "^0.12.4",
19-
"@steeze-ui/heroicons": "^2.1.0",
20-
"@steeze-ui/svelte-icon": "^1.3.2",
21-
"@sveltejs/adapter-auto": "^1.0.1",
22-
"@sveltejs/kit": "^1.1.1",
23-
"@types/lodash.times": "^4.3.7",
24-
"@typescript-eslint/eslint-plugin": "^5.27.0",
25-
"@typescript-eslint/parser": "^5.27.0",
26-
"autoprefixer": "^10.4.7",
27-
"date-fns": "^2.29.3",
28-
"date-picker-svelte": "^2.2.5",
29-
"eslint": "^8.16.0",
30-
"eslint-config-prettier": "^8.5.0",
31-
"eslint-plugin-svelte3": "^4.0.0",
32-
"filedrop-svelte": "^0.1.2",
33-
"histoire": "^0.12.4",
34-
"lodash.times": "^4.3.2",
35-
"nanoid": "^4.0.0",
36-
"postcss": "^8.4.14",
37-
"postcss-load-config": "^4.0.1",
38-
"prettier-plugin-svelte": "^2.9.0",
39-
"svelte": "^3.44.0",
40-
"svelte-check": "^2.7.1",
41-
"svelte-preprocess": "^4.10.7",
42-
"tailwindcss": "^3.1.5",
43-
"tslib": "^2.3.1",
44-
"typescript": "^4.7.4",
45-
"vite": "^4.0.4"
46-
},
47-
"type": "module",
48-
"dependencies": {
49-
"@faker-js/faker": "^7.6.0",
50-
"echarts": "^5.4.1"
51-
}
2+
"name": "web",
3+
"version": "0.0.1",
4+
"private": true,
5+
"scripts": {
6+
"dev": "vite dev",
7+
"build": "vite build",
8+
"preview": "vite preview",
9+
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
10+
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
11+
"lint": "eslint src --fix",
12+
"format": "prettier src --write",
13+
"story:dev": "histoire dev",
14+
"story:build": "histoire build",
15+
"story:preview": "histoire preview"
16+
},
17+
"devDependencies": {
18+
"@histoire/plugin-svelte": "^0.15.4",
19+
"@steeze-ui/heroicons": "^2.1.0",
20+
"@steeze-ui/simple-icons": "^1.4.0",
21+
"@steeze-ui/svelte-icon": "^1.3.2",
22+
"@sveltejs/adapter-auto": "^1.0.1",
23+
"@sveltejs/kit": "^1.15.2",
24+
"@types/lodash.startcase": "^4.4.7",
25+
"@types/lodash.times": "^4.3.7",
26+
"@typescript-eslint/eslint-plugin": "^5.27.0",
27+
"@typescript-eslint/parser": "^5.27.0",
28+
"autoprefixer": "^10.4.7",
29+
"date-fns": "^2.29.3",
30+
"date-picker-svelte": "^2.2.5",
31+
"eslint": "^8.16.0",
32+
"eslint-config-prettier": "^8.5.0",
33+
"eslint-plugin-svelte3": "^4.0.0",
34+
"filedrop-svelte": "^0.1.2",
35+
"histoire": "^0.15.4",
36+
"houdini": "^1.0.9",
37+
"houdini-svelte": "^1.0.9",
38+
"lodash.times": "^4.3.2",
39+
"nanoid": "^4.0.0",
40+
"postcss": "^8.4.14",
41+
"postcss-load-config": "^4.0.1",
42+
"prettier-plugin-svelte": "^2.9.0",
43+
"svelte": "^3.44.0",
44+
"svelte-check": "^2.7.1",
45+
"svelte-preprocess": "^4.10.7",
46+
"tailwindcss": "^3.1.5",
47+
"tslib": "^2.3.1",
48+
"typescript": "^4.7.4",
49+
"vite": "^4.1.5"
50+
},
51+
"type": "module",
52+
"dependencies": {
53+
"@faker-js/faker": "^7.6.0",
54+
"@fontsource/montserrat": "^4.5.14",
55+
"@sveltejs/adapter-node": "^1.0.0-next.106",
56+
"@tanstack/svelte-table": "^8.9.3",
57+
"echarts": "^5.4.1",
58+
"jwt-decode": "^3.1.2",
59+
"lodash.startcase": "^4.4.0",
60+
"subscriptions-transport-ws": "^0.11.0",
61+
"typescript-cookie": "^1.0.4"
62+
}
5263
}

clients/web/src/app.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,15 @@ declare namespace App {
66
// interface PageData {}
77
// interface Error {}
88
// interface Platform {}
9+
interface Session {
10+
access?: string;
11+
refresh?: string;
12+
}
13+
interface Metadata {
14+
/**
15+
* Used to force the use of a specific access token.
16+
* Useful when running mutations / queries before the session updates
17+
*/
18+
accessTokenOverride?: string;
19+
}
920
}

clients/web/src/app.postcss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@
22
@tailwind base;
33
@tailwind components;
44
@tailwind utilities;
5+
6+
body {
7+
font-family: "Montserrat";
8+
}

clients/web/src/client.ts

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import {env} from "$env/dynamic/public";
2+
import {HoudiniClient} from "$houdini";
3+
import {SubscriptionClient} from "subscriptions-transport-ws";
4+
import {subscription} from "$houdini/plugins";
5+
import {goto} from "$app/navigation";
6+
import {getAuthCookies, clearAuthCookies} from "$lib/api";
7+
import {redirect} from "@sveltejs/kit";
8+
import {refreshAuthPlugin} from "./houdini/refresh-auth.plugin";
9+
10+
const getAuthToken = ({
11+
session,
12+
metadata,
13+
useRefresh,
14+
}: {session?: App.Session; metadata?: App.Metadata; useRefresh?: boolean} = {}) => {
15+
if (metadata?.accessTokenOverride) return metadata.accessTokenOverride;
16+
if (useRefresh && session?.refresh) return session.refresh;
17+
if (session?.access) return session.access;
18+
const cookies = getAuthCookies();
19+
if (cookies.access) return cookies.access;
20+
return "";
21+
};
22+
23+
export default new HoudiniClient({
24+
url: `${env.PUBLIC_GQL_URL}/graphql`,
25+
26+
// uncomment this to configure the network call (for things like authentication)
27+
// for more information, please visit here: https://www.houdinigraphql.com/guides/authentication
28+
fetchParams({session, metadata, document}) {
29+
const authToken = getAuthToken({
30+
session: session ?? undefined,
31+
metadata: metadata ?? undefined,
32+
useRefresh: false,
33+
});
34+
return {
35+
headers: {
36+
authorization: `Bearer ${authToken}`,
37+
},
38+
};
39+
},
40+
throwOnError: {
41+
operations: ["all"],
42+
error: errors => {
43+
if (errors.some(e => e.message === "Unauthorized")) {
44+
// TODO: Check if JWT is actually expired, or if this is an authorization issue, not authentication
45+
// TODO: Check to see if we can use the refresh token, and then reload the page
46+
// (e.g. goto with invalidateAll on current path).
47+
// This would create a choppy-ish UX (e.g. page would "soft reload")
48+
// But it would also prevent a user having to log in when they don't need to.
49+
clearAuthCookies();
50+
51+
if (typeof window !== "undefined") goto(`/auth/login?next=${encodeURI(window.location.pathname)}`);
52+
else {
53+
throw redirect(307, "/auth/login");
54+
}
55+
} else {
56+
console.error(errors);
57+
}
58+
},
59+
},
60+
plugins: [
61+
refreshAuthPlugin,
62+
subscription(ctx => {
63+
const c = new SubscriptionClient(`${env.PUBLIC_GQL_URL.replace("http", "ws")}/graphql`, {
64+
reconnect: true,
65+
lazy: true,
66+
});
67+
return {
68+
subscribe(payload, handlers) {
69+
const {unsubscribe} = c
70+
.request({
71+
...payload,
72+
context: {authorization: getAuthToken() ? `Bearer ${getAuthToken()}` : undefined},
73+
})
74+
.subscribe(handlers);
75+
return unsubscribe;
76+
},
77+
};
78+
}),
79+
],
80+
});

0 commit comments

Comments
 (0)