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
24 changes: 11 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
name: CI

on:
push:
paths-ignore:
- '*.md'
pull_request:
types: [opened, synchronize, reopened]

env:
CI: true
Expand All @@ -23,7 +21,7 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VER }}
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- run: npm install
- name: Initialize MySQL
run: sh sql/init-mysql.sh
Expand Down Expand Up @@ -56,12 +54,12 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
node-version: ${{ fromJson(needs.get-lts.outputs.active) }}
node-version: ${{ fromJson(needs.get-lts.outputs.lts) }}
fail-fast: false
steps:
- run: sudo /etc/init.d/mysql start
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: ${{ matrix.node-version }}
- run: sh sql/init-mysql.sh
Expand All @@ -73,15 +71,15 @@ jobs:
runs-on: macos-latest
strategy:
matrix:
node-version: ${{ fromJson(needs.get-lts.outputs.active) }}
node-version: ${{ fromJson(needs.get-lts.outputs.lts) }}
fail-fast: false
steps:
- name: Install & Start MySQL
run: |
brew install mysql@8.4
brew services start mysql@8.4
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
name: Node ${{ matrix.node-version }} on ${{ matrix.os }}
with:
node-version: ${{ matrix.node-version }}
Expand All @@ -95,15 +93,15 @@ jobs:
runs-on: windows-latest
strategy:
matrix:
node-version: ${{ fromJson(needs.get-lts.outputs.active) }}
node-version: ${{ fromJson(needs.get-lts.outputs.lts) }}
experimental: [true]
fail-fast: false
steps:
- name: Install MySQL
run: |
choco install mysql
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
name: Node ${{ matrix.node-version }}
with:
node-version: ${{ matrix.node-version }}
Expand Down
29 changes: 9 additions & 20 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
name: publish

on:
push:
branches:
- main
paths:
- package.json
release:
types: [published]
release:
types: [published]

env:
CI: true
node-version: 20
node-version: 22

jobs:
build:
runs-on: ubuntu-latest
steps:
- run: sudo /etc/init.d/mysql start
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: ${{ env.node-version }}
- run: sh sql/init-mysql.sh
Expand All @@ -30,25 +25,19 @@ jobs:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/setup-node@v4
- uses: actions/setup-node@v6
name: Node ${{ env.node-version }}
with:
node-version: ${{ env.node-version }}
registry-url: https://registry.npmjs.org/

- uses: actions/checkout@v4
- uses: actions/checkout@v6
with:
fetch-depth: 0
# fetch-depth 0 needed by GitHub Release

- name: publish to NPM
run: npm publish --access=public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}

- name: GitHub Release
uses: justincy/github-action-npm-release@2.0.1
id: release

publish-gpr:
needs: build
Expand All @@ -57,8 +46,8 @@ jobs:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: ${{ env.node-version }}
registry-url: https://npm.pkg.github.com/
Expand Down
3 changes: 0 additions & 3 deletions .prettierrc.yml

This file was deleted.

18 changes: 15 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
# Changelog

