Skip to content

Commit

Permalink
Merge branch 'dev' into refactor/user-platform-accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsMeBrianD authored Sep 22, 2023
2 parents 3457b58 + 5492bf1 commit 7c84820
Show file tree
Hide file tree
Showing 197 changed files with 8,336 additions and 2,740 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,5 @@ core/config/development.json.bak
core/config/main.json

core/config/staging.json

clients/web/schema.graphql
25 changes: 25 additions & 0 deletions aUsefulTmuxScript.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/zsh

SESSIONNAME="sprocket"
tmux has-session -t $SESSIONNAME &> /dev/null

if [ $? != 0 ]
then
tmux new-session -s $SESSIONNAME -n script -d
tmux split-window -h
tmux selectp -t 0
tmux send-keys 'npm run build --workspaces --if-present' C-m
tmux split-window -v
tmux selectp -t 1
tmux send-keys 'cd $PWD/core' C-m
tmux send-keys 'sleep 120; npm run dev;' C-m
tmux selectp -t 2
tmux send-keys 'cd $PWD/clients/web' C-m 'reset' C-m
tmux send-keys 'export PUBLIC_GQL_URL=http://localhost:3001; sleep 240; npm run dev' C-m
tmux split-window -v
tmux selectp -t 3
tmux send-keys 'cd $PWD/common' C-m 'reset' C-m
tmux selectp -t 0
fi

tmux attach -t $SESSIONNAME
2 changes: 1 addition & 1 deletion clients/discord-bot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"homepage": "https://github.com/SprocketBot/service-template#readme",
"dependencies": {
"@nestjs/common": "^8.2.3",
"@nestjs/core": "^8.2.3",
"@nestjs/core": "^9.0.5",
"@nestjs/microservices": "^8.2.3",
"@sprocketbot/common": "^0.2.13",
"bufferutil": "^4.0.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {CoreModule, EventsModule} from "@sprocketbot/common";
import {DiscordModule} from "../../discord/discord.module";
import {EmbedModule} from "../../embed/embed.module";
import {CommandsModule} from "../../marshal";
import {DatabaseSyncMarshal} from "./database-sync.marshal";
// import {CommandDecoratorTestMarshal} from "./command-decorator-test.marshal";
// import {DebugCommandsMarshal} from "./debug-commands.marshal";
import {DeveloperCommandsMarshal} from "./developer-commands.marshal";
Expand All @@ -21,6 +22,7 @@ import {DeveloperCommandsMarshal} from "./developer-commands.marshal";
// SprocketConfigurationMarshal,
// CommandDecoratorTestMarshal,
DeveloperCommandsMarshal,
DatabaseSyncMarshal,
],
})
export class AdministratorCommandsModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import {Logger} from "@nestjs/common";
import {CoreEndpoint, ResponseStatus} from "@sprocketbot/common";
import {Message} from "discord.js";

import {Command, Marshal} from "../../marshal";

