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
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ jobs:
- run: npm test

test-win:
# if: false
needs: [ get-lts ]
runs-on: windows-latest
strategy:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,4 @@ dist
.pnp.*

package-lock.json
conf.d/*.pem
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.release/
2 changes: 1 addition & 1 deletion .release
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).

### Unreleased

### [3.0.0-alpha.10] - 2026-03-25

- config: replace .yaml with .toml
- zone_record can be empty, default 0
- feat(zone records): create and delete

### [3.0.0-alpha.9] - 2026-03-15

- feat(zone): use DataTable for list, added search/limit options
Expand Down Expand Up @@ -64,3 +70,4 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).
[3.0.0-alpha.7]: https://github.com/NicTool/api/releases/tag/v3.0.0-alpha.7
[3.0.0-alpha.8]: https://github.com/NicTool/api/releases/tag/v3.0.0-alpha.8
[3.0.0-alpha.9]: https://github.com/NicTool/api/releases/tag/v3.0.0-alpha.9
[3.0.0-alpha.10]: https://github.com/NicTool/api/releases/tag/v3.0.0-alpha.10
2 changes: 1 addition & 1 deletion CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This handcrafted artisanal software is brought to you by:

| <img height="80" src="https://avatars.githubusercontent.com/u/261635?v=4"><br><a href="https://github.com/msimerson">msimerson</a> (<a href="https://github.com/NicTool/api/commits?author=msimerson">16</a>)|
| <img height="80" src="https://avatars.githubusercontent.com/u/261635?v=4"><br><a href="https://github.com/msimerson">msimerson</a> (<a href="https://github.com/NicTool/api/commits?author=msimerson">18</a>)|
| :---: |

<sub>this file is generated by [.release](https://github.com/msimerson/.release).
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

# NicTool API v3

A RESTful JSON web service that exposes DNS management functions to users.

## Install

Expand Down
18 changes: 18 additions & 0 deletions conf.d/http.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
host = "localhost"
port = 3000
keepAlive = false
group = "NicTool"

[jwt]
key = "af1b926a5e21f535c4f5b6c42941c4cf"

[cookie]
# https://hapi.dev/module/cookie/api/?v=12.0.1
name = "sid-nictool"
ttl = 3600000 # 1 hour
path = "/"
clearInvalid = true
isSameSite = "Strict"
isSecure = true
isHttpOnly = false
password = "" # hint: openssl rand -hex 16
64 changes: 0 additions & 64 deletions conf.d/http.yml

This file was deleted.

9 changes: 9 additions & 0 deletions conf.d/mysql.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
host = "127.0.0.1"
port = 3306
socketPath = ""
user = "nictool"
database = "nictool"
timezone = "+00:00"
dateStrings = ["DATETIME", "TIMESTAMP"]
decimalNumbers = true
password = ""
30 changes: 0 additions & 30 deletions conf.d/mysql.yml

This file was deleted.

52 changes: 18 additions & 34 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,39 +1,23 @@
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";
import globals from 'globals'
import js from '@eslint/js'
import prettier from 'eslint-config-prettier'

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"), {
export default [
{
ignores: ['**/package-lock.json', 'node_modules/**', '.release/**'],
},
js.configs.recommended,
prettier,
{
languageOptions: {
globals: {
...globals.node,
},

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

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

requireConfigFile: false,
},
ecmaVersion: 'latest',
sourceType: 'module',
globals: {
...globals.node
},
},

rules: {
"no-unused-vars": "warn"
'no-unused-vars': 'warn',
},
}];
},
]
101 changes: 64 additions & 37 deletions lib/config.js
Original file line number Diff line number Diff line change
@@ -1,63 +1,90 @@
import fs from 'node:fs/promises'
import fsSync from 'node:fs'
import path from 'node:path'

import YAML from 'yaml'

import { setEnv } from './util.js'
setEnv()
import { parse } from 'smol-toml'

class Config {
constructor(opts = {}) {
constructor() {
this.cfg = {}
this.getEnv(opts)
}

getEnv(opts = {}) {
this.env = process.env.NODE_ENV ?? opts.env ?? ''
this.debug = Boolean(process.env.NODE_DEBUG)
if (this.debug) console.log(`debug: true, env: ${this.env}`)
}

async get(name, env) {
this.getEnv()
async get(name) {
this.debug = Boolean(process.env.NODE_DEBUG)

const cacheKey = [name, env ?? this.env].join(':')
if (this.cfg?.[cacheKey]) return this.cfg[cacheKey] // cached
if (this.cfg[name]) return this.cfg[name]

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

this.cfg[cacheKey] = applyDefaults(cfg[env ?? this.env], cfg.default)
return this.cfg[cacheKey]
if (name === 'http') {
const tls = await loadPEM('./conf.d')
if (tls) cfg.tls = tls
}

this.cfg[name] = cfg
return cfg
}

getSync(name, env) {
this.getEnv()
getSync(name) {
this.debug = Boolean(process.env.NODE_DEBUG)

const cacheKey = [name, env ?? this.env].join(':')
if (this.cfg?.[cacheKey]) return this.cfg[cacheKey] // cached
if (this.cfg[name]) return this.cfg[name]

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

this.cfg[cacheKey] = applyDefaults(cfg[env ?? this.env], cfg.default)
return this.cfg[cacheKey]
if (name === 'http') {
const tls = loadPEMSync('./conf.d')
if (tls) cfg.tls = tls
}

this.cfg[name] = cfg
return cfg
}
}

function applyDefaults(cfg = {}, defaults = {}) {
for (const d in defaults) {
/* c8 ignore next */
if (d === '__proto__' || d === 'constructor') continue
if ([undefined, null].includes(cfg[d])) {
cfg[d] = defaults[d]
} else if (typeof cfg[d] === 'object' && typeof defaults[d] === 'object') {
cfg[d] = applyDefaults(cfg[d], defaults[d])
}
async function loadPEM(dir) {
let entries
try {
entries = await fs.readdir(dir)
} catch {
return null
}
const pemFile = entries.find((f) => f.endsWith('.pem'))
if (!pemFile) return null

const content = await fs.readFile(path.join(dir, pemFile), 'utf8')
return parsePEMBlocks(content)
}

function loadPEMSync(dir) {
let entries
try {
entries = fsSync.readdirSync(dir)
} catch {
return null
}
const pemFile = entries.find((f) => f.endsWith('.pem'))
if (!pemFile) return null

const content = fsSync.readFileSync(path.join(dir, pemFile), 'utf8')
return parsePEMBlocks(content)
}

function parsePEMBlocks(content) {
const keyMatch = content.match(/-----BEGIN (?:[A-Z]+ )?PRIVATE KEY-----[\s\S]*?-----END (?:[A-Z]+ )?PRIVATE KEY-----/)
const certMatches = [...content.matchAll(/-----BEGIN CERTIFICATE-----[\s\S]*?-----END CERTIFICATE-----/g)]

if (!keyMatch && !certMatches.length) return null

return {
key: keyMatch ? keyMatch[0] + '\n' : null,
cert: certMatches.length ? certMatches.map((m) => m[0]).join('\n') + '\n' : null,
}
return cfg
}

export default new Config()
Loading
Loading