Skip to content

Commit

Permalink
refactor: copy forward qoverflow api source
Browse files Browse the repository at this point in the history
  • Loading branch information
Xunnamius committed May 27, 2023
1 parent 832bd2b commit 764312e
Show file tree
Hide file tree
Showing 190 changed files with 223,669 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
coverage:
range: '75...100'
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
charset = utf-8
indent_style = space
indent_size = 2
197 changes: 197 additions & 0 deletions .env.default
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
### GLOBAL VARIABLES ###

# If !false, Next's bundle(s) will be analyzed and report files generated.
ANALYZE=false

# This will overwrite the NODE_ENV setting during runtime and for the compiled
# applications.
#
# Recognized values: test development production
# Default value: empty
NODE_ENV=

# MongoDB connect URI. Specify auth credentials if necessary. YOU MUST *NOT*
# SPECIFY A DATABASE AT THE END!
MONGODB_URI=mongodb://127.0.0.1:27017

# Dedicated port to be used by the MongoDB Memory Server during unit tests.
# Especially useful when stepping through code, since you can always access the
# db at `mongodb://127.0.0.1:MONGODB_MS_PORT` when the debugger is paused.
# Tip: call `jest.setTimeout()` with a large number (i.e. 10**6) to ensure the
# MongoClient isn't closed randomly leading to strange errors.
#
# Leave this blank to choose any random port (not recommended). Note: this
# option is also used when Node is started in debug mode, e.g. `node
# --inspect-brk` or `node --debug`, or if the debugger is attached before the
# database connection is memoized.
MONGODB_MS_PORT=6666

# Determines the maximum allowed character length of an *entire* HTTP
# Authorization header. The default is 500.
AUTH_HEADER_MAX_LENGTH=500

# Controls which versions of the API will respond to requests. Examples (disable
# v1; disable v1 and v2; disable v3, v5, and v7):
# DISABLED_API_VERSIONS=1
# DISABLED_API_VERSIONS=1,2
# DISABLED_API_VERSIONS=3,5,7
#
# Note that `DISABLED_API_VERSIONS=` (i.e. empty) means no
# versions are disabled!
DISABLED_API_VERSIONS=

# Determines the number of items returned by paginated endpoints.
RESULTS_PER_PAGE=100

# If !false, all rate limits and exponential soft banning will be ignored.
IGNORE_RATE_LIMITS=false

# If !false, no one will be able to use the API.
LOCKOUT_ALL_CLIENTS=false

# Controls what request methods are allowed. Empty means all are allowed
# (default).
#
# Example, to make API read-only:
# DISALLOWED_METHODS=POST,PUT
DISALLOWED_METHODS=

# Every Nth request will be be cancelled and an HTTP 555 response returned. Note
# that, in addition to every Nth request, the very first request sent to the API
# will also return a contrived error. Set to 0 to disable all contrived errors.
REQUESTS_PER_CONTRIVED_ERROR=10

# Maximum allowed size of a request body (and content-length header value) in
# bytes. Should be a string like 1kb, 1mb, 500b.
MAX_CONTENT_LENGTH_BYTES=10kb

# Maximum number of parameters that can be passed to endpoints that accept
# multiple slash parameters.
MAX_PARAMS_PER_REQUEST=100

# Minimum allowed string length of a username.
MIN_USER_NAME_LENGTH=4

# Maximum allowed string length of a username.
MAX_USER_NAME_LENGTH=16

# Minimum allowed string length of a user email.
MIN_USER_EMAIL_LENGTH=4

# Maximum allowed string length of a user email.
MAX_USER_EMAIL_LENGTH=75

# Expected string length of a user's cryptographic salt (hexadecimal length).
USER_SALT_LENGTH=32

# Expected string length of a user's cryptographic key (hexadecimal length).
USER_KEY_LENGTH=128

# Maximum allowed length of a comment.
MAX_COMMENT_LENGTH=150

# Maximum allowed length of a question title.
MAX_QUESTION_TITLE_LENGTH=150

# Maximum allowed size of a question body. Should be a string like 1kb, 1mb,
# 500b.
MAX_QUESTION_BODY_LENGTH_BYTES=3kb

# Maximum allowed size of an answer body. Should be a string like 1kb, 1mb,
# 500b.
MAX_ANSWER_BODY_LENGTH_BYTES=3kb

# Maximum allowed length of a question subject.
MAX_MAIL_SUBJECT_LENGTH=75