The format is based on [Keep a Changelog](https://keepachangelog.com/).

# CHANGES

### Unreleased

### [3.0.0-alpha.7] - 2026-03-13

- fixes

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

- dep(eslint): upgraded to v9
Expand Down Expand Up @@ -39,7 +47,11 @@
- lib/user.get: convert booleans


[3.0.0-alpha.0]: https://github.com/NicTool/api/releases/tag/3.0.0-alpha.0
[3.0.0-alpha.1]: https://github.com/NicTool/api/releases/tag/3.0.0-alpha.1
[3.0.0-alpha.2]: https://github.com/NicTool/api/releases/tag/3.0.0-alpha.2
[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
[3.0.0-alpha.4]: https://github.com/NicTool/api/releases/tag/v3.0.0-alpha.4
[3.0.0-alpha.5]: https://github.com/NicTool/api/releases/tag/v3.0.0-alpha.5
[3.0.0-alpha.6]: https://github.com/NicTool/api/releases/tag/v3.0.0-alpha.6
[3.0.0-alpha.7]: https://github.com/NicTool/api/releases/tag/v3.0.0-alpha.7
9 changes: 9 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Contributors

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">14</a>)|
| :---: |

<sub>this file is generated by [.release](https://github.com/msimerson/.release).
Contribute to this project to get your GitHub profile included here.</sub>
2 changes: 1 addition & 1 deletion lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Config {
this.getEnv(opts)
}

async 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}`)
Expand Down
7 changes: 2 additions & 5 deletions lib/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,12 @@ describe('config', () => {

it(`detects NODE_DEBUG env`, async () => {
process.env.NODE_DEBUG = 1
let cfg = await Config.get('mysql', 'test')
await Config.get('mysql', 'test')
assert.equal(Config.debug, true)

process.env.NODE_DEBUG = ''
cfg = await Config.get('mysql', 'test')
await Config.get('mysql', 'test')
assert.equal(Config.debug, false)

cfg = await Config.get('mysql', 'test')
assert.equal(cfg.user, 'root')
})
})
})
Expand Down
14 changes: 3 additions & 11 deletions lib/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ class Group {
if (g.length === 1) return g[0].id
}

return await Mysql.execute(
...Mysql.insert(`nt_group`, mapToDbColumn(args, groupDbMap)),
)
return await Mysql.execute(...Mysql.insert(`nt_group`, mapToDbColumn(args, groupDbMap)))
}

async get(args) {
Expand Down Expand Up @@ -48,11 +46,7 @@ class Group {
const id = args.id
delete args.id
const r = await Mysql.execute(
...Mysql.update(
`nt_group`,
`nt_group_id=${id}`,
mapToDbColumn(args, groupDbMap),
),
...Mysql.update(`nt_group`, `nt_group_id=${id}`, mapToDbColumn(args, groupDbMap)),
)
return r.changedRows === 1
}
Expand All @@ -67,9 +61,7 @@ class Group {
}

async destroy(args) {
const r = await Mysql.execute(
...Mysql.delete(`nt_group`, { nt_group_id: args.id }),
)
const r = await Mysql.execute(...Mysql.delete(`nt_group`, { nt_group_id: args.id }))
return r.affectedRows === 1
}
}
Expand Down
8 changes: 2 additions & 6 deletions lib/mysql.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ class Mysql {
if (_debug) console.log(cfg)

this.dbh = await mysql.createConnection(cfg)
if (_debug)
console.log(`MySQL connection id ${this.dbh.connection.connectionId}`)
if (_debug) console.log(`MySQL connection id ${this.dbh.connection.connectionId}`)
return this.dbh
}

Expand Down Expand Up @@ -54,10 +53,7 @@ class Mysql {
}

update(table, where, params = {}) {
return [
`UPDATE ${table} SET ${Object.keys(params).join('=?,')}=? WHERE ${where}`,
Object.values(params),
]
return [`UPDATE ${table} SET ${Object.keys(params).join('=?,')}=? WHERE ${where}`, Object.values(params)]
}

delete(table, params) {
Expand Down
15 changes: 3 additions & 12 deletions lib/mysql.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,32 +34,23 @@ describe('mysql', () => {
first_name: 'uNite',
last_name: 'Test',
})
assert.deepEqual(r, [
`INSERT INTO nt_user (first_name,last_name) VALUES(?,?)`,
['uNite', 'Test'],
])
assert.deepEqual(r, [`INSERT INTO nt_user (first_name,last_name) VALUES(?,?)`, ['uNite', 'Test']])
})

describe('update', () => {
it('formats with one value', () => {
const r = Mysql.update(`nt_user`, `nt_user_id=4096`, {
first_name: 'uNite',
})
assert.deepEqual(r, [
`UPDATE nt_user SET first_name=? WHERE nt_user_id=4096`,
['uNite'],
])
assert.deepEqual(r, [`UPDATE nt_user SET first_name=? WHERE nt_user_id=4096`, ['uNite']])
})

it('formats with two values', () => {
const r = Mysql.update(`nt_user`, `nt_user_id=4096`, {
last_name: 'Teste',
is_admin: 1,
})
assert.deepEqual(r, [
`UPDATE nt_user SET last_name=?,is_admin=? WHERE nt_user_id=4096`,
['Teste', 1],
])
assert.deepEqual(r, [`UPDATE nt_user SET last_name=?,is_admin=? WHERE nt_user_id=4096`, ['Teste', 1]])
})

it('formats with three values', () => {
Expand Down
26 changes: 4 additions & 22 deletions lib/nameserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@ class Nameserver {
delete args.export.type
}

return await Mysql.execute(
...Mysql.insert(
`nt_nameserver`,
mapToDbColumn(objectToDb(args), nsDbMap),
),
)
return await Mysql.execute(...Mysql.insert(`nt_nameserver`, mapToDbColumn(objectToDb(args), nsDbMap)))
}

async get(args) {
Expand Down Expand Up @@ -79,11 +74,7 @@ class Nameserver {
delete args.id
// Mysql.debug(1)
const r = await Mysql.execute(
...Mysql.update(
`nt_nameserver`,
`nt_nameserver_id=${id}`,
mapToDbColumn(args, nsDbMap),
),
...Mysql.update(`nt_nameserver`, `nt_nameserver_id=${id}`, mapToDbColumn(args, nsDbMap)),
)
return r.changedRows === 1
}
Expand All @@ -98,9 +89,7 @@ class Nameserver {
}

async destroy(args) {
const r = await Mysql.execute(
...Mysql.delete(`nt_nameserver`, { nt_nameserver_id: args.id }),
)
const r = await Mysql.execute(...Mysql.delete(`nt_nameserver`, { nt_nameserver_id: args.id }))
return r.affectedRows === 1
}
}
Expand All @@ -109,14 +98,7 @@ export default new Nameserver()

function dbToObject(rows) {
for (const row of rows) {
for (const f of [
'description',
'address6',
'remote_login',
'datadir',
'logdir',
'export_status',
]) {
for (const f of ['description', 'address6', 'remote_login', 'datadir', 'logdir', 'export_status']) {
if ([undefined, null].includes(row[f])) row[f] = ''
}
for (const f of ['export']) {
Expand Down
4 changes: 1 addition & 3 deletions lib/nameserver.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ describe('nameserver', function () {
})

it('changes a nameserver', async () => {
assert.ok(
await Nameserver.put({ id: testCase.id, name: 'b.ns.example.com.' }),
)
assert.ok(await Nameserver.put({ id: testCase.id, name: 'b.ns.example.com.' }))
const ns = await Nameserver.get({ id: testCase.id })
assert.deepEqual(ns[0].name, 'b.ns.example.com.')
assert.ok(await Nameserver.put({ id: testCase.id, name: testCase.name }))
Expand Down
Loading
Loading