diff --git a/.gitea/workflows/default_nottags.yaml b/.gitea/workflows/default_nottags.yaml new file mode 100644 index 0000000..0bae651 --- /dev/null +++ b/.gitea/workflows/default_nottags.yaml @@ -0,0 +1,66 @@ +name: Default (not tags) + +on: + push: + tags-ignore: + - '**' + +env: + IMAGE: code.foss.global/host.today/ht-docker-node:npmci + NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@/${{gitea.repository}}.git + NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}} + NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}} + NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}} + NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}} + +jobs: + security: + runs-on: ubuntu-latest + continue-on-error: true + container: + image: ${{ env.IMAGE }} + + steps: + - uses: actions/checkout@v3 + + - name: Install pnpm and npmci + run: | + pnpm install -g pnpm + pnpm install -g @ship.zone/npmci + + - name: Run npm prepare + run: npmci npm prepare + + - name: Audit production dependencies + run: | + npmci command npm config set registry https://registry.npmjs.org + npmci command pnpm audit --audit-level=high --prod + continue-on-error: true + + - name: Audit development dependencies + run: | + npmci command npm config set registry https://registry.npmjs.org + npmci command pnpm audit --audit-level=high --dev + continue-on-error: true + + test: + if: ${{ always() }} + needs: security + runs-on: ubuntu-latest + container: + image: ${{ env.IMAGE }} + + steps: + - uses: actions/checkout@v3 + + - name: Test stable + run: | + npmci node install stable + npmci npm install + npmci npm test + + - name: Test build + run: | + npmci node install stable + npmci npm install + npmci npm build diff --git a/.gitea/workflows/default_tags.yaml b/.gitea/workflows/default_tags.yaml new file mode 100644 index 0000000..821d33f --- /dev/null +++ b/.gitea/workflows/default_tags.yaml @@ -0,0 +1,124 @@ +name: Default (tags) + +on: + push: + tags: + - '*' + +env: + IMAGE: code.foss.global/host.today/ht-docker-node:npmci + NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@/${{gitea.repository}}.git + NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}} + NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}} + NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}} + NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}} + +jobs: + security: + runs-on: ubuntu-latest + continue-on-error: true + container: + image: ${{ env.IMAGE }} + + steps: + - uses: actions/checkout@v3 + + - name: Prepare + run: | + pnpm install -g pnpm + pnpm install -g @ship.zone/npmci + npmci npm prepare + + - name: Audit production dependencies + run: | + npmci command npm config set registry https://registry.npmjs.org + npmci command pnpm audit --audit-level=high --prod + continue-on-error: true + + - name: Audit development dependencies + run: | + npmci command npm config set registry https://registry.npmjs.org + npmci command pnpm audit --audit-level=high --dev + continue-on-error: true + + test: + if: ${{ always() }} + needs: security + runs-on: ubuntu-latest + container: + image: ${{ env.IMAGE }} + + steps: + - uses: actions/checkout@v3 + + - name: Prepare + run: | + pnpm install -g pnpm + pnpm install -g @ship.zone/npmci + npmci npm prepare + + - name: Test stable + run: | + npmci node install stable + npmci npm install + npmci npm test + + - name: Test build + run: | + npmci node install stable + npmci npm install + npmci npm build + + release: + needs: test + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') + runs-on: ubuntu-latest + container: + image: ${{ env.IMAGE }} + + steps: + - uses: actions/checkout@v3 + + - name: Prepare + run: | + pnpm install -g pnpm + pnpm install -g @ship.zone/npmci + npmci npm prepare + + - name: Release + run: | + npmci node install stable + npmci npm publish + + metadata: + needs: test + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') + runs-on: ubuntu-latest + container: + image: ${{ env.IMAGE }} + continue-on-error: true + + steps: + - uses: actions/checkout@v3 + + - name: Prepare + run: | + pnpm install -g pnpm + pnpm install -g @ship.zone/npmci + npmci npm prepare + + - name: Code quality + run: | + npmci command npm install -g typescript + npmci npm install + + - name: Trigger + run: npmci trigger + + - name: Build docs and upload artifacts + run: | + npmci node install stable + npmci npm install + pnpm install -g @git.zone/tsdoc + npmci command tsdoc + continue-on-error: true diff --git a/.gitignore b/.gitignore index ef13c79..0b26089 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,6 @@ # artifacts coverage/ public/ -pages/ # installs node_modules/ @@ -17,4 +16,4 @@ node_modules/ dist/ dist_*/ -# custom \ No newline at end of file +#------# custom \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index 0ed6c38..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,141 +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: - - npm install -g @shipzone/npmci - -# ==================== -# security stage -# ==================== -mirror: - stage: security - script: - - npmci git mirror - only: - - tags - tags: - - lossless - - docker - - notpriv - -auditProductionDependencies: - image: registry.gitlab.com/hosttoday/ht-docker-node:npmci - stage: security - script: - - npmci npm prepare - - npmci command npm install --production --ignore-scripts - - npmci command npm config set registry https://registry.npmjs.org - - npmci command npm audit --audit-level=high --only=prod --production - tags: - - docker - allow_failure: true - -auditDevDependencies: - image: registry.gitlab.com/hosttoday/ht-docker-node:npmci - stage: security - script: - - npmci npm prepare - - npmci command npm install --ignore-scripts - - npmci command npm config set registry https://registry.npmjs.org - - npmci command npm audit --audit-level=high --only=dev - tags: - - docker - allow_failure: true - -# ==================== -# test stage -# ==================== - -testStable: - stage: test - script: - - npmci npm prepare - - npmci node install stable - - npmci npm install - - npmci npm test - coverage: /\d+.?\d+?\%\s*coverage/ - tags: - - docker - -testBuild: - stage: test - script: - - npmci npm prepare - - npmci node install stable - - npmci npm install - - npmci command npm run 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 tslint typescript - - npmci npm prepare - - npmci npm install - - npmci command "tslint -c tslint.json ./ts/**/*.ts" - tags: - - lossless - - docker - - priv - -trigger: - stage: metadata - script: - - npmci trigger - only: - - tags - tags: - - lossless - - docker - - notpriv - -pages: - stage: metadata - script: - - npmci node install lts - - npmci command npm install -g @git.zone/tsdoc - - npmci npm prepare - - npmci npm install - - npmci command tsdoc - tags: - - lossless - - docker - - notpriv - only: - - tags - artifacts: - expire_in: 1 week - paths: - - public - allow_failure: true diff --git a/changelog.md b/changelog.md index fb70ca4..41d0587 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,14 @@ # Changelog +## 2025-04-28 - 3.0.4 - fix(ci/config) +Improve CI workflows, update project configuration, and clean up code formatting + +- Added new Gitea workflow files (default_nottags.yaml and default_tags.yaml) to replace GitLab CI +- Updated package.json with new buildDocs script, revised homepage URL, bug tracking info, and pnpm overrides +- Refined code formatting in TypeScript files, including improved error handling in Cloudflare speed tests and consistent callback structure +- Enhanced tsconfig.json by adding baseUrl and paths for better module resolution +- Introduced readme.plan.md outlining future improvements and feature enhancements + ## 2025-04-28 - 3.0.3 - fix(deps) Update dependency namespaces and bump package versions in CI configuration and source imports diff --git a/package.json b/package.json index 9498d14..3854834 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,8 @@ "license": "MIT", "scripts": { "test": "(tstest test/)", - "build": "(tsbuild --web --allowimplicitany)" + "build": "(tsbuild --web --allowimplicitany)", + "buildDocs": "tsdoc" }, "devDependencies": { "@git.zone/tsbuild": "^2.1.61", @@ -56,10 +57,16 @@ "network utility", "TypeScript" ], - "homepage": "https://code.foss.global/push.rocks/smartnetwork", + "homepage": "https://code.foss.global/push.rocks/smartnetwork#readme", "repository": { "type": "git", "url": "https://code.foss.global/push.rocks/smartnetwork.git" }, - "packageManager": "pnpm@10.7.0+sha512.6b865ad4b62a1d9842b61d674a393903b871d9244954f652b8842c2b553c72176b278f64c463e52d40fff8aba385c235c8c9ecf5cc7de4fd78b8bb6d49633ab6" -} + "packageManager": "pnpm@10.7.0+sha512.6b865ad4b62a1d9842b61d674a393903b871d9244954f652b8842c2b553c72176b278f64c463e52d40fff8aba385c235c8c9ecf5cc7de4fd78b8bb6d49633ab6", + "bugs": { + "url": "https://code.foss.global/push.rocks/smartnetwork/issues" + }, + "pnpm": { + "overrides": {} + } +} \ No newline at end of file diff --git a/readme.md b/readme.md index 536d8f1..4d85d3e 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,5 @@ # @push.rocks/smartnetwork + network diagnostics ## Install @@ -58,7 +59,7 @@ const checkLocalPort = async (port: number) => { } }; -checkLocalPort(8080); // Example port number +checkLocalPort(8080); // Example port number ``` ### Checking Remote Port Availability @@ -75,7 +76,7 @@ const checkRemotePort = async (hostname: string, port: number) => { } }; -checkRemotePort('example.com', 443); // Checking HTTPS port on example.com +checkRemotePort('example.com', 443); // Checking HTTPS port on example.com ``` ### Using Ping @@ -131,7 +132,7 @@ These examples offer a glimpse into the module's utility in real-world scenarios ## License and Legal Information -This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. +This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. **Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file. diff --git a/readme.plan.md b/readme.plan.md new file mode 100644 index 0000000..65d1479 --- /dev/null +++ b/readme.plan.md @@ -0,0 +1,47 @@ + # Plan to Enhance Code Quality, Feature Set & Documentation + + This plan focuses on three pillars to elevate `@push.rocks/smartnetwork`: 1) Code Quality, 2) Feature Enhancements, and 3) Documentation. + + ## 1. Code Quality Improvements + - Enable strict TypeScript (`strict`, `noImplicitAny`, `strictNullChecks`). + - Enforce linting (ESLint) and formatting (Prettier) with pre-commit hooks. + - Audit and refactor core modules for: + - Clear separation of concerns (IO, business logic, helpers). + - Removal of duplicated logic and dead code. + - Consistent use of async/await and error propagation. + - Introduce custom error classes (e.g., `NetworkError`, `TimeoutError`) for predictable failure handling. + - Augment logging support via injectable logger interface. + - Establish a baseline of ≥90% unit-test coverage and enforce via CI. + + ## 2. Feature Enhancements + - Expand diagnostics: + - Traceroute functionality with hop-by-hop latency. + - DNS lookup (A, AAAA, MX records). + - HTTP(s) endpoint health check (status codes, headers, latency). + - Improve existing methods: + - `getSpeed`: allow configurable test duration and parallel streams. + - `ping`: add statistical summary (min, max, stddev) and continuous mode. + - `isRemotePortAvailable`: support TCP/UDP checks with timeout and retry. + - Introduce plugin architecture: + - Define `Plugin` interface for third-party extensions. + - Enable runtime registration/unregistration. + - Provide sample plugins (e.g., custom ping strategies, alternate speed providers). + - Optional in-memory caching with TTL for expensive calls (`getPublicIps`, `getGateways`). + + ## 3. Documentation & Examples + - Upgrade README: + - Detailed API reference with method signatures and option parameters. + - Real-world usage snippets and full example projects. + - Add TSDoc comments to all public classes, methods, and types. + - Create a `docs/` folder with: + - Getting Started guide. + - Advanced topics (plugin development, custom error handling). + - FAQ and troubleshooting section. + - Integrate TypeDoc for automated documentation site generation. + - Update `CONTRIBUTING.md` and `CHANGELOG.md` to reflect development and release practices. + + ## Next Steps + 1. Review and prioritize high-impact items per pillar. + 2. Kick off Phase 1 (Code Quality) with linting, TS config, and core refactor. + 3. Schedule sprints for Feature and Documentation phases. + 4. Configure CI pipeline to enforce quality gates and publish docs. \ No newline at end of file diff --git a/test/test.ping.ts b/test/test.ping.ts index 077097a..db595f4 100644 --- a/test/test.ping.ts +++ b/test/test.ping.ts @@ -20,6 +20,6 @@ tap.test('should state when a ping is not alive ', async () => { tap.test('should send a ping to an IP', async () => { await expectAsync(testSmartnetwork.ping('192.168.186.999')).property('alive').toBeFalse(); -}) +}); tap.start(); diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index fd65569..4401ddb 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@push.rocks/smartnetwork', - version: '3.0.3', + version: '3.0.4', description: 'A toolkit for network diagnostics including speed tests, port availability checks, and more.' } diff --git a/ts/smartnetwork.classes.cloudflarespeed.ts b/ts/smartnetwork.classes.cloudflarespeed.ts index dca4abc..f7ecf94 100644 --- a/ts/smartnetwork.classes.cloudflarespeed.ts +++ b/ts/smartnetwork.classes.cloudflarespeed.ts @@ -50,7 +50,7 @@ export class CloudflareSpeed { }, (error) => { console.log(`Error: ${error}`); - } + }, ); } @@ -74,7 +74,7 @@ export class CloudflareSpeed { }, (error) => { console.log(`Error: ${error}`); - } + }, ); } @@ -92,7 +92,7 @@ export class CloudflareSpeed { }, (error) => { console.log(`Error: ${error}`); - } + }, ); } @@ -138,7 +138,7 @@ export class CloudflareSpeed { req.on('error', (err) => { reject(err); }); - } + }, ); req.end(); diff --git a/ts/smartnetwork.classes.smartnetwork.ts b/ts/smartnetwork.classes.smartnetwork.ts index ec7873a..61ce825 100644 --- a/ts/smartnetwork.classes.smartnetwork.ts +++ b/ts/smartnetwork.classes.smartnetwork.ts @@ -16,7 +16,10 @@ export class SmartNetwork { return test; } - public async ping(hostArg: string, timeoutArg: number = 500): Promise> { + public async ping( + hostArg: string, + timeoutArg: number = 500, + ): Promise> { const smartpingInstance = new plugins.smartping.Smartping(); const pingResult = await smartpingInstance.ping(hostArg, timeoutArg); return pingResult; @@ -120,18 +123,22 @@ export class SmartNetwork { public async getPublicIps() { return { - v4: await plugins.publicIp.publicIpv4({ - timeout: 1000, - onlyHttps: true, - }).catch(async (err) => { - return null - }), - v6: await plugins.publicIp.publicIpv6({ - timeout: 1000, - onlyHttps: true, - }).catch(async (err) => { - return null - }) + v4: await plugins.publicIp + .publicIpv4({ + timeout: 1000, + onlyHttps: true, + }) + .catch(async (err) => { + return null; + }), + v6: await plugins.publicIp + .publicIpv6({ + timeout: 1000, + onlyHttps: true, + }) + .catch(async (err) => { + return null; + }), }; } } diff --git a/tsconfig.json b/tsconfig.json index dfe5a55..2413b93 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,9 +6,11 @@ "module": "NodeNext", "moduleResolution": "NodeNext", "esModuleInterop": true, - "verbatimModuleSyntax": true + "verbatimModuleSyntax": true, + "baseUrl": ".", + "paths": {} }, "exclude": [ "dist_*/**/*.d.ts" ] -} +} \ No newline at end of file