# Maximum allowed size of an mail (direct message) body. Should be a string like
# 1kb, 1mb, 500b.
MAX_MAIL_BODY_LENGTH_BYTES=512b

### EXTERNAL SCRIPT VARIABLES ###
# (optional unless using the relevant external script)

# How often this script is going to be invoked. This doesn't determine anything
# automatically on its own, this is useful to ensure the script works no matter
# how often you decide to call it.
BAN_HAMMER_WILL_BE_CALLED_EVERY_SECONDS=60

# The maximum number of requests per BAN_HAMMER_RESOLUTION_WINDOW_SECONDS
# allowed by a single client.
BAN_HAMMER_MAX_REQUESTS_PER_WINDOW=10

# How far back into the past this script looks when checking a key or ip against
# BAN_HAMMER_MAX_REQUESTS_PER_WINDOW.
BAN_HAMMER_RESOLUTION_WINDOW_SECONDS=1

# The initial amount of time an offender is banned.
BAN_HAMMER_DEFAULT_BAN_TIME_MINUTES=1

# When an offender is banned twice in the same "period," they're banned for
# BAN_HAMMER_DEFAULT_BAN_TIME_MINUTES * BAN_HAMMER_RECIDIVISM_PUNISH_MULTIPLIER
# minutes instead of the default. This is also the length of the "period".
BAN_HAMMER_RECIDIVISM_PUNISH_MULTIPLIER=2

# The size (in bytes) of the root request-log collection will not be allowed to
# exceed this amount. Oldest entries are deleted first. Should be a string like
# 1kb, 1mb, 500b.
PRUNE_DATA_MAX_LOGS_BYTES=50mb

# The size (in bytes) of the root limited-log collection will not be allowed to
# exceed this amount. Oldest entries are deleted first. Should be a string like
# 1kb, 1mb, 500b.
PRUNE_DATA_MAX_BANNED_BYTES=10mb

# The size (in bytes) of the mail collection will not be allowed to exceed this
# amount. Oldest entries are deleted first. Should be a string like 1kb, 1mb,
# 500b.
PRUNE_DATA_MAX_MAIL_BYTES=10mb

# The size (in bytes) of the questions collection will not be allowed to exceed
# this amount. Oldest entries are deleted first. Should be a string like 1kb,
# 1mb, 500b.
PRUNE_DATA_MAX_QUESTIONS_BYTES=350mb

# The size (in bytes) of the users collection will not be allowed to exceed this
# amount. Oldest entries are deleted first. Should be a string like 1kb, 1mb,
# 500b.
PRUNE_DATA_MAX_USERS_BYTES=10mb

# The StackExchange client key used to ensure the initialize-data external script
# has a much higher request quota.
STACKAPPS_AUTH_KEY=

# A maximum of STACKAPPS_INTERVAL_PERIOD_MS requests will be sent to the
# StackExchange API every >=STACKAPPS_MAX_REQUESTS_PER_INTERVAL milliseconds.
#
# Must be a positive number such that no greater than 30 requests are sent per
# second or the StackExchange API will rate limit you.
STACKAPPS_INTERVAL_PERIOD_MS=1000

# A maximum of STACKAPPS_INTERVAL_PERIOD_MS requests will be sent to the
# StackExchange API every >=STACKAPPS_MAX_REQUESTS_PER_INTERVAL milliseconds.
#
# Must be a positive number such that no greater than 30 requests are sent per
# second or the StackExchange API will rate limit you.
STACKAPPS_MAX_REQUESTS_PER_INTERVAL=10

# The number of questions to render from the StackExchange API, which will be
# one less than the total number of questions inserted into the database.
STACKAPPS_TOTAL_API_GENERATED_QUESTIONS=100

# The number of answers the "collect all" questions will have.
STACKAPPS_COLLECTALL_QUESTION_ANSWERS=150

# The number of comments the "collect all" questions will have.
STACKAPPS_COLLECTALL_QUESTION_COMMENTS=250

# The number of comments the first answer of the "collect all" question will
# have.
STACKAPPS_COLLECTALL_FIRST_ANSWER_COMMENTS=150

# The maximum number of items that will be requested from the StackExchange API.
# Must be a positive number no greater than 100.
STACKAPPS_MAX_PAGE_SIZE=100

### TOOLS FRONTEND VARIABLES ###
# (optional unless using tools)
157 changes: 157 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
'use strict';

const debug = require('debug')(`${require('./package.json').name}:eslint-config`);
const restrictedGlobals = require('confusing-browser-globals');

