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
15 changes: 0 additions & 15 deletions .eslintrc.yaml

This file was deleted.

22 changes: 11 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
env:
CI: true
NODE_ENV: test
NODE_VER: 22

jobs:
lint:
Expand All @@ -21,7 +22,7 @@ jobs:
run: sudo /etc/init.d/mysql start
- uses: actions/setup-node@v4
with:
node-version: 20
node-version: ${{ env.NODE_VER }}
- uses: actions/checkout@v4
- run: npm install
- name: Initialize MySQL
Expand All @@ -43,17 +44,19 @@ jobs:
- id: get
uses: msimerson/node-lts-versions@v1
outputs:
lts: ${{ steps.get.outputs.lts }}
active: ${{ steps.get.outputs.active }}
maintenance: ${{ steps.get.outputs.maintenance }}
lts: ${{ steps.get.outputs.lts }}
current: ${{ steps.get.outputs.current }}
min: ${{ steps.get.outputs.min }}

test:
needs: [ get-lts ]
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
# node-version: ${{ fromJson(needs.get-lts.outputs.active) }}
node-version: [ 20 ]
node-version: ${{ fromJson(needs.get-lts.outputs.active) }}
fail-fast: false
steps:
- run: sudo /etc/init.d/mysql start
Expand All @@ -70,15 +73,13 @@ jobs:
runs-on: macos-latest
strategy:
matrix:
# node-version: ${{ fromJson(needs.get-lts.outputs.active) }}
node-version: [ 20 ]
node-version: ${{ fromJson(needs.get-lts.outputs.active) }}
fail-fast: false
steps:
- name: Install & Start MySQL
run: |
brew install mysql
brew tap homebrew/services
brew services start mysql
brew install mysql@8.4
brew services start mysql@8.4
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
name: Node ${{ matrix.node-version }} on ${{ matrix.os }}
Expand All @@ -94,8 +95,7 @@ jobs:
runs-on: windows-latest
strategy:
matrix:
node-version: [ 20 ]
# node-version: ${{ fromJson(needs.get-lts.outputs.active) }}
node-version: ${{ fromJson(needs.get-lts.outputs.active) }}
experimental: [true]
fail-fast: false
steps:
Expand Down
2 changes: 1 addition & 1 deletion .release
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

### Unreleased

### [3.0.0-alpha.6] - 2025-04-08

- dep(eslint): upgraded to v9
- dep(\*): bump versions to latest
- feat(conf.d/http): added tls
- feat(session): added JWT for session auth
- feat(zone): removed location
- feat(routes/zone_record): added, fixes #17
- change(routes/users): result is always array
- change(routes/ns): GET id is optional, result is always array
- change(routes/zone): GET id is optional, result is always array

### [3.0.0-alpha.5] - 2024-03-06

Expand Down Expand Up @@ -31,3 +42,4 @@
[3.0.0-alpha.3]: https://github.com/NicTool/api/releases/tag/3.0.0-alpha.3
[3.0.0-alpha.4]: https://github.com/NicTool/api/releases/tag/3.0.0-alpha.4
[3.0.0-alpha.5]: https://github.com/NicTool/api/releases/tag/3.0.0-alpha.5
[3.0.0-alpha.6]: https://github.com/NicTool/api/releases/tag/3.0.0-alpha.6
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Running one of these commands:

`npm run start (production)`

or
or

`npm run develop (development)`

Expand Down
35 changes: 33 additions & 2 deletions conf.d/http.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
default:
host: localhost
port: 3000
tls:
key: null
cert: null
jwt:
key: 'af1b926a5e21f535c4f5b6c42941c4cf'
cookie:
# https://hapi.dev/module/cookie/api/?v=12.0.1
name: sid-nictool
Expand All @@ -11,7 +16,7 @@ default:
clearInvalid: true
isSameSite: Strict
isSecure: true
isHttpOnly: true
isHttpOnly: false
keepAlive: false
# redirectTo:
group: NicTool
Expand All @@ -28,6 +33,32 @@ test:
password: ^NicTool.Is,The#Best_Dns-Manager$

