From 8940086e961e74c9ac563ac1edd3abe3ee162df8 Mon Sep 17 00:00:00 2001 From: Untone Date: Mon, 5 Feb 2024 14:49:38 +0300 Subject: [PATCH] 1.0.2 --- .gitea/workflows/main.yml | 22 +++++ CHANGELOG.txt | 3 + Dockerfile | 3 +- biome.json | 67 +++++++++++++++ index.ts | 24 +++--- package-lock.json | 176 +++++++++++++++++++++++++++++++++++++- package.json | 17 ++-- 7 files changed, 291 insertions(+), 21 deletions(-) create mode 100644 .gitea/workflows/main.yml create mode 100644 biome.json diff --git a/.gitea/workflows/main.yml b/.gitea/workflows/main.yml new file mode 100644 index 0000000..c88393d --- /dev/null +++ b/.gitea/workflows/main.yml @@ -0,0 +1,22 @@ +name: 'deploy' +on: [push] + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - name: Cloning repo + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Get Repo Name + id: repo_name + run: echo "::set-output name=repo::$(echo ${GITHUB_REPOSITORY##*/})" + + - name: Push to dokku + uses: dokku/github-action@master + with: + branch: 'main' + git_remote_url: 'ssh://dokku@staging.discours.io:22/${{ steps.repo_name.outputs.repo }}' + ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} \ No newline at end of file diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 366c349..d4273ce 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,6 +1,9 @@ [1.0.2] - moved to typescript +- added biome - authorizer adapter added +- migrated to Dockerfile deploy +- gitea ci script added [1.0.0] - basic CRDT server \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index e613eac..950fdbd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,5 @@ -FROM node:18 +FROM node:alpine EXPOSE 4242 COPY . . RUN npm install +CMD npm start diff --git a/biome.json b/biome.json new file mode 100644 index 0000000..7df32a8 --- /dev/null +++ b/biome.json @@ -0,0 +1,67 @@ +{ + "$schema": "https://biomejs.dev/schemas/1.5.3/schema.json", + "files": { + "include": ["*.tsx", "*.ts", "*.js", "*.json"], + "ignore": ["./dist", "./node_modules", ".husky", "docs", "gen"] + }, + "vcs": { + "defaultBranch": "dev", + "useIgnoreFile": true + }, + "organizeImports": { + "enabled": true, + "ignore": ["./api", "./gen"] + }, + "formatter": { + "indentStyle": "space", + "indentWidth": 2, + "lineWidth": 108, + "ignore": ["./src/graphql/schema", "./gen"] + }, + "javascript": { + "formatter": { + "semicolons": "asNeeded", + "quoteStyle": "single", + "trailingComma": "all", + "enabled": true, + "jsxQuoteStyle": "double", + "arrowParentheses": "always" + } + }, + "linter": { + "ignore": ["*.scss", "*.md", ".DS_Store", "*.svg"], + "enabled": true, + "rules": { + "recommended": true, + "complexity": { + "all": true, + "noForEach": "off", + "useOptionalChain": "warn", + "useLiteralKeys": "off" + }, + "a11y": { + "useHeadingContent": "off", + "useKeyWithClickEvents": "off", + "useKeyWithMouseEvents": "off", + "useAnchorContent": "off", + "useValidAnchor": "off", + "useMediaCaption": "off", + "useAltText": "off", + "useButtonType": "off", + "noRedundantAlt": "off", + "noSvgWithoutTitle": "off" + }, + "nursery": { + "useImportRestrictions": "off" + }, + "style": { + "useNamingConvention": "off", + "noUnusedTemplateLiteral": "off" + }, + "suspicious": { + "noConsoleLog": "off", + "noAssignInExpressions": "off" + } + } + } +} diff --git a/index.ts b/index.ts index 2b90122..fa5814e 100644 --- a/index.ts +++ b/index.ts @@ -1,17 +1,22 @@ -import { Server, onAuthenticatePayload } from "@hocuspocus/server"; -import { ApiResponse, Authorizer, ConfigType, ValidateJWTTokenInput, ValidateJWTTokenResponse } from '@authorizerdev/authorizer-js'; +import { + ApiResponse, + Authorizer, + ConfigType, + ValidateJWTTokenInput, + ValidateJWTTokenResponse, +} from '@authorizerdev/authorizer-js' +import { Server, onAuthenticatePayload } from '@hocuspocus/server' const authorizer = new Authorizer({ clientID: process.env.AUTHORIZER_CLIENT_ID, authorizerURL: 'https://auth.discours.io', - redirectURL: 'https://testing.discours.io' -} as ConfigType); - + redirectURL: 'https://testing.discours.io', +} as ConfigType) const server = await Server.configure({ port: 4242, async onConnect({ connection }) { - connection.requiresAuthentication = false; // FIXME + connection.requiresAuthentication = false // FIXME }, async onAuthenticate(data: onAuthenticatePayload) { // Danger! This won’t be called for that connection attempt. @@ -24,7 +29,7 @@ const server = await Server.configure({ if (params.token) { // NOTE: ожидаем, что клиент отправит токен const response: ApiResponse = await authorizer.validateJWTToken(params) - if(response?.data?.is_valid) { + if (response?.data?.is_valid) { const { sub: user, allowed_roles: roles } = response.data.claims console.debug(`user_id: ${user} roles: ${roles}`) } else { @@ -32,8 +37,7 @@ const server = await Server.configure({ } } } - }, -}).listen(); +}).listen() -server.listen(); +server.listen() diff --git a/package-lock.json b/package-lock.json index 91f7192..1d50ebb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,16 +1,20 @@ { "name": "discours-hocuspocus", - "version": "1.0.0", + "version": "1.0.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "discours-hocuspocus", - "version": "1.0.0", + "version": "1.0.2", "license": "MIT", "dependencies": { "@authorizerdev/authorizer-js": "2.0.0", "@hocuspocus/server": "2.0.1" + }, + "devDependencies": { + "@biomejs/biome": "1.5.3", + "typescript": "5.3.3" } }, "node_modules/@authorizerdev/authorizer-js": { @@ -27,6 +31,161 @@ "url": "https://github.com/sponsors/authorizerdev" } }, + "node_modules/@biomejs/biome": { + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/@biomejs/biome/-/biome-1.5.3.tgz", + "integrity": "sha512-yvZCa/g3akwTaAQ7PCwPWDCkZs3Qa5ONg/fgOUT9e6wAWsPftCjLQFPXBeGxPK30yZSSpgEmRCfpGTmVbUjGgg==", + "dev": true, + "hasInstallScript": true, + "bin": { + "biome": "bin/biome" + }, + "engines": { + "node": ">=14.*" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/biome" + }, + "optionalDependencies": { + "@biomejs/cli-darwin-arm64": "1.5.3", + "@biomejs/cli-darwin-x64": "1.5.3", + "@biomejs/cli-linux-arm64": "1.5.3", + "@biomejs/cli-linux-arm64-musl": "1.5.3", + "@biomejs/cli-linux-x64": "1.5.3", + "@biomejs/cli-linux-x64-musl": "1.5.3", + "@biomejs/cli-win32-arm64": "1.5.3", + "@biomejs/cli-win32-x64": "1.5.3" + } + }, + "node_modules/@biomejs/cli-darwin-arm64": { + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/@biomejs/cli-darwin-arm64/-/cli-darwin-arm64-1.5.3.tgz", + "integrity": "sha512-ImU7mh1HghEDyqNmxEZBoMPr8SxekkZuYcs+gynKlNW+TALQs7swkERiBLkG9NR0K1B3/2uVzlvYowXrmlW8hw==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=14.*" + } + }, + "node_modules/@biomejs/cli-darwin-x64": { + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/@biomejs/cli-darwin-x64/-/cli-darwin-x64-1.5.3.tgz", + "integrity": "sha512-vCdASqYnlpq/swErH7FD6nrFz0czFtK4k/iLgj0/+VmZVjineFPgevOb+Sr9vz0tk0GfdQO60bSpI74zU8M9Dw==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=14.*" + } + }, + "node_modules/@biomejs/cli-linux-arm64": { + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-arm64/-/cli-linux-arm64-1.5.3.tgz", + "integrity": "sha512-cupBQv0sNF1OKqBfx7EDWMSsKwRrBUZfjXawT4s6hKV6ALq7p0QzWlxr/sDmbKMLOaLQtw2Qgu/77N9rm+f9Rg==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=14.*" + } + }, + "node_modules/@biomejs/cli-linux-arm64-musl": { + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-arm64-musl/-/cli-linux-arm64-musl-1.5.3.tgz", + "integrity": "sha512-DYuMizUYUBYfS0IHGjDrOP1RGipqWfMGEvNEJ398zdtmCKLXaUvTimiox5dvx4X15mBK5M2m8wgWUgOP1giUpQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=14.*" + } + }, + "node_modules/@biomejs/cli-linux-x64": { + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-x64/-/cli-linux-x64-1.5.3.tgz", + "integrity": "sha512-YQrSArQvcv4FYsk7Q91Yv4uuu5F8hJyORVcv3zsjCLGkjIjx2RhjYLpTL733SNL7v33GmOlZY0eFR1ko38tuUw==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=14.*" + } + }, + "node_modules/@biomejs/cli-linux-x64-musl": { + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-x64-musl/-/cli-linux-x64-musl-1.5.3.tgz", + "integrity": "sha512-UUHiAnlDqr2Y/LpvshBFhUYMWkl2/Jn+bi3U6jKuav0qWbbBKU/ByHgR4+NBxpKBYoCtWxhnmatfH1bpPIuZMw==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=14.*" + } + }, + "node_modules/@biomejs/cli-win32-arm64": { + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/@biomejs/cli-win32-arm64/-/cli-win32-arm64-1.5.3.tgz", + "integrity": "sha512-HxatYH7vf/kX9nrD+pDYuV2GI9GV8EFo6cfKkahAecTuZLPxryHx1WEfJthp5eNsE0+09STGkKIKjirP0ufaZA==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=14.*" + } + }, + "node_modules/@biomejs/cli-win32-x64": { + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/@biomejs/cli-win32-x64/-/cli-win32-x64-1.5.3.tgz", + "integrity": "sha512-fMvbSouZEASU7mZH8SIJSANDm5OqsjgtVXlbUqxwed6BP7uuHRSs396Aqwh2+VoW8fwTpp6ybIUoC9FrzB0kyA==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=14.*" + } + }, "node_modules/@hocuspocus/common": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/@hocuspocus/common/-/common-2.0.1.tgz", @@ -151,6 +310,19 @@ "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" }, + "node_modules/typescript": { + "version": "5.3.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.3.tgz", + "integrity": "sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==", + "dev": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, "node_modules/uuid": { "version": "9.0.0", "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.0.tgz", diff --git a/package.json b/package.json index af6e281..4f02384 100644 --- a/package.json +++ b/package.json @@ -1,24 +1,25 @@ { - "name": "discours-hocuspocus", + "name": "discours-editing-server", "version": "1.0.2", - "description": "", + "description": "discours.io webrtc p2p network helping crdt-server", "main": "index.ts", "type": "module", "scripts": { - "start": "node index.ts" + "lint": "npx @biomejs/biome check --apply-unsafe .", + "start": "npx tsc index.ts" }, "repository": { "type": "git", - "url": "git+https://dev.discours.io/discours.io/editing-server.git" + "url": "git+https://dev.discours.io/discours.io/crdt-server.git" }, "author": "Discours Dev Team", "license": "MIT", - "bugs": { - "url": "https://gitlab.com/discoursio/hocuspocus/issues" - }, - "homepage": "https://gitlab.com/discoursio/hocuspocus#readme", "dependencies": { "@authorizerdev/authorizer-js": "2.0.0", "@hocuspocus/server": "2.0.1" + }, + "devDependencies": { + "@biomejs/biome": "1.5.3", + "typescript": "5.3.3" } }