-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test * Wrap location hook * Use wrapped hook * Tidy up forgot password process * Return 200 when user does not exist as well * Update build action * Add curl to docker file * Update build action * Fix seed migration and add database persistance * Remove database reset * Ensure multiple accounts don't get provisioned * Remove database reset * Remove push from PR action * Add useForm hook * Move accounts forms to useForm hook * Add useForm to admin forms * Add useForm hook to command forms * Add useForm hook to user forms * Remove html qualifier * Remove debug if statement short circuit * Fix build errors * Add develop branch workflow * Fix token expiry calculation * Enhance command schema (#34) * Enable strict no console eslint rule * Add textarea to command edit form * Add button replacement for interpolation * Tidy up to fix compile errors * Fix missed token calculation * Get working interpolation replacement * Add data back to internaldata store * Implement change handler properly and remove old code * Add functioning change handler for response element * Add button margin and initialise buttons on first load * Remove comments * Add semi working selector * Add resize property to textarea * Add popup for interpolation input * Make popup mobile friendly * Ensure button converts correctly when inserted * Fix compile warnings * Add modal component * Implement form to edit complex interpolation * Move change handler out to hook * Helps if you save everything before committing * Fix linting errors * Add more commands * Move styles out * Move modal styles out * Add multiple action capability (#36) * Add new migration and change logic around inserting global admins * Fix migration and add order column to actions * Gracefully handle specifically connection refused errors on webhook * Get pages compiling again * Fix delete route and start working on create route * Implement add new action button on frontend * Add saving new or existing command with action support * Fix up errors around saving * Ensure actions save and load by order property * Ensure getCommands includes actions according to argument again * Get reordering working * Add delete action logic * Fix build errors and tidy up * Update key logic * Remove unused variables * Add dynamic provisioning (#37) * Use id as action key when possible * Break out webhook logic to generic hook and add edit account webhook post * Update vulnerable libraries and add build test for yarn audit (#38) * Update vulnerable libraries and add build test for yarn audit * Update build test * . * . * . * . * . * . * . * Update qwik * Update yarn * Update typescript and vite * Update eslint * Update dockerfile and build dependencies * Update yarn audit test * Update lock file * They done changed the cli name on me * Update readme * Update version number and pipeline
- Loading branch information
1 parent
2b6bdb5
commit 6b2dea9
Showing
60 changed files
with
9,217 additions
and
4,320 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,5 @@ | |
!tsconfig.json | ||
!vite.config.ts | ||
!yarn.lock | ||
!.yarnrc.yml | ||
!.yarn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ on: | |
push: | ||
branches: | ||
- main | ||
- release/1.1 | ||
|
||
jobs: | ||
build-and-push: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
nodeLinker: node-modules | ||
|
||
yarnPath: .yarn/releases/yarn-4.1.1.cjs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,35 @@ | ||
# Qwik City App ⚡️ | ||
# Qwik Webapp | ||
|
||
- [Qwik Docs](https://qwik.builder.io/) | ||
- [Discord](https://qwik.builder.io/chat) | ||
- [Qwik GitHub](https://github.com/BuilderIO/qwik) | ||
- [@QwikDev](https://twitter.com/QwikDev) | ||
- [Vite](https://vitejs.dev/) | ||
This webapp is designed as a web interface for a separate bot that connects to the twitch API as a chatbot. | ||
|
||
--- | ||
## Installation | ||
|
||
## Project Structure | ||
1. Ensure postgres, node 20+, and yarn are installed | ||
2. Create a `.env` file with the following data | ||
|
||
This project is using Qwik with [QwikCity](https://qwik.builder.io/qwikcity/overview/). QwikCity is just a extra set of tools on top of Qwik to make it easier to build a full site, including directory-based routing, layouts, and more. | ||
```env | ||
JWT_SECRET= <Random values for jwt encryption> | ||
Inside your project, you'll see the following directory structure: | ||
SENDGRID_API_KEY= <Sendgrid API Key (Only needed in production)> | ||
``` | ||
├── public/ | ||
│ └── ... | ||
└── src/ | ||
├── components/ | ||
│ └── ... | ||
└── routes/ | ||
└── ... | ||
``` | ||
|
||
- `src/routes`: Provides the directory based routing, which can include a hierarchy of `layout.tsx` layout files, and an `index.tsx` file as the page. Additionally, `index.ts` files are endpoints. Please see the [routing docs](https://qwik.builder.io/qwikcity/routing/overview/) for more info. | ||
|
||
- `src/components`: Recommended directory for components. | ||
|
||
- `public`: Any static assets, like images, can be placed in the public directory. Please see the [Vite public directory](https://vitejs.dev/guide/assets.html#the-public-directory) for more info. | ||
SENDGRID_FROM_ADDRESS= <From email address> | ||
## Add Integrations and deployment | ||
DATABASE_URL= postgresql://<databasename>:[email protected]:PORT | ||
Use the `yarn qwik add` command to add additional integrations. Some examples of integrations include: Cloudflare, Netlify or Express server, and the [Static Site Generator (SSG)](https://qwik.builder.io/qwikcity/static-site-generation/static-site-config/). | ||
ADMIN_EMAIL= <your-email> | ||
```shell | ||
yarn qwik add # or `yarn qwik add` | ||
``` | ||
|
||
## Development | ||
|
||
Development mode uses [Vite's development server](https://vitejs.dev/). During development, the `dev` command will server-side render (SSR) the output. | ||
ADMIN_PASSWORD= <your-password> | ||
```shell | ||
npm start # or `yarn start` | ||
ADMIN_NAME= <your-name> | ||
``` | ||
|
||
> Note: during dev mode, Vite may request a significant number of `.js` files. This does not represent a Qwik production build. | ||
3. Run `yarn install` | ||
4. Run `yarn prisma migrate dev` to populate your database with empty tables from the migration | ||
5. Run `node add-global-admin.js` to seed the data provided as admin env vars as a global admin in the db | ||
6. Run `yarn dev` | ||
|
||
## Preview | ||
## Helpful commands | ||
|
||
The preview command will create a production build of the client modules, a production build of `src/entry.preview.tsx`, and run a local server. The preview server is only for convenience to locally preview a production build, and it should not be used as a production server. | ||
|
||
```shell | ||
yarn preview # or `yarn preview` | ||
``` | ||
|
||
## Production | ||
|
||
The production build will generate client and server modules by running both client and server build commands. Additionally, the build command will use Typescript to run a type check on the source code. | ||
|
||
```shell | ||
yarn build # or `yarn build` | ||
``` | ||
|
||
## Express Server | ||
|
||
This app has a minimal [Express server](https://expressjs.com/) implementation. After running a full build, you can preview the build using the command: | ||
|
||
``` | ||
yarn serve | ||
``` | ||
The makefile contains a number of helpful commands for running in docker. Builds to this repo build the docker image and run an audit on npm package security vulnerabilities before being able to merge. To test this will pass locally you can run `npm run build` to build the app baremetal, or `make build` to build the docker image locally. Once built locally you can run either `yarn serve` to run baremetal, or `make run` to run in docker. | ||
|
||
Then visit [http://localhost:8080/](http://localhost:8080/) | ||
To inspect the database locally you can run `yarn prisma studio` to open an in browser edit tool |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
const PrismaClient = require("@prisma/client").PrismaClient; | ||
const fs = require("fs"); | ||
const crypto = require("crypto"); | ||
|
||
const insertGlobalAdmin = async () => { | ||
// Parse env variables | ||
fs.readFileSync(".env", "utf8") | ||
.split("\n") | ||
.forEach((envVar) => { | ||
const [key, value] = envVar.split("="); | ||
process.env[key] = value; | ||
}); | ||
|
||
const email = process.env.ADMIN_EMAIL; | ||
const password = process.env.ADMIN_PASSWORD; | ||
const name = process.env.ADMIN_NAME; | ||
|
||
const salt = crypto.randomUUID().replace(/-/g, ""); | ||
|
||
const hashedPassword = Buffer.from( | ||
crypto.createHash("sha256").update(`${salt}${password}`).digest("hex") | ||
).toString(); | ||
|
||
const savePassword = `${salt}$${hashedPassword}`; | ||
|
||
const client = new PrismaClient(); | ||
|
||
console.log(email); | ||
|
||
await client.$executeRaw` | ||
INSERT INTO "User" ( | ||
"email", | ||
"name", | ||
"password", | ||
"isGlobalAdmin" | ||
) | ||
SELECT ${email}, ${name}, ${savePassword}, 'true' | ||
WHERE NOT EXISTS ( | ||
SELECT 1 | ||
FROM "User" | ||
WHERE "email" = ${email} | ||
);`; | ||
|
||
await client.$disconnect(); | ||
}; | ||
|
||
insertGlobalAdmin() | ||
.then(() => { | ||
console.log("Global admin inserted successfully"); | ||
}) | ||
.catch((error) => { | ||
console.error("Error inserting global admin user:", error); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
{ | ||
"name": "webapp", | ||
"description": "Web interface for twitch chatbot", | ||
"version": "1.1.0", | ||
"engines": { | ||
"node": ">=18.0.0" | ||
"node": ">=20.0.0" | ||
}, | ||
"private": true, | ||
"scripts": { | ||
|
@@ -23,34 +24,35 @@ | |
"qwik": "qwik" | ||
}, | ||
"devDependencies": { | ||
"@builder.io/qwik": "^1.1.4", | ||
"@builder.io/qwik-city": "^1.1.4", | ||
"@builder.io/qwik": "^1.5.2", | ||
"@builder.io/qwik-city": "^1.5.2", | ||
"@types/compression": "^1.7.2", | ||
"@types/eslint": "8.4.10", | ||
"@types/express": "4.17.17", | ||
"@types/node": "^18.11.16", | ||
"@types/node-fetch": "latest", | ||
"@typescript-eslint/eslint-plugin": "5.46.1", | ||
"@typescript-eslint/parser": "5.46.1", | ||
"@typescript-eslint/eslint-plugin": "6.21.0", | ||
"@typescript-eslint/parser": "6.21.0", | ||
"compression": "^1.7.4", | ||
"eslint": "8.30.0", | ||
"eslint-plugin-qwik": "0.16.1", | ||
"prettier": "2.8.1", | ||
"preview-email": "^3.0.7", | ||
"prisma": "^4.15.0", | ||
"typescript": "4.9.4", | ||
"typescript": "5.4.5", | ||
"util": "^0.12.5", | ||
"vite": "4.0.1", | ||
"vite-tsconfig-paths": "3.5.0" | ||
"vite": "5.2.10", | ||
"vite-tsconfig-paths": "4.3.2" | ||
}, | ||
"dependencies": { | ||
"@prisma/client": "^4.15.0", | ||
"@sendgrid/mail": "^7.7.0", | ||
"@vanilla-extract/css": "^1.9.2", | ||
"@vanilla-extract/vite-plugin": "^3.7.0", | ||
"crypto-js": "^4.1.1", | ||
"crypto-js": "^4.2.0", | ||
"express": "4.18.2", | ||
"jose": "^4.11.1", | ||
"undici": "5.14.0", | ||
"express": "4.18.2" | ||
} | ||
"undici": "5.19.1" | ||
}, | ||
"packageManager": "[email protected]" | ||
} |
5 changes: 5 additions & 0 deletions
5
prisma/migrations/20231015081329_add_multiple_actions/down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
ALTER TABLE "Command" ADD COLUMN "response" TEXT NULL; | ||
|
||
ALTER TABLE "Action" DROP CONSTRAINT "Action_commandId_fkey"; | ||
|
||
DROP TABLE "Action" |
20 changes: 20 additions & 0 deletions
20
prisma/migrations/20231015081329_add_multiple_actions/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
-- CreateTable | ||
CREATE TABLE "Action" ( | ||
"id" SERIAL NOT NULL, | ||
"commandId" INTEGER NOT NULL, | ||
"order" INTEGER NULL, | ||
"type" TEXT NOT NULL, | ||
"content" TEXT NOT NULL, | ||
|
||
CONSTRAINT "Action_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Action" ADD CONSTRAINT "Action_commandId_fkey" FOREIGN KEY ("commandId") REFERENCES "Command"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- Copy data from command into action | ||
INSERT INTO "Action" ("commandId", "type", "content") | ||
SELECT id, 'RESPONSE', response FROM "Command"; | ||
|
||
-- AlterTable | ||
ALTER TABLE "Command" DROP COLUMN "response"; |
Oops, something went wrong.