BREAKING CHANGE(server/client): move from client only to server + client exports

This commit is contained in:
Philipp Kunz 2024-06-02 15:34:19 +02:00
parent c56e732d6d
commit 7eb8a46c7c
12 changed files with 5468 additions and 3197 deletions

View File

@ -1,128 +0,0 @@
# gitzone ci_default
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache:
paths:
- .npmci_cache/
key: '$CI_BUILD_STAGE'
stages:
- security
- test
- release
- metadata
before_script:
- pnpm install -g pnpm
- pnpm install -g @shipzone/npmci
- npmci npm prepare
# ====================
# security stage
# ====================
# ====================
# security stage
# ====================
auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci command npm config set registry https://registry.npmjs.org
- npmci command pnpm audit --audit-level=high --prod
tags:
- lossless
- docker
allow_failure: true
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci command npm config set registry https://registry.npmjs.org
- npmci command pnpm audit --audit-level=high --dev
tags:
- lossless
- docker
allow_failure: true
# ====================
# test stage
# ====================
testStable:
stage: test
script:
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
testBuild:
stage: test
script:
- npmci node install stable
- npmci npm install
- npmci npm build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
release:
stage: release
script:
- npmci node install stable
- npmci npm publish
only:
- tags
tags:
- lossless
- docker
- notpriv
# ====================
# metadata stage
# ====================
codequality:
stage: metadata
allow_failure: true
only:
- tags
script:
- npmci command npm install -g typescript
- npmci npm prepare
- npmci npm install
tags:
- lossless
- docker
- priv
trigger:
stage: metadata
script:
- npmci trigger
only:
- tags
tags:
- lossless
- docker
- notpriv
pages:
stage: metadata
script:
- npmci node install stable
- npmci npm install
- npmci command npm run buildDocs
tags:
- lossless
- docker
- notpriv
only:
- tags
artifacts:
expire_in: 1 week
paths:
- public
allow_failure: true

View File