development:
host: box-under-my-desk.example.com
tls:
key: |
-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDwBx1Qt9309i89
O9Y8bhHO9BqyWWzd0hXI1o3d8Zn4aT2lhwmeeu2oSQsczvny0cJSs6HYe6asI6XZ
<snip>
Ane1BnOJ6/E+7Clo463N++OS
-----END PRIVATE KEY-----

cert: |
-----BEGIN CERTIFICATE-----
MIID9DCCAtygAwIBAgIUF+ziLgjIA3qCf95DmVskHqSNvLUwDQYJKoZIhvcNAQEL
BQAwfDELMAkGA1UEBhMCVVMxEzARBgNVBAgMCldhc2hpbmd0b24xGjAYBgNVBAoM
<snip>
juZxYqQoPYBpk+eG/sudGGFKKGow1RbGbbNUrqATYxJCqPrN0mZuNkAgATbQtBjS
vyvASCDueS0=
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
MIID2TCCAsGgAwIBAgIUF+ziLgjIA3qCf95DmVskHqSNvLEwDQYJKoZIhvcNAQEL
BQAwfDELMAkGA1UEBhMCVVMxEzARBgNVBAgMCldhc2hpbmd0b24xGjAYBgNVBAoM
<snip>
iMt4AE3zfKgj/OLyAeseUlqukbnBQYlTiMUuPLTTp6d7uBi8/VuXBTrZ9nafPvSZ
TqccpFMgxCeImsJCgO5hBJYUTELDNEmJS5Vgy3Y=
-----END CERTIFICATE-----

cookie:
isSecure: false
# isSecure: false
password: ^NicTool.Is,The#Best_Dns-Manager$
39 changes: 39 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import globals from "globals";
import babelParser from "@babel/eslint-parser";
import path from "node:path";
import { fileURLToPath } from "node:url";
import js from "@eslint/js";
import { FlatCompat } from "@eslint/eslintrc";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all
});

