diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 90ce95d..a778a92 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -11,12 +11,11 @@ jobs: matrix: node-version: - latest - - 20 - - 18 + - 22 steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - run: npm install diff --git a/index.ts b/index.ts index 0f979e8..f1190f1 100644 --- a/index.ts +++ b/index.ts @@ -3,11 +3,11 @@ import MessageService from './src/message-service.js'; import CipherService from './src/cipher-service.js'; class HttpSms { + private readonly client: AxiosInstance; + public messages: MessageService; public cipher: CipherService; - private readonly client: AxiosInstance; - constructor(apiKey: string, baseUrl = 'https://api.httpsms.com') { this.client = axios.create({ // eslint-disable-next-line @typescript-eslint/naming-convention diff --git a/package.json b/package.json index ea0ebde..e9605a1 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ }, "types": "./dist/index.d.ts", "engines": { - "node": ">=16" + "node": ">=22" }, "scripts": { "test": "xo --env=node && npm run build && mocha -r ts-node/register 'tests/**/*.js'", @@ -36,14 +36,14 @@ "@types/mocha": "^10.0.6", "chai": "^6.0.1", "del-cli": "^7.0.0", - "mocha": "^11.0.1", + "mocha": "^12.0.2", "msw": "^2.1.2", "ts-node": "^10.9.2", "tsd": "^0.33.0", - "xo": "^1.0.5" + "xo": "^5.0.1" }, "dependencies": { - "@types/node": "^24.1.0", + "@types/node": "^26.0.1", "axios": "^1.6.5" }, "prettier": { @@ -56,7 +56,13 @@ }, "xo": { "rules": { - "n/file-extension-in-import": 0 + "n/file-extension-in-import": 0, + "jsdoc/require-asterisk-prefix": 0, + "unicorn/prefer-uint8array-base64": 0, + "@typescript-eslint/no-unsafe-return": 0, + "@typescript-eslint/no-unsafe-call": 0, + "@typescript-eslint/no-unsafe-member-access": 0, + "@typescript-eslint/no-unsafe-assignment": 0 } } } diff --git a/src/cipher-service.ts b/src/cipher-service.ts index 36aadf4..965c746 100644 --- a/src/cipher-service.ts +++ b/src/cipher-service.ts @@ -7,13 +7,13 @@ import { import {Buffer} from 'node:buffer'; class CipherService { + private hash(value: string): Uint8Array { + return createHash('sha256').update(value).digest(); + } + public encrypt(key: string, message: string): string { const iv = randomBytes(16); - const cipher = createCipheriv( - 'aes-256-cfb', - this.hash(key), - iv, - ).setAutoPadding(false); + const cipher = createCipheriv('aes-256-cfb', this.hash(key), iv).setAutoPadding(false); return Buffer.concat([ iv, cipher.update(message, 'utf8'), @@ -24,21 +24,13 @@ class CipherService { public decrypt(key: string, message: string): string { const cipherBytes = Buffer.from(message, 'base64'); const iv = cipherBytes.subarray(0, 16); - const decipher = createDecipheriv( - 'aes-256-cfb', - this.hash(key), - iv, - ).setAutoPadding(false); + const decipher = createDecipheriv('aes-256-cfb', this.hash(key), iv).setAutoPadding(false); return Buffer.concat([ decipher.update(cipherBytes.subarray(16, cipherBytes.length)), decipher.final(), ]).toString(); } - - private hash(value: string): Uint8Array { - return createHash('sha256').update(value).digest(); - } } export default CipherService; diff --git a/src/message-service.ts b/src/message-service.ts index 0de9997..5324489 100644 --- a/src/message-service.ts +++ b/src/message-service.ts @@ -11,8 +11,8 @@ class MessageService { .then((response: AxiosResponse) => { resolve(response.data.data); }) - .catch(async (error: AxiosError) => { - reject(error); + .catch(async (error: unknown) => { + reject(error as AxiosError); }); }); } diff --git a/tests/message-service.spec.js b/tests/message-service.spec.js index a68ff9c..cc0b6a8 100644 --- a/tests/message-service.spec.js +++ b/tests/message-service.spec.js @@ -9,14 +9,7 @@ const successMessageResponse = '{ "data": { "id": "32b0774a-5094-4b58-9efa-57bc describe('MessageService', () => { it('should respond with a valid message', async () => { // Arrange - const server = setupServer( - // Describe network behavior with request handlers. - // Tip: move the handlers into their own module and - // import it across your browser and Node.js setups! - http.post('https://api.httpsms.com/v1/messages/send', () => - HttpResponse.json(JSON.parse(successMessageResponse)), - ), - ); + const server = setupServer(http.post('https://api.httpsms.com/v1/messages/send', () => HttpResponse.json(JSON.parse(successMessageResponse)))); server.listen(); const client = new HttpSms('test key'); @@ -35,14 +28,7 @@ describe('MessageService', () => { }); it('should respond with an error when there is a network error', async () => { // Arrange - const server = setupServer( - // Describe network behavior with request handlers. - // Tip: move the handlers into their own module and - // import it across your browser and Node.js setups! - http.post('https://api.httpsms.com/v1/messages/send', () => - HttpResponse.error(), - ), - ); + const server = setupServer(http.post('https://api.httpsms.com/v1/messages/send', () => HttpResponse.error())); server.listen(); const client = new HttpSms('test key'); diff --git a/tsconfig.json b/tsconfig.json index 1f1a3a7..70bd5e3 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,9 +3,11 @@ "compilerOptions": { "outDir": "dist", "experimentalDecorators": true, - "esModuleInterop": true + "esModuleInterop": true, + "erasableSyntaxOnly": false, + "types": ["node"] }, - "files": ["index.ts"], + "include": ["index.ts", "src/**/*.ts"], "ts-node": { "transpileOnly": true, "esm": true