From 2e6468ab555854dc59199ae816430782b50beca2 Mon Sep 17 00:00:00 2001 From: Richard Fontein <32132657+rifont@users.noreply.github.com> Date: Tue, 4 Jun 2024 17:28:32 +0100 Subject: [PATCH] fix(echo): Replace faulty instanceof check with static code check (#5678) * chore: update prerelease script to use rimraf * refactor(handler): add error type guard for better handling * fix(ci): update docker-compose path in action.yml * ci(localstack): use e2e docker-compose for localstack * refactor(docker): rename compose file and update config * refactor(docker): use extends in docker-compose.yml * ci: Update docker-compose file for localstack * refactor(ci): rename docker-compose file and update usage * chore: Update package version and repository info --- .github/actions/start-localstack/action.yml | 4 ++-- docker/local/docker-compose.e2e.yml | 18 ++++++++++++++++++ packages/create-novu-app/package.json | 2 +- packages/echo/package.json | 7 +++++-- packages/echo/src/handler.ts | 9 +++++++-- 5 files changed, 33 insertions(+), 7 deletions(-) create mode 100644 docker/local/docker-compose.e2e.yml diff --git a/.github/actions/start-localstack/action.yml b/.github/actions/start-localstack/action.yml index e7a2a8a32be..440ead969fb 100644 --- a/.github/actions/start-localstack/action.yml +++ b/.github/actions/start-localstack/action.yml @@ -16,7 +16,7 @@ runs: AWS_EC2_METADATA_DISABLED: true working-directory: docker/local run: | - docker-compose -f docker-compose.localstack.yml up -d + docker-compose -f docker-compose.e2e.yml up -d sleep 10 max_retry=30 counter=0 @@ -28,5 +28,5 @@ runs: echo "Trying again. Try #$counter" ((counter++)) done - docker-compose -f docker-compose.localstack.yml logs --tail="all" + docker-compose -f docker-compose.e2e.yml logs --tail="all" aws --endpoint-url=http://127.0.0.1:4566 --cli-connect-timeout 600 s3 mb s3://novu-test diff --git a/docker/local/docker-compose.e2e.yml b/docker/local/docker-compose.e2e.yml new file mode 100644 index 00000000000..5270656dbd9 --- /dev/null +++ b/docker/local/docker-compose.e2e.yml @@ -0,0 +1,18 @@ +version: '3.1' + +services: + localstack: + container_name: "${LOCALSTACK_DOCKER_NAME-localstack_main}" + image: "localstack/localstack:0.14.5" + network_mode: bridge + environment: + - SERVICES=s3 + ports: + - "${DOCKER_LOCALSTACK_PORT:-4566}:4566" + volumes: + - "${TMPDIR:-/tmp/localstack}:/tmp/localstack" + - "/var/run/docker.sock:/var/run/docker.sock" + healthcheck: + test: "bash -c 'AWS_ACCESS_KEY_ID=test AWS_SECRET_ACCESS_KEY=test aws --endpoint-url=http://127.0.0.1:4566 s3 ls'" + retries: 5 + interval: 10s diff --git a/packages/create-novu-app/package.json b/packages/create-novu-app/package.json index f1b9fc989c1..892dade0b24 100644 --- a/packages/create-novu-app/package.json +++ b/packages/create-novu-app/package.json @@ -20,7 +20,7 @@ "scripts": { "start": "node dist/index.js", "dev": "ncc build ./index.ts -w -o dist/", - "prerelease": "node ../../scripts/rm.mjs dist", + "prerelease": "rimraf dist", "release": "ncc build ./index.ts -o ./dist/ --minify --no-cache --no-source-map-register", "build": "pnpm release", "lint-fix": "pnpm prettier -w --plugin prettier-plugin-tailwindcss 'templates/*-tw/{ts,js}/{app,pages}/**/*.{js,ts,tsx}'", diff --git a/packages/echo/package.json b/packages/echo/package.json index 90f3b7130b3..dbe1b4108d4 100644 --- a/packages/echo/package.json +++ b/packages/echo/package.json @@ -1,6 +1,6 @@ { "name": "@novu/echo", - "version": "0.24.3-alpha.0", + "version": "0.24.3-alpha.2", "description": "The Code-First Notifications Workflow SDK.", "main": "./dist/index.js", "types": "./dist/index.d.ts", @@ -9,7 +9,10 @@ "access": "public" }, "private": false, - "repository": "https://github.com/novuhq/novu", + "repository": { + "type": "git", + "url": "git+https://github.com/novuhq/novu.git" + }, "scripts": { "preinstall": "npx only-allow pnpm", "test": "jest", diff --git a/packages/echo/src/handler.ts b/packages/echo/src/handler.ts index 7fdc6fa9e5d..450cd04412a 100644 --- a/packages/echo/src/handler.ts +++ b/packages/echo/src/handler.ts @@ -2,6 +2,7 @@ import { createHmac } from 'node:crypto'; import { Echo } from './client'; import { + ErrorCodeEnum, GetActionEnum, HttpHeaderKeysEnum, HttpMethodEnum, @@ -261,8 +262,12 @@ export class EchoRequestHandler { } } - private handleError(error: any): IActionResponse { - if (error instanceof EchoError) { + private isClientError(error: unknown): error is EchoError { + return Object.values(ErrorCodeEnum).includes((error as EchoError).code); + } + + private handleError(error: unknown): IActionResponse { + if (this.isClientError(error)) { if (error.statusCode === HttpStatusEnum.INTERNAL_SERVER_ERROR) { // eslint-disable-next-line no-console console.error(error);