Skip to content

Commit

Permalink
feat: initial OAuth support
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinKolarik committed Aug 30, 2024
1 parent 846bd0b commit 2c4e0f3
Show file tree
Hide file tree
Showing 53 changed files with 10,656 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab

[*.md]
indent_style = space

[*.{yaml,yml}]
indent_style = space
indent_size = 2
84 changes: 84 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"extends": "@martin-kolarik/eslint-config/typescript",
"ignorePatterns": [
"coverage/**",
"data/**",
"dist/**"
],
"overrides": [
{
"files": [
"src/**/*.ts"
],
"extends": "@martin-kolarik/eslint-config/typescript-type-checking",
"parserOptions": {
"project": true
}
},
{
"files": [
"**"
],
"rules": {
"no-duplicate-imports": "off",
"no-extra-parens": "off"
}
},
{
"files": [
"public/**"
],
"parserOptions": {
"sourceType": "script"
},
"rules": {
"no-undef": "off",
"no-unused-vars": "off"
}
},
{
"files": [
"test/**"
],
"rules": {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"no-restricted-properties": [
"error",
{
"object": "sinon",
"property": "spy"
},
{
"object": "sinon",
"property": "stub"
},
{
"object": "sinon",
"property": "mock"
},
{
"object": "sinon",
"property": "fake"
},
{
"object": "sinon",
"property": "restore"
},
{
"object": "sinon",
"property": "reset"
},
{
"object": "sinon",
"property": "resetHistory"
},
{
"object": "sinon",
"property": "resetBehavior"
}
]
}
}
]
}
4 changes: 4 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# These are supported funding model platforms
github: jsdelivr
open_collective: jsdelivr
custom: ['https://www.jsdelivr.com/sponsors']
60 changes: 60 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: CI

on:
push:
branches: [ "*" ]
pull_request:
branches: [ "*" ]

jobs:
build:
name: Run tests
runs-on: ubuntu-latest

env:
NODE_ENV: test

services:
redis:
image: redis/redis-stack-server:latest
ports:
- 16379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
mariadb:
image: mariadb:10.11.5
ports:
- 13306:3306
env:
MARIADB_DATABASE: dashboard-globalping-test
MARIADB_USER: directus
MARIADB_PASSWORD: password
MARIADB_RANDOM_ROOT_PASSWORD: 1
options: >-
--health-cmd "mysqladmin ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Build
run: |
npm ci
npm run build
- name: Test Unit, Integration
run: |
npm run lint
npm run coverage
- name: Test Dist
run: |
rm -rf node_modules
npm ci --omit=dev
npm run test:dist
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.idea/
.vscode/
.nyc_output/
node_modules/
coverage/
dist/
tmp/
config/local*
.eslintcache
.env
43 changes: 43 additions & 0 deletions .mocharc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
module.exports = {
'exit': true,
'timeout': 10000,
'check-leaks': true,
'file': [
'test/setup.ts',
],
'spec': [
// 'test/tests/unit/**/*.test.ts',
'test/tests/integration/**/*.test.ts',
],
'node-option': [
'enable-source-maps',
'experimental-specifier-resolution=node',
'loader=ts-node/esm',
],
'globals': [
'__extends',
'__assign',
'__rest',
'__decorate',
'__param',
'__metadata',
'__awaiter',
'__generator',
'__exportStar',
'__createBinding',
'__values',
'__read',
'__spread',
'__spreadArrays',
'__spreadArray',
'__await',
'__asyncGenerator',
'__asyncDelegator',
'__asyncValues',
'__makeTemplateObject',
'__importStar',
'__importDefault',
'__classPrivateFieldGet',
'__classPrivateFieldSet',
],
};
9 changes: 9 additions & 0 deletions config/create-dbs.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CREATE DATABASE IF NOT EXISTS `dashboard-globalping`;
GRANT ALL PRIVILEGES ON `dashboard-globalping`.* to 'directus'@'%';

CREATE DATABASE IF NOT EXISTS `dashboard-globalping-test`;
GRANT ALL PRIVILEGES ON `dashboard-globalping-test`.* to 'directus'@'%';

-- Directus issue https://github.com/directus/directus/discussions/11786
ALTER DATABASE `dashboard-globalping` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER DATABASE `dashboard-globalping-test` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
16 changes: 16 additions & 0 deletions config/custom-environment-variables.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const _ = require('lodash');
const df = require('./default.cjs');

function mapEnvConfig (object, prefix = '') {
return _.mapValues(object, (value, key) => {
if (_.isObject(value)) {
return mapEnvConfig(value, (prefix ? `${prefix}_` : '') + _.snakeCase(key).toUpperCase());
}

return (prefix ? `${prefix}_` : '') + _.snakeCase(key).toUpperCase();
});
}

const mapped = mapEnvConfig(df);

module.exports = mapped;
30 changes: 30 additions & 0 deletions config/default.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module.exports = {
server: {
host: 'https://auth.globalping.io',
docsHost: 'https://www.jsdelivr.com',
dashHost: 'https://dash.globalping.io',
directusHost: 'https://dash-directus.globalping.io',
port: 13110,
processes: 1,
session: {
cookieName: 'dash_session_token',
cookieSecret: '',
},
},
redis: {
url: 'redis://localhost:6379',
socket: {
tls: false,
},
},
db: {
type: 'mysql',
connection: {
host: 'localhost',
user: 'directus',
password: 'password',
database: 'dashboard-globalping',
port: 3306,
},
},
};
21 changes: 21 additions & 0 deletions config/development.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
server: {
host: 'http://localhost:13110',
dashHost: 'http://localhost:13010',
directusHost: 'http://localhost:18055',
session: {
cookieSecret: 'xxx',
},
},
redis: {
url: 'redis://localhost:16379',
socket: {
tls: false,
},
},
db: {
connection: {
port: 13306,
},
},
};
1 change: 1 addition & 0 deletions config/production.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {};
20 changes: 20 additions & 0 deletions config/test.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = {
server: {
session: {
cookieSecret: 'xxx',
},
},
redis: {
url: 'redis://localhost:16379',
socket: {
tls: false,
},
},
db: {
connection: {
port: 13306,
database: 'dashboard-globalping-test',
multipleStatements: true,
},
},
};
33 changes: 33 additions & 0 deletions knexfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import _ from 'lodash';
import config from 'config';

const __dirname = path.dirname(fileURLToPath(import.meta.url));

const dbConfig = config.get('db');

/**
* @typedef {import('knex').Knex.Config} KnexConfig
* @type {{ [key: string]: KnexConfig }}
*/
export default _.merge({}, ...[ 'development', 'production', 'staging', 'test' ].map((environment) => {
return {
[environment]: {
client: dbConfig.type,
connection: dbConfig.connection,
pool: {
min: 0,
max: 10,
propagateCreateError: false,
},
acquireConnectionTimeout: 5000,
seeds: {
directory: path.join(__dirname, `./seeds/${environment}`),
},
migrations: {
directory: path.join(__dirname, `./migrations`),
},
},
};
}));
11 changes: 11 additions & 0 deletions migrations/create-tables.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import fs from 'node:fs';
import path from 'path';
import { fileURLToPath } from 'url';

export const up = async (db) => {
const __filename = fileURLToPath(import.meta.url);
const query = fs.readFileSync(path.join(__filename + '.sql'), 'utf8');
await db.schema.raw(query);
};

export const down = () => {};
Loading

0 comments on commit 2c4e0f3

Please sign in to comment.