export default [...compat.extends("eslint:recommended"), {
languageOptions: {
globals: {
...globals.node,
},

parser: babelParser,
ecmaVersion: "latest",
sourceType: "module",

parserOptions: {
babelOptions: {
configFile: false,
plugins: ["@babel/plugin-syntax-import-attributes"],
},

requireConfigFile: false,
},
},

rules: {
"no-unused-vars": "warn"
},
}];
1 change: 1 addition & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Config {

const str = fsSync.readFileSync(`./conf.d/${name}.yml`, 'utf8')
const cfg = YAML.parse(str)
if (this.debug) console.debug(cfg)

this.cfg[cacheKey] = applyDefaults(cfg[env ?? this.env], cfg.default)
return this.cfg[cacheKey]
Expand Down
9 changes: 8 additions & 1 deletion lib/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,21 @@ const httpCfg = {
port: 3000,
cookie: {
clearInvalid: true,
isHttpOnly: true,
isHttpOnly: false,
isSameSite: 'Strict',
isSecure: false,
name: 'sid-nictool',
password: '^NicTool.Is,The#Best_Dns-Manager$',
path: '/',
ttl: 3600000,
},
jwt: {
key: 'af1b926a5e21f535c4f5b6c42941c4cf',
},
tls: {
cert: null,
key: null,
},
keepAlive: false,
group: 'NicTool',
}
3 changes: 3 additions & 0 deletions lib/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,12 @@ class Session {

if (args.last_access) {
const p = await this.get({ id: args.id })
if (!p) return false

// if less than 60 seconds old, do nothing
const now = parseInt(Date.now() / 1000, 10)
const oneMinuteAgo = now - 60

// update only when +1 minute old (save DB writes)
if (p.last_access > oneMinuteAgo) return true
args.last_access = now
Expand Down
1 change: 0 additions & 1 deletion lib/test/zone.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@
"expire": 3,
"minimum": 4,
"ttl": 3600,
"location": "",
"last_publish": null
}
1 change: 0 additions & 1 deletion lib/zone.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class Zone {
, expire
, minimum
, ttl
, location
, last_modified
, last_publish
, deleted
Expand Down
12 changes: 6 additions & 6 deletions lib/zone_record.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ function unApplyMap(obj, map) {
const [algo, flags, iters, salt, bitmaps, next] = obj.address
.slice(1, -1)
.split("','")
obj['hash algorithm'] = /^\d+$/.test(algo) ? parseInt(algo) : algo ?? ''
obj.flags = /^\d+$/.test(flags) ? parseInt(flags) : flags ?? ''
obj.iterations = /^\d+$/.test(iters) ? parseInt(iters) : iters ?? ''
obj['hash algorithm'] = /^\d+$/.test(algo) ? parseInt(algo) : (algo ?? '')
obj.flags = /^\d+$/.test(flags) ? parseInt(flags) : (flags ?? '')
obj.iterations = /^\d+$/.test(iters) ? parseInt(iters) : (iters ?? '')
obj.salt = salt
obj['type bit maps'] = bitmaps
obj['next hashed owner name'] = next
Expand All @@ -176,9 +176,9 @@ function unApplyMap(obj, map) {
}
if (obj.type === 'NSEC3PARAM') {
const [algo, flags, iters, salt] = obj.address.slice(1, -1).split("','")
obj['hash algorithm'] = /^\d+$/.test(algo) ? parseInt(algo) : algo ?? ''
obj.flags = /^\d+$/.test(flags) ? parseInt(flags) : flags ?? ''
obj.iterations = /^\d+$/.test(iters) ? parseInt(iters) : iters ?? ''
obj['hash algorithm'] = /^\d+$/.test(algo) ? parseInt(algo) : (algo ?? '')
obj.flags = /^\d+$/.test(flags) ? parseInt(flags) : (flags ?? '')
obj.iterations = /^\d+$/.test(iters) ? parseInt(iters) : (iters ?? '')
obj.salt = salt
delete obj.address
delete map.address
Expand Down
30 changes: 16 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nictool/api",
"version": "3.0.0-alpha.5",
"version": "3.0.0-alpha.6",
"description": "NicTool API",
"main": "index.js",
"type": "module",
Expand All @@ -11,9 +11,10 @@
"prettier": "npx prettier *.js conf.d lib routes html --check",
"prettier:fix": "npx prettier *.js conf.d lib routes html --write",
"start": "NODE_ENV=production node ./server",
"develop": "NODE_ENV=development node ./server",
"develop": "NODE_ENV=development node --watch server.js ./server",
"test": "./test.sh",
"versions": "npx dependency-version-checker check",
"versions:fix": "npx dependency-version-checker update",
"watch": "./test.sh watch"
},
"repository": {
Expand All @@ -33,21 +34,22 @@
},
"homepage": "https://github.com/NicTool/api#readme",
"devDependencies": {
"@babel/eslint-parser": "^7.23.10",
"@babel/plugin-syntax-import-attributes": "^7.23.3",
"eslint": "^8.57.0"
"@babel/eslint-parser": "^7.27.0",
"@babel/plugin-syntax-import-attributes": "^7.26.0",
"eslint": "^9.24.0"
},
"dependencies": {
"@hapi/cookie": "^12.0.1",
"@hapi/hapi": "^21.3.3",
"@hapi/hoek": "^11.0.4",
"@hapi/hapi": "^21.4.0",
"@hapi/hoek": "^11.0.7",
"@hapi/inert": "^7.1.0",
"@hapi/jwt": "^3.2.0",
"@hapi/vision": "^7.0.3",
"@nictool/dns-resource-record": "^1.2.1",
"@nictool/validate": "^0.8.0",
"hapi-swagger": "^17.2.1",
"mysql2": "^3.9.2",
"qs": "^6.11.2",
"yaml": "^2.4.0"
"@nictool/dns-resource-record": "^1.2.2",
"@nictool/validate": "^0.8.2",
"hapi-swagger": "^17.3.2",
"mysql2": "^3.14.0",
"qs": "^6.14.0",
"yaml": "^2.7.1"
}
}
}
Loading