@ -3,11 +3,14 @@
"version": "5.0.4",
"private": false,
"description": "A TypeScript library for smart DNS methods, supporting various DNS records and providers.",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"exports": {
".": "./dist_ts_server/index.js",
"./server": "./dist_ts_server/index.js",
"./client": "./dist_ts_client/index.js"
},
"scripts": {
"test": "(tstest test/)",
"build": "(tsbuild --web --allowimplicitany)",
"build": "(tsbuild tsfolders --web --allowimplicitany)",
"buildDocs": "tsdoc"
},
"repository": {
@ -31,19 +34,20 @@
},
"homepage": "https://code.foss.global/push.rocks/smartdns",
"dependencies": {
"@pushrocks/smartdelay": "^2.0.13",
"@pushrocks/smartenv": "^5.0.2",
"@pushrocks/smartpromise": "^3.1.7",
"@pushrocks/smartrequest": "^2.0.11",
"@tsclass/tsclass": "^4.0.17",
"dns2": "^2.0.5"
"@push.rocks/smartdelay": "^3.0.1",
"@push.rocks/smartenv": "^5.0.5",
"@push.rocks/smartpromise": "^4.0.2",
"@push.rocks/smartrequest": "^2.0.15",
"@tsclass/tsclass": "^4.0.54",
"@types/dns-packet": "^5.6.5",
"dns-packet": "^5.6.1"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.1.63",
"@gitzone/tsrun": "^1.2.39",
"@gitzone/tstest": "^1.0.72",
"@pushrocks/tapbundle": "^5.0.4",
"@types/node": "^18.15.11"
"@git.zone/tsbuild": "^2.1.66",
"@git.zone/tsrun": "^1.2.44",
"@git.zone/tstest": "^1.0.77",
"@push.rocks/tapbundle": "^5.0.8",
"@types/node": "^20.13.0"
},
"files": [
"ts/**/*",

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
import { expect, tap } from '@pushrocks/tapbundle';
import { expect, tap } from '@push.rocks/tapbundle';
import * as smartdns from '../ts/index.js';
import * as smartdns from '../ts_client/index.js';
let testDnsly: smartdns.Smartdns;

0
test/test.server.ts Normal file
View File

View File

@ -1,8 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
* autocreated commitinfo by @push.rocks/commitinfo
*/
export const commitinfo = {
name: '@pushrocks/smartdns',
name: '@push.rocks/smartdns',
version: '5.0.4',
description: 'smart dns methods written in TypeScript'
}

View File

@ -1,4 +1,4 @@
import * as smartenv from '@pushrocks/smartenv';
import * as smartenv from '@push.rocks/smartenv';
const smartenvInstance = new smartenv.Smartenv();
// node native scope
import type dnsType from 'dns';
@ -7,9 +7,9 @@ const dns: typeof dnsType = await smartenvInstance.getSafeNodeModule('dns');
export { dns };
// pushrocks scope
import * as smartdelay from '@pushrocks/smartdelay';
import * as smartpromise from '@pushrocks/smartpromise';
import * as smartrequest from '@pushrocks/smartrequest';
import * as smartdelay from '@push.rocks/smartdelay';
import * as smartpromise from '@push.rocks/smartpromise';
import * as smartrequest from '@push.rocks/smartrequest';
export { smartdelay, smartenv, smartpromise, smartrequest };

1
ts_client/index.ts Normal file
View File

@ -0,0 +1 @@
export * from './classes.dnsclient.js';

View File

@ -0,0 +1,120 @@
import * as plugins from './plugins.js';
interface IDnsServerOptions {
httpsKey: string;
httpsCert: string;
httpsPort: number;
udpPort: number;
}
class DnsServer {
private udpServer: plugins.dgram.Socket;
private httpsServer: plugins.https.Server;
constructor(private options: IDnsServerOptions) {
this.udpServer = plugins.dgram.createSocket('udp4');
this.setupUdpServer();
this.httpsServer = plugins.https.createServer(
{
key: plugins.fs.readFileSync(options.httpsKey),
cert: plugins.fs.readFileSync(options.httpsCert)
},
this.handleHttpsRequest.bind(this)
);
}
private setupUdpServer(): void {
this.udpServer.on('message', (msg, rinfo) => {
const request = plugins.dnsPacket.decode(msg);
const response = {
type: 'response' as const,
id: request.id,
flags: plugins.dnsPacket.RECURSION_DESIRED | plugins.dnsPacket.RECURSION_AVAILABLE,
questions: request.questions,
answers: [] as plugins.dnsPacket.Answer[]
};
const question = request.questions[0];
console.log(`UDP query for ${question.name} of type ${question.type}`);
if (question.type === 'A') {
response.answers.push({
name: question.name,
type: 'A',
class: 'IN',
ttl: 300,
data: '127.0.0.1'
});
}
const responseData = plugins.dnsPacket.encode(response);
this.udpServer.send(responseData, rinfo.port, rinfo.address);
});
this.udpServer.on('error', (err) => {
console.error(`UDP Server error:\n${err.stack}`);
this.udpServer.close();
});
this.udpServer.bind(this.options.udpPort, '0.0.0.0', () => {
console.log(`UDP DNS server running on port ${this.options.udpPort}`);
});
}
private handleHttpsRequest(req: plugins.http.IncomingMessage, res: plugins.http.ServerResponse): void {
if (req.method === 'POST' && req.url === '/dns-query') {
let body: Buffer[] = [];
req.on('data', chunk => {
body.push(chunk);
}).on('end', () => {
const msg = Buffer.concat(body);
const request = plugins.dnsPacket.decode(msg);
const response = {
type: 'response' as const,
id: request.id,
flags: plugins.dnsPacket.RECURSION_DESIRED | plugins.dnsPacket.RECURSION_AVAILABLE,
questions: request.questions,
answers: [] as plugins.dnsPacket.Answer[]
};
const question = request.questions[0];
console.log(`DoH query for ${question.name} of type ${question.type}`);
if (question.type === 'A') {
response.answers.push({
name: question.name,
type: 'A',
class: 'IN',
ttl: 300,
data: '127.0.0.1'
});
}
const responseData = plugins.dnsPacket.encode(response);
res.writeHead(200, { 'Content-Type': 'application/dns-message' });
res.end(responseData);
});
} else {
res.writeHead(404);
res.end();
}
}
public start(): void {
this.httpsServer.listen(this.options.httpsPort, () => {
console.log(`DoH server running on port ${this.options.httpsPort}`);
});
}
public stop(): void {
this.udpServer.close(() => {
console.log('UDP DNS server stopped');
});
this.httpsServer.close(() => {
console.log('HTTPS DNS server stopped');
});
}
}

0
ts_server/index.ts Normal file
View File

17
ts_server/plugins.ts Normal file
View File

@ -0,0 +1,17 @@
import fs from 'fs';
import http from 'http';
import https from 'https';
import dgram from 'dgram';
export {
fs,
http,
https,
dgram,
}
import * as dnsPacket from 'dns-packet';
export {
dnsPacket
}