module.exports = {
parser: '@typescript-eslint/parser',
plugins: ['jest', 'jest-dom', '@typescript-eslint', 'import'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:import/errors',
'plugin:import/warnings',
'plugin:import/typescript',
'plugin:@next/next/recommended'
],
parserOptions: {
ecmaVersion: 8,
sourceType: 'module',
ecmaFeatures: {
impliedStrict: true,
experimentalObjectRestSpread: true,
jsx: true
},
project: 'tsconfig.eslint.json'
},
env: {
es6: true,
node: true,
jest: true,
'jest/globals': true,
browser: true,
webextensions: true
},
rules: {
'no-console': 'warn',
'no-return-await': 'warn',
'no-await-in-loop': 'warn',
'import/no-unresolved': [
'error',
{
commonjs: true
}
],
'no-restricted-globals': ['warn'].concat(restrictedGlobals),
'no-extra-boolean-cast': 'off',
'no-empty': 'off',
'@typescript-eslint/camelcase': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/prefer-ts-expect-error': 'warn',
'@typescript-eslint/no-floating-promises': [
'error',
{ ignoreVoid: true, ignoreIIFE: true }
],
'@typescript-eslint/ban-ts-comment': [
'warn',
{
'ts-expect-error': 'allow-with-description',
minimumDescriptionLength: 6
}
],
'@typescript-eslint/no-unused-vars': [
'warn',
{
argsIgnorePattern: '^_+',
varsIgnorePattern: '^_+',
caughtErrorsIgnorePattern: '^ignored?\\d*$',
caughtErrors: 'all'
}
],
// ? Ever since v4, we will rely on TypeScript to catch these
'no-undef': 'off',
'@typescript-eslint/no-var-requires': 'off',
'no-unused-vars': 'off',
// ? Broken as of next 12.0.7
'@next/next/no-page-custom-font': 'off',
'@typescript-eslint/no-non-null-assertion': 'off'
},
overrides: [
{
files: ['*.test.*'],
extends: [
'plugin:jest/all',
'plugin:jest/style',
'plugin:jest-dom/recommended'
],
rules: {
'jest/lowercase': 'off',
'jest/consistent-test-it': 'off',
'jest/require-top-level-describe': 'off',
'jest/valid-describe': 'off',
'jest/no-hooks': 'off',
'jest/require-to-throw-message': 'off',
'jest/prefer-called-with': 'off',
'jest/prefer-spy-on': 'off',
'jest/no-if': 'off',
'jest/no-disabled-tests': 'warn',
'jest/no-commented-out-tests': 'warn',
'jest/require-hook': 'off',
'jest/no-alias-methods': 'off',
'jest/no-conditional-in-test': 'off',
'jest/no-conditional-expect': 'off',
'jest/max-expects': 'off',
'jest/prefer-mock-promise-shorthand': 'off'
}
}
],
settings: {
react: {
version: 'detect'
},
'import/extensions': ['.ts', '.tsx', '.js', '.jsx'],
// ? Switch parsers depending on which type of file we're looking at
'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx'],
'babel-eslint': ['.js', '.jsx']
},
'import/resolver': {
alias: {
map: [
// ! If changed, also update these aliases in tsconfig.json,
// ! webpack.config.js, next.config.ts, and jest.config.js
['universe', './src'],
['multiverse', './lib'],
['testverse', './test'],
['externals', './external-scripts'],
['types', './types'],
['package', './package.json'],
// ? These are used at various points (including at compile time by
// ? Next.js) to get mongo schema configuration and/or test dummy data.
// ! Must be defined if using @xunnamius/mongo-schema
['configverse/get-schema-config', './src/backend/db.ts'],
// ! Must be defined if using @xunnamius/mongo-test
['configverse/get-dummy-data', './test/db.ts']
],
extensions: ['.js', '.jsx', '.ts', '.tsx']
},
typescript: {}
},
'import/ignore': [
// ? Don't go complaining about anything that we don't own
'.*/node_modules/.*',
'.*/bin/.*'
]
},
ignorePatterns: ['coverage', 'dist', 'bin', 'build', '/next.config.js'],
globals: {
page: true,
browser: true,
context: true,
jestPuppeteer: true
}
};

debug('exports: %O', module.exports);
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# See https://docs.github.com/en/free-pro-team@latest/github/creating-cloning-and-archiving-repositories/about-code-owners

* @Xunnamius
Loading

0 comments on commit 764312e

Please sign in to comment.