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
14 changes: 0 additions & 14 deletions .npmignore

This file was deleted.

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 @@ -6,6 +6,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).

### Unreleased

### [0.8.2] - 2025-04-08

- feat(zone_record): added GET, POST, and DELETE formats
- feat(zone): added GET, POST, and DELETE formats
- feat(session): can return a token
- feat(perm): name ca be empty
- feat(ns): GET always returns an array of items
- feat(ns): address6 can be empty
- meta: add [files] to package.json, deleted .npmignore

### [0.8.1] - 2024-12-16

- doc(CONTRIBUTORS): added
Expand Down Expand Up @@ -75,3 +85,5 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).
[0.7.4]: https://github.com/NicTool/validate/releases/tag/0.7.4
[0.8.0]: https://github.com/NicTool/validate/releases/tag/0.8.0
[0.8.1]: https://github.com/NicTool/validate/releases/tag/v0.8.1
[0.8.2]: https://github.com/NicTool/validate/releases/tag/v0.8.2
[1.0.0]: https://github.com/NicTool/validate/releases/tag/1.0.0
4 changes: 2 additions & 2 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

This handcrafted artisinal 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/validate/commits?author=msimerson">20</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/validate/commits?author=msimerson">21</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>
42 changes: 23 additions & 19 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
import globals from "globals";
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 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 __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all
});
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
})

