Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support cjs and esm both by tshy #101

Merged
merged 11 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 0 additions & 3 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
test/fixtures
test/benchmark
coverage
node_modules
lib/plugins/**/app/proxy
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": [
"eslint-config-egg",
"eslint-config-egg/typescript",
"eslint-config-egg/lib/rules/enforce-node-prefix"
]
}
3 changes: 1 addition & 2 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ jobs:
name: Node.js
uses: node-modules/github-actions/.github/workflows/node-test.yml@master
with:
os: 'ubuntu-latest, macos-latest, windows-latest'
version: '14.20.0, 14, 16, 18, 20, 22'
version: '18.19.0, 20, 22'
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
18 changes: 9 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
node_modules
coverage
test/**/logs
_book
.DS_Store
logs/
npm-debug.log
run/
.vscode
node_modules/
coverage/
test/fixtures/**/run
.DS_Store
.tshy*
.eslintcache
dist
package-lock.json
.travis.yml
.idea
.package-lock.json
7 changes: 0 additions & 7 deletions agent.js

This file was deleted.

23 changes: 0 additions & 23 deletions app.js

This file was deleted.

5 changes: 0 additions & 5 deletions app/extend/agent.js

This file was deleted.

34 changes: 0 additions & 34 deletions app/extend/application.js

This file was deleted.

7 changes: 0 additions & 7 deletions config/config.local.js

This file was deleted.

12 changes: 0 additions & 12 deletions index.js

This file was deleted.

33 changes: 0 additions & 33 deletions lib/extend/safe_curl.js

This file was deleted.

106 changes: 72 additions & 34 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,73 +1,111 @@
{
"name": "egg-security",
"name": "@eggjs/security",
"version": "3.7.0",
"engines": {
"node": ">=14.20.0"
"publishConfig": {
"access": "public"
},
"description": "security plugin in egg framework",
"eggPlugin": {
"name": "security",
"optionalDependencies": [
"session"
]
],
"exports": {
"import": "./dist/esm",
"require": "./dist/commonjs",
"typescript": "./src"
}
},
"keywords": [
"egg",
"eggPlugin",
"egg-plugin",
"security"
],
"repository": {
"type": "git",
"url": "git+https://github.com/eggjs/security.git"
},
"bugs": {
"url": "https://github.com/eggjs/egg/issues"
},
"homepage": "https://github.com/eggjs/security#readme",
"author": "jtyjty99999",
"license": "MIT",
"engines": {
"node": ">= 18.19.0"
},
"dependencies": {
"@eggjs/ip": "^2.0.2",
"@eggjs/core": "^6.2.13",
"@eggjs/ip": "^2.1.0",
"csrf": "^3.0.6",
"delegates": "^1.0.0",
"egg-path-matching": "^1.0.0",
"escape-html": "^1.0.3",
"extend": "^3.0.1",
"extend2": "^4.0.0",
"koa-compose": "^4.1.0",
"matcher": "^4.0.0",
"methods": "^1.1.2",
"nanoid": "^3.3.6",
"platform": "^1.3.4",
"nanoid": "^3.3.8",
"statuses": "^2.0.1",
"type-is": "^1.6.15",
"xss": "^1.0.3"
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.17.1",
"@eggjs/bin": "7",
"@eggjs/mock": "^6.0.5",
"@eggjs/tsconfig": "1",
"@types/koa-compose": "^3.2.8",
"@types/mocha": "10",
"@types/node": "22",
"beautify-benchmark": "^0.2.4",
"benchmark": "^2.1.4",
"egg": "^3.26.0",
"egg-bin": "^6.4.0",
"egg-mock": "^5.10.6",
"egg": "^4.0.1",
"egg-view-nunjucks": "^2.3.0",
"eslint": "^8.40.0",
"eslint-config-egg": "^12.2.1",
"eslint": "8",
"eslint-config-egg": "14",
"rimraf": "6",
"spy": "^1.0.0",
"supertest": "^6.3.3"
"supertest": "^6.3.3",
"tshy": "3",
"tshy-after": "1",
"typescript": "5"
},
"scripts": {
"lint": "eslint .",
"test": "npm run lint -- --fix && npm run test-local",
"test-local": "egg-bin test",
"cov": "egg-bin cov",
"ci": "npm run lint && npm run cov"
"lint": "eslint --cache src test --ext .ts",
"pretest": "npm run clean && npm run lint -- --fix",
"test": "egg-bin test",
"preci": "npm run clean && npm run lint",
"ci": "egg-bin cov",
"postci": "npm run prepublishOnly && npm run clean",
"clean": "rimraf dist",
"prepublishOnly": "tshy && tshy-after && attw --pack"
},
"repository": {
"type": "git",
"url": "git+https://github.com/eggjs/security.git"
"type": "module",
"tshy": {
"exports": {
".": "./src/index.ts",
"./package.json": "./package.json"
}
},
"exports": {
".": {
"import": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"types": "./dist/commonjs/index.d.ts",
"default": "./dist/commonjs/index.js"
}
},
"./package.json": "./package.json"
},
"files": [
"agent.js",
"app",
"lib",
"config",
"app.js",
"index.js"
"dist",
"src"
],
"bugs": {
"url": "https://github.com/eggjs/egg/issues"
},
"homepage": "https://github.com/eggjs/security#readme",
"author": "jtyjty99999",
"license": "MIT"
"types": "./dist/commonjs/index.d.ts",
"main": "./dist/commonjs/index.js"
}
14 changes: 14 additions & 0 deletions src/agent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { ILifecycleBoot, EggCore } from '@eggjs/core';
import { preprocessConfig } from './lib/utils.js';

export class AgentBoot implements ILifecycleBoot {
private readonly agent;

constructor(agent: EggCore) {
this.agent = agent;
}

async configWillLoad() {
preprocessConfig(this.agent.config.security);
}
}
29 changes: 29 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import assert from 'node:assert';
import type { ILifecycleBoot, EggCore } from '@eggjs/core';
import { preprocessConfig } from './lib/utils.js';

export class AgentBoot implements ILifecycleBoot {
private readonly app;

constructor(app: EggCore) {
this.app = app;
}

async configWillLoad() {
const app = this.app;
app.config.coreMiddleware.push('securities');

if (app.config.security.csrf && app.config.security.csrf.enable) {
const { ignoreJSON, type } = app.config.security.csrf;
if (ignoreJSON) {
app.deprecate('[@eggjs/security/app] `app.config.security.csrf.ignoreJSON` is not safe now, please disable it.');
}

const legalTypes = [ 'all', 'referer', 'ctoken', 'any' ];
assert(legalTypes.includes(type),
'[@eggjs/security/ap] `config.security.csrf.type` must be one of ' + legalTypes.join(', '));
}

preprocessConfig(app.config.security);
}
}
6 changes: 6 additions & 0 deletions src/app/extend/agent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { EggCore } from '@eggjs/core';
import { safeCurlForApplication } from '../../lib/extend/safe_curl.js';

export default class SecurityAgent extends EggCore {
safeCurl = safeCurlForApplication;
}
Loading
Loading