export class DatabaseSyncMarshal extends Marshal {
private readonly logger = new Logger(DatabaseSyncMarshal.name);

@Command({
name: "syncNames",
args: [],
docs: "Sync all player names in the main MLE server.",
})
async syncNames(m: Message): Promise<void> {
if (
![
"353194025995730945", // Adi
"105408136285818880", // Hyper
"423850557334093827", // Hoos
"470703275163779084", // Achilles
"243430304319143936", // Kunics
].includes(m.author.id)
)
return;

await m.reply("Starting sync...");

const serverId = "172404472637685760"; // MLE Main
const server = await this.botClient.guilds.fetch(serverId);
await server.members.fetch();

for (const member of server.members.cache.values()) {
const nicknameRequest = await this.coreService.send(CoreEndpoint.GetNicknameByDiscordUser, {
discordId: member.id,
});
if (nicknameRequest.status === ResponseStatus.ERROR) {
this.logger.log(`Failed to get nickname for ${member.id}`);
continue;
}

if (member.nickname === nicknameRequest.data) continue;

await member.setNickname(nicknameRequest.data).catch(err => {
this.logger.error(err);
});
}

await m.reply("Sync complete!");
}
}
2 changes: 1 addition & 1 deletion clients/image-generation-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"lint:check": "eslint src"
},
"devDependencies": {
"@sveltejs/kit": "^1.0.0-next.156",
"@sveltejs/kit": "^1.15.2",
"@types/amqplib": "^0.8.2",
"autoprefixer": "^10.3.3",
"postcss": "^8.3.6",
Expand Down
2 changes: 2 additions & 0 deletions clients/web/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ node_modules
.env
.env.*
!.env.example

$houdini
9 changes: 9 additions & 0 deletions clients/web/.graphqlrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
projects:
default:
schema:
- ./schema.graphql
- ./$houdini/graphql/schema.graphql
documents:
- '**/*.gql'
- '**/*.svelte'
- ./$houdini/graphql/documents.gql
9 changes: 9 additions & 0 deletions clients/web/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ARG BASE_IMAGE
FROM $BASE_IMAGE AS test_image
ENTRYPOINT npm run test --workspace=clients/web

FROM $BASE_IMAGE AS app_image
RUN DISABLE_CONFIG=true npm run gen-sdl --workspace=core
RUN cp /app/core/schema.graphql /app/clients/web/schema.graphql
RUN npm run build --workspace=clients/web
ENTRYPOINT node /app/clients/web/build/index.js
8 changes: 4 additions & 4 deletions clients/web/histoire.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {defineConfig} from "histoire";
import {HstSvelte} from "@histoire/plugin-svelte";
import { defineConfig } from "histoire";
import { HstSvelte } from "@histoire/plugin-svelte";
import path from "path";

import {palette} from "./src/lib/palette";
const {primary, gray} = palette;
import { palette } from "./src/lib/palette";
const { primary, gray } = palette;

export default defineConfig({
plugins: [HstSvelte()],
Expand Down
18 changes: 18 additions & 0 deletions clients/web/houdini.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/// <references types="houdini-svelte">

/** @type {import('houdini').ConfigFile} */
const config = {
"watchSchema": {
url(env) {
return `${env.PUBLIC_GQL_URL}/graphql`
}
},
"plugins": {
"houdini-svelte": {},
},
scalars: {
DateTime: { type: Date.name }
}
}

export default config
111 changes: 61 additions & 50 deletions clients/web/package.json
Original file line number Diff line number Diff line change
@@ -1,52 +1,63 @@
{
"name": "web",
"version": "0.0.1",
"private": true,
"scripts": {
"dev": "vite dev",
"build": "vite build",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"lint": "eslint src --fix",
"format": "prettier src --write",
"story:dev": "histoire dev",
"story:build": "histoire build",
"story:preview": "histoire preview"
},
"devDependencies": {
"@histoire/plugin-svelte": "^0.12.4",
"@steeze-ui/heroicons": "^2.1.0",
"@steeze-ui/svelte-icon": "^1.3.2",
"@sveltejs/adapter-auto": "^1.0.1",
"@sveltejs/kit": "^1.1.1",
"@types/lodash.times": "^4.3.7",
"@typescript-eslint/eslint-plugin": "^5.27.0",
"@typescript-eslint/parser": "^5.27.0",
"autoprefixer": "^10.4.7",
"date-fns": "^2.29.3",
"date-picker-svelte": "^2.2.5",
"eslint": "^8.16.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-svelte3": "^4.0.0",
"filedrop-svelte": "^0.1.2",
"histoire": "^0.12.4",
"lodash.times": "^4.3.2",
"nanoid": "^4.0.0",
"postcss": "^8.4.14",
"postcss-load-config": "^4.0.1",
"prettier-plugin-svelte": "^2.9.0",
"svelte": "^3.44.0",
"svelte-check": "^2.7.1",
"svelte-preprocess": "^4.10.7",
"tailwindcss": "^3.1.5",
"tslib": "^2.3.1",
"typescript": "^4.7.4",
"vite": "^4.0.4"
},
"type": "module",
"dependencies": {
"@faker-js/faker": "^7.6.0",
"echarts": "^5.4.1"
}
"name": "web",
"version": "0.0.1",
"private": true,
"scripts": {
"dev": "vite dev",
"build": "vite build",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"lint": "eslint src --fix",
"format": "prettier src --write",
"story:dev": "histoire dev",
"story:build": "histoire build",
"story:preview": "histoire preview"
},
"devDependencies": {
"@histoire/plugin-svelte": "^0.15.4",
"@steeze-ui/heroicons": "^2.1.0",
"@steeze-ui/simple-icons": "^1.4.0",
"@steeze-ui/svelte-icon": "^1.3.2",
"@sveltejs/adapter-auto": "^1.0.1",
"@sveltejs/kit": "^1.15.2",
"@types/lodash.startcase": "^4.4.7",
"@types/lodash.times": "^4.3.7",
"@typescript-eslint/eslint-plugin": "^5.27.0",
"@typescript-eslint/parser": "^5.27.0",
"autoprefixer": "^10.4.7",
"date-fns": "^2.29.3",
"date-picker-svelte": "^2.2.5",
"eslint": "^8.16.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-svelte3": "^4.0.0",
"filedrop-svelte": "^0.1.2",
"histoire": "^0.15.4",
"houdini": "^1.0.9",
"houdini-svelte": "^1.0.9",
"lodash.times": "^4.3.2",
"nanoid": "^4.0.0",
"postcss": "^8.4.14",
"postcss-load-config": "^4.0.1",
"prettier-plugin-svelte": "^2.9.0",
"svelte": "^3.44.0",
"svelte-check": "^2.7.1",
"svelte-preprocess": "^4.10.7",
"tailwindcss": "^3.1.5",
"tslib": "^2.3.1",
"typescript": "^4.7.4",
"vite": "^4.1.5"
},
"type": "module",
"dependencies": {
"@faker-js/faker": "^7.6.0",
"@fontsource/montserrat": "^4.5.14",
"@sveltejs/adapter-node": "^1.0.0-next.106",
"@tanstack/svelte-table": "^8.9.3",
"echarts": "^5.4.1",
"jwt-decode": "^3.1.2",
"lodash.startcase": "^4.4.0",
"subscriptions-transport-ws": "^0.11.0",
"typescript-cookie": "^1.0.4"
}
}
11 changes: 11 additions & 0 deletions clients/web/src/app.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,15 @@ declare namespace App {
// interface PageData {}
// interface Error {}
// interface Platform {}
interface Session {
access?: string;
refresh?: string;
}
interface Metadata {
/**
* Used to force the use of a specific access token.
* Useful when running mutations / queries before the session updates
*/
accessTokenOverride?: string;
}
}
4 changes: 4 additions & 0 deletions clients/web/src/app.postcss
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

body {
font-family: "Montserrat";
}
80 changes: 80 additions & 0 deletions clients/web/src/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import {env} from "$env/dynamic/public";
import {HoudiniClient} from "$houdini";
import {SubscriptionClient} from "subscriptions-transport-ws";
import {subscription} from "$houdini/plugins";
import {goto} from "$app/navigation";
import {getAuthCookies, clearAuthCookies} from "$lib/api";
import {redirect} from "@sveltejs/kit";
import {refreshAuthPlugin} from "./houdini/refresh-auth.plugin";

const getAuthToken = ({
session,
metadata,
useRefresh,
}: {session?: App.Session; metadata?: App.Metadata; useRefresh?: boolean} = {}) => {
if (metadata?.accessTokenOverride) return metadata.accessTokenOverride;
if (useRefresh && session?.refresh) return session.refresh;
if (session?.access) return session.access;
const cookies = getAuthCookies();
if (cookies.access) return cookies.access;
return "";
};

export default new HoudiniClient({
url: `${env.PUBLIC_GQL_URL}/graphql`,

// uncomment this to configure the network call (for things like authentication)
// for more information, please visit here: https://www.houdinigraphql.com/guides/authentication
fetchParams({session, metadata, document}) {
const authToken = getAuthToken({
session: session ?? undefined,
metadata: metadata ?? undefined,
useRefresh: false,
});
return {
headers: {
authorization: `Bearer ${authToken}`,
},
};
},
throwOnError: {
operations: ["all"],
error: errors => {
if (errors.some(e => e.message === "Unauthorized")) {
// TODO: Check if JWT is actually expired, or if this is an authorization issue, not authentication
// TODO: Check to see if we can use the refresh token, and then reload the page
// (e.g. goto with invalidateAll on current path).
// This would create a choppy-ish UX (e.g. page would "soft reload")
// But it would also prevent a user having to log in when they don't need to.
clearAuthCookies();

if (typeof window !== "undefined") goto(`/auth/login?next=${encodeURI(window.location.pathname)}`);
else {
throw redirect(307, "/auth/login");
}
} else {
console.error(errors);
}
},
},
plugins: [
refreshAuthPlugin,
subscription(ctx => {
const c = new SubscriptionClient(`${env.PUBLIC_GQL_URL.replace("http", "ws")}/graphql`, {
reconnect: true,
lazy: true,
});
return {
subscribe(payload, handlers) {
const {unsubscribe} = c
.request({
...payload,
context: {authorization: getAuthToken() ? `Bearer ${getAuthToken()}` : undefined},
})
.subscribe(handlers);
return unsubscribe;
},
};
}),
],
});
Loading

0 comments on commit 7c84820

Please sign in to comment.