export default [{
ignores: ["**/package-lock.json"],
}, ...compat.extends("eslint:recommended", "prettier"), {
export default [
{
ignores: ['**/package-lock.json'],
},
...compat.extends('eslint:recommended', 'prettier'),
{
languageOptions: {
globals: {
...globals.node,
...globals.mocha,
},
globals: {
...globals.node,
...globals.mocha,
},
},
}];
},
]
4 changes: 2 additions & 2 deletions lib/nameserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ exports.v3 = Joi.object({
ttl: shared.ttl.required(),
description: Joi.string().empty('').max(255),
address: shared.ipv4.required(),
address6: shared.ipv6,
address6: shared.ipv6.empty(''),
remote_login: exports.remote_login,
logdir: Joi.string().empty('').max(255),
datadir: Joi.string().empty('').min(2).max(255),
Expand All @@ -49,7 +49,7 @@ exports.GET_req = Joi.object({
})

exports.GET_res = Joi.object({
nameserver: exports.v3,
nameserver: Joi.array().items(exports.v3),
meta: shared.meta,
})

Expand Down
2 changes: 1 addition & 1 deletion lib/permission.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ exports.id = Joi.number().integer().min(1).max(4294967295)

exports.v3 = Joi.object({
id: exports.id,
name: Joi.string(),
name: Joi.string().empty(''),
inherit: Joi.boolean(),
self_write: Joi.boolean(),
deleted: Joi.boolean(),
Expand Down
1 change: 1 addition & 0 deletions lib/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ exports.GET_res = Joi.object({
group: group.v3,
session: Joi.object({
id: Joi.number().integer().min(1).max(4294967295),
token: Joi.string(),
last_access: Joi.number().integer().min(1).max(4294967295),
}),
meta: shared.meta,
Expand Down
2 changes: 1 addition & 1 deletion lib/test/zone_record.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": 1,
"zid": 1,
"name": "a",
"owner": "a",
"ttl": 86400,
"type": "A",
"address": "1.1.1.1"
Expand Down
38 changes: 32 additions & 6 deletions lib/zone.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@ const Joi = require('joi')

const shared = require('./shared')

exports.id = shared.uint32

exports.zone = Joi.string()
.min(3)
.max(255)
.domain({ allowFullyQualified: true, tlds: false })
.required()

exports.v3 = Joi.object({
id: shared.uint32,
id: exports.id,

gid: shared.uint32.required(),

zone: Joi.string()
.min(3)
.max(255)
.domain({ allowFullyQualified: true, tlds: false })
.required(),
zone: exports.zone,

description: Joi.string().empty(''),

Expand All @@ -31,5 +35,27 @@ exports.v3 = Joi.object({

ttl: shared.ttl.required(),

last_modified: Joi.date(),

last_publish: Joi.date().allow('', null),

deleted: Joi.boolean(),
})

exports.GET_req = Joi.object({
id: exports.id,
zone: exports.zone,
deleted: Joi.boolean(),
})

exports.GET_res = Joi.object({
zone: Joi.array().items(exports.v3),
meta: shared.meta,
})

exports.POST = exports.v3

exports.DELETE = Joi.object({
id: exports.id,
deleted: Joi.boolean(),
})
34 changes: 28 additions & 6 deletions lib/zone_record.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@ const Joi = require('joi')

const shared = require('./shared')

exports.id = shared.uint32.min(1).required()

exports.owner = Joi.string()
.min(1)
.max(255)
.domain({ minDomainSegments: 1, allowFullyQualified: false, tlds: false })
.required()

exports.v3 = Joi.object({
id: shared.uint32.min(1).required(),
id: exports.id,

zid: shared.uint32.min(1).required(),

name: Joi.string()
.min(1)
.max(255)
.domain({ minDomainSegments: 1, allowFullyQualified: false, tlds: false })
.required(),
owner: exports.owner,

ttl: shared.ttl.required(),

Expand All @@ -27,3 +31,21 @@ exports.v3 = Joi.object({

deleted: Joi.boolean(),
})

exports.GET_req = Joi.object({
id: shared.uint32,
zid: shared.uint32,
deleted: Joi.boolean(),
})

exports.GET_res = Joi.object({
zone_record: Joi.array().items(exports.v3),
meta: shared.meta,
})

exports.POST = exports.v3

exports.DELETE = Joi.object({
id: exports.id,
deleted: Joi.boolean(),
})
18 changes: 9 additions & 9 deletions lib/zone_record.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('zone_record', function () {
}
})

describe('name', function () {
describe('owner', function () {
it(`accepts valid`, () => {
const testCase = JSON.parse(JSON.stringify(testZR))
const { error, value } = schema.validate(testCase)
Expand All @@ -56,26 +56,26 @@ describe('zone_record', function () {

it(`rejects missing`, () => {
const testCase = JSON.parse(JSON.stringify(testZR))
delete testCase.name
delete testCase.owner
const { error } = schema.validate(testCase)
assert.strictEqual(error.message, '"name" is required')
assert.strictEqual(error.message, '"owner" is required')
})

it(`rejects empty`, () => {
const testCase = JSON.parse(JSON.stringify(testZR))
testCase.name = ''
testCase.owner = ''
const { error } = schema.validate(testCase)
assert.strictEqual(error.message, '"name" is not allowed to be empty')
assert.strictEqual(error.message, '"owner" is not allowed to be empty')
})

for (const name of ['a.m.', 'something.test.']) {
it(`rejects invalid: ${name}`, () => {
for (const owner of ['a.m.', 'something.test.']) {
it(`rejects invalid: ${owner}`, () => {
const testCase = JSON.parse(JSON.stringify(testZR))
testCase.name = name
testCase.owner = owner
const { error } = schema.validate(testCase)
assert.deepEqual(
error.message,
'"name" must contain a valid domain name',
'"owner" must contain a valid domain name',
)
})
}
Expand Down
18 changes: 12 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
{
"name": "@nictool/validate",
"version": "0.8.1",
"version": "0.8.2",
"description": "NicTool Object Validation",
"files": [
"lib",
"index.js",
"CHANGELOG.md"
],
"main": "index.js",
"directories": {
"test": "test"
Expand All @@ -15,6 +20,7 @@
"prettier:fix": "npx prettier --ignore-path .gitignore --write .",
"test": "node --test",
"versions": "npx dependency-version-checker check",
"versions:fix": "npx dependency-version-checker update",
"watch": "node --test --watch"
},
"repository": {
Expand All @@ -34,11 +40,11 @@
},
"homepage": "https://github.com/NicTool/validate#readme",
"devDependencies": {
"@eslint/eslintrc": "^3.2.0",
"eslint": "^9.17.0",
"@eslint/js": "^9.17.0",
"eslint-config-prettier": "^9.1.0",
"globals": "^15.13.0"
"@eslint/eslintrc": "^3.3.1",
"eslint": "^9.24.0",
"@eslint/js": "^10.0.0",
"eslint-config-prettier": "^10.1.1",
"globals": "^16.0.0"
},
"dependencies": {
"joi": "^17.13.3",
Expand Down