Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 0 additions & 60 deletions .eslintrc.js

This file was deleted.

6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,9 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

# Claude
.claude

# History
.history
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ The [public API](https://semver.org/spec/v2.0.0.html#spec-item-1) of this librar
properties and constants belonging to the `src` folder.


---

## [0.2.0](https://github.com/crowdsecurity/nodejs-cs-bouncer/releases/tag/v0.2.0) - 2025-??-??

[_Compare with previous release_](https://github.com/crowdsecurity/nodejs-cs-bouncer/compare/v0.1.0...v0.2.0)

### Changed

- **Breaking Change**: Migrate from CommonJS to ESM

### Added

- Add optional `captchaAction` configuration to set the action attribute of the captcha form

---

## [0.1.0](https://github.com/crowdsecurity/nodejs-cs-bouncer/releases/tag/v0.1.0) - 2025-03-28
Expand Down
2 changes: 1 addition & 1 deletion docs/DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ npm install -g doctoc
Then, run it in the relevant folders:

```bash
doctoc docs/* --maxlevel 4 && doctoc examples/express-server/README.md --maxlevel 4
doctoc docs/* --maxlevel 4 && doctoc examples/express-server/README.md --maxlevel 4 && doctoc examples/nextjs/README.md --maxlevel 4
```

## Release process
Expand Down
25 changes: 13 additions & 12 deletions docs/USER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@
- [Features](#features)
- [Usage](#usage)
- [Configurations](#configurations)
- [Bouncer behavior](#bouncer-behavior)
- [Local API Connection](#local-api-connection)
- [Cache](#cache)
- [Captcha and Ban walls settings](#captcha-and-ban-walls-settings)
- [Bouncer behavior](#bouncer-behavior)
- [Local API Connection](#local-api-connection)
- [Cache](#cache)
- [Captcha and Ban walls settings](#captcha-and-ban-walls-settings)
- [Implement your own bouncer](#implement-your-own-bouncer)
- [Instantiation](#instantiation)
- [Apply a remediation](#apply-a-remediation)
- [Refresh decision cache](#refresh-decision-cache)
- [Push usage metrics](#push-usage-metrics)
- [Custom Captcha](#custom-captcha)
- [Custom Cache Adapter](#custom-cache-adapter)
- [Instantiation](#instantiation)
- [Apply a remediation](#apply-a-remediation)
- [Refresh decision cache](#refresh-decision-cache)
- [Push usage metrics](#push-usage-metrics)
- [Custom Captcha](#custom-captcha)
- [Custom Cache Adapter](#custom-cache-adapter)
- [Examples](#examples)
- [Basics](#basics)
- [Express server](#express-server)
- [Basics](#basics)
- [Express server](#express-server)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

Expand Down Expand Up @@ -161,6 +161,7 @@ Below is the list of available settings (see also `CrowdSecBouncerConfigurations
},
"captcha": {
"captchaImageTag": "Generated with svg-captcha-fixed",
"captchaAction": "Optional action of the captcha form (e.g. '/crowdsec-captcha'). Empty by default.",
"texts": {
"tabTitle": "CrowdSec | Captcha Wall",
"title": "Access Denied",
Expand Down
181 changes: 97 additions & 84 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,92 @@ import { FlatCompat } from '@eslint/eslintrc';
import js from '@eslint/js';
import typescriptEslint from '@typescript-eslint/eslint-plugin';
import tsParser from '@typescript-eslint/parser';
import _import from 'eslint-plugin-import';
import noRelativeImportPaths from 'eslint-plugin-no-relative-import-paths';
import eslintImport from 'eslint-plugin-import';
import preferArrowFunctions from 'eslint-plugin-prefer-arrow-functions';
import jestPlugin from 'eslint-plugin-jest';
import globals from 'globals';

import path from 'node:path';
import process from 'node:process';
import { fileURLToPath } from 'node:url';

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

const jestGlobals = jestPlugin.envs?.['jest/globals']?.globals ?? jestPlugin.environments?.['jest/globals']?.globals ?? {};

const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
});

const shared = {
plugins: {
'@typescript-eslint': fixupPluginRules(typescriptEslint),
'prefer-arrow-functions': preferArrowFunctions,
import: fixupPluginRules(eslintImport),
},

languageOptions: {
parser: tsParser,
ecmaVersion: 'latest',
sourceType: 'module',
globals: { ...globals.node },
parserOptions: {
project: path.join(__dirname, 'tsconfig.json'),
tsconfigRootDir: __dirname,
},
},

settings: {
'import/resolver': {
node: { extensions: ['.js', '.mjs', '.ts'] },
typescript: {
project: [path.join(__dirname, 'tsconfig.json'), path.join(__dirname, 'tsconfig.spec.json')],
alwaysTryTypes: true,
},
},
'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx'],
},
},

rules: {
'import/no-unresolved': 'error',
'import/extensions': ['error', 'ignorePackages', { ts: 'never', tsx: 'never', js: 'never', mjs: 'never' }],
'import/order': [
'error',
{
groups: ['external', ['builtin', 'index', 'sibling', 'parent', 'internal'], 'object', 'type'],
alphabetize: { order: 'asc', caseInsensitive: true },
'newlines-between': 'always',
},
],
'prefer-arrow-functions/prefer-arrow-functions': [
'error',
{
allowNamedFunctions: false,
classPropertiesAllowed: false,
disallowPrototype: false,
returnStyle: 'unchanged',
singleReturnOnly: false,
},
],
'prefer-template': 'error',
'no-nested-ternary': 'error',
'no-implicit-coercion': ['error', { boolean: true }],
'@typescript-eslint/naming-convention': [
'error',
{ selector: 'typeLike', format: ['PascalCase'] },
{ selector: 'enum', format: ['UPPER_CASE'] },
],
},
};

export default [
{
ignores: process.env.CI ? ['**/*.ejs', '**/dist/', '**/examples'] : ['**/*.ejs', '**/dist/'],
ignores: ['**/*.ejs', '**/dist/**', '**/examples/**', 'eslint.config.mjs', 'jest.config.mjs'],
},

...fixupConfigRules(
compat.extends(
'eslint:recommended',
Expand All @@ -32,97 +97,45 @@ export default [
'plugin:import/typescript',
),
),

{
plugins: {
'@typescript-eslint': fixupPluginRules(typescriptEslint),
'prefer-arrow-functions': preferArrowFunctions,
import: fixupPluginRules(_import),
'no-relative-import-paths': noRelativeImportPaths,
},
files: ['**/*.ts', '**/*.tsx'],
...shared,
},

{
files: ['tests/**/*.{ts,tsx}', '**/*.test.{ts,tsx}', '**/*.spec.{ts,tsx}'],
plugins: { ...shared.plugins, jest: jestPlugin },
languageOptions: {
globals: {
...globals.browser,
},

parser: tsParser,
ecmaVersion: 'latest',
sourceType: 'module',
...shared.languageOptions,
globals: { ...shared.languageOptions.globals, ...jestGlobals },
},

settings: {
'import/resolver': {
typescript: {
alwaysTryTypes: true,
project: './tsconfig.json',
},
},

'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx'],
},
},

settings: shared.settings,
rules: {
'import/no-unresolved': 'error',

'import/order': [
'error',
{
groups: ['external', ['builtin', 'index', 'sibling', 'parent', 'internal'], 'object', 'type'],
'newlines-between': 'always',
alphabetize: {
order: 'asc',
caseInsensitive: true,
},
},
],

'no-relative-import-paths/no-relative-import-paths': [
'error',
{
allowSameFolder: false,
},
],

'prefer-arrow-functions/prefer-arrow-functions': [
'error',
{
allowNamedFunctions: false,
classPropertiesAllowed: false,
disallowPrototype: false,
returnStyle: 'unchanged',
singleReturnOnly: false,
},
],

'prefer-template': 'error',
'no-nested-ternary': 'error',
'no-implicit-coercion': ['error', { boolean: true }],

'@typescript-eslint/naming-convention': [
'error',
{
selector: 'typeLike',
format: ['PascalCase'],
},
{
selector: 'enum',
format: ['UPPER_CASE'],
},
],
...shared.rules,
'import/no-extraneous-dependencies': ['error', { devDependencies: true }],
},
},

{
files: ['**/.eslintrc.js'],
files: ['*.config.{ts,js,mjs,cjs}'],
languageOptions: {
...shared.languageOptions,
parserOptions: { project: null },
},
rules: { 'import/no-unresolved': 'off' },
},

{
files: ['jest-ejs-transform.cjs'],
languageOptions: {
sourceType: 'script',
globals: {
...globals.node,
module: 'readonly',
exports: 'readonly',
require: 'readonly',
},

ecmaVersion: 5,
sourceType: 'commonjs',
},
rules: { 'no-undef': 'off' },
},
];
3 changes: 1 addition & 2 deletions examples/basics/fetch-decisions-stream.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import CrowdSecBouncer from 'src/lib/bouncer';
import { CrowdSecBouncerConfigurations } from 'src/lib/bouncer/types';
import { CrowdSecBouncer, CrowdSecBouncerConfigurations } from '../../src';

/**
* Example usage of fetching decisions stream.
Expand Down
5 changes: 2 additions & 3 deletions examples/basics/get-ip-remediation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import CrowdSecBouncer from 'src/lib/bouncer';
import { CrowdSecBouncerConfigurations } from 'src/lib/bouncer/types';
import { BOUNCER_KEYS } from 'src/lib/constants';
import { CrowdSecBouncer, CrowdSecBouncerConfigurations } from '../../src';
import { BOUNCER_KEYS } from '../../src/lib/constants';

/**
* Example of basic usage of the CrowdSec Bouncer.
Expand Down
2 changes: 1 addition & 1 deletion examples/express-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const { origin, remediation } = remediationData;

- Depending on the value of the remediation, we apply it:

- let the process continue with `next()`if there is no remediation (bypass)
- let the process continue with `next()` if there is no remediation (bypass)

- block the user with a ban or captcha wall remediation:

Expand Down
Loading
Loading