From faf2b25dcacb71122eb6fd2636bf09b4abf70880 Mon Sep 17 00:00:00 2001 From: almog8k Date: Wed, 2 Jul 2025 13:13:52 +0300 Subject: [PATCH 1/8] feat: add contentTooLarge and tooManyrequestsError classes --- src/http/contentTooLargeError.ts | 19 +++++++++++++++++++ src/http/tooManyRequestsError.ts | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 src/http/contentTooLargeError.ts create mode 100644 src/http/tooManyRequestsError.ts diff --git a/src/http/contentTooLargeError.ts b/src/http/contentTooLargeError.ts new file mode 100644 index 0000000..384e9c4 --- /dev/null +++ b/src/http/contentTooLargeError.ts @@ -0,0 +1,19 @@ +import HttpStatus from 'http-status-codes'; +import { HttpError } from './httpError'; + +export class ContentTooLarge extends HttpError { + public constructor(message: string); + public constructor(error: Error, messageOverride?: string); + public constructor(error: string | Error, messageOverride?: string) { + if (error instanceof Error) { + super(error, HttpStatus.REQUEST_TOO_LONG, messageOverride); + } else { + super(error, HttpStatus.FORBIDDEN); + } + + // Issue: https://github.com/microsoft/TypeScript/issues/10166 + // Reference: https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work + // Set the prototype explicitly. + Object.setPrototypeOf(this, ContentTooLarge.prototype); + } +} diff --git a/src/http/tooManyRequestsError.ts b/src/http/tooManyRequestsError.ts new file mode 100644 index 0000000..13cd234 --- /dev/null +++ b/src/http/tooManyRequestsError.ts @@ -0,0 +1,19 @@ +import HttpStatus from 'http-status-codes'; +import { HttpError } from './httpError'; + +export class TooManyRequestsError extends HttpError { + public constructor(message: string); + public constructor(error: Error, messageOverride?: string); + public constructor(error: string | Error, messageOverride?: string) { + if (error instanceof Error) { + super(error, HttpStatus.TOO_MANY_REQUESTS, messageOverride); + } else { + super(error, HttpStatus.FORBIDDEN); + } + + // Issue: https://github.com/microsoft/TypeScript/issues/10166 + // Reference: https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work + // Set the prototype explicitly. + Object.setPrototypeOf(this, TooManyRequestsError.prototype); + } +} From 977bc6cfc312e4a91d0a6d543fdcdb600d81392c Mon Sep 17 00:00:00 2001 From: almog8k Date: Wed, 2 Jul 2025 13:23:44 +0300 Subject: [PATCH 2/8] chore: remove gitHub actions old workflow for publishing package --- .github/workflows/publish_package.yml | 56 --------------------------- 1 file changed, 56 deletions(-) delete mode 100644 .github/workflows/publish_package.yml diff --git a/.github/workflows/publish_package.yml b/.github/workflows/publish_package.yml deleted file mode 100644 index a1a8967..0000000 --- a/.github/workflows/publish_package.yml +++ /dev/null @@ -1,56 +0,0 @@ -on: - push: - branches: - - master - paths-ignore: - - '.github/**' - - '.gitignore' - - 'CHANGELOG.md' - - 'commitlint.config.js' - - 'tsbuildconfig.json' - - '.prettierrc.json' - - '.prettierignore' - -jobs: - publish: - runs-on: ubuntu-latest - steps: - - name: Check out TS Project Git repository - uses: actions/checkout@v2 - - - name: Set up Node - uses: actions/setup-node@v1 - with: - node-version: 12 - - - name: Install Node.js dependencies - run: npm i - - - name: Run lint - run: npm run lint - - - name: Run format - run: npm run format - - - name: Build project - run: npm run build - - - name: setup git config - run: | - git config --global user.email "mapcolonies@gmail.com" - git config --global user.name "mapcolonies" - - - name: Bump new version - run: npm run release - - - name: Push git tag - uses: ad-m/github-push-action@master - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - branch: ${{ github.ref }} - tags: true - - - name: Push to NPM - uses: JS-DevTools/npm-publish@v1 - with: - token: ${{ secrets.NPM_TOKEN }} From d6a5d8c025ea1350238cb3280e730626683ddaf7 Mon Sep 17 00:00:00 2001 From: almog8k Date: Wed, 2 Jul 2025 13:26:25 +0300 Subject: [PATCH 3/8] chore: chore: update node.js version in workflow and .nvmrc to v20 --- .github/workflows/pull_request.yml | 63 ++++++++++++++---------------- .nvmrc | 2 +- 2 files changed, 31 insertions(+), 34 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index f190713..d4137b7 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -1,56 +1,53 @@ name: pull_request -on: [pull_request] +on: [pull_request, workflow_dispatch] jobs: - tests: - name: Run Tests + eslint: + name: Run TS Project eslint runs-on: ubuntu-latest + strategy: matrix: - node: [12.x, 14.x] + node: [20.x, 22.x] steps: - - name: Check out Git repository - uses: actions/checkout@v2 + - name: Check out TS Project Git repository + uses: actions/checkout@v4 - - name: Set up Node.js - uses: actions/setup-node@v1 + - name: Init nodejs + uses: ./.github/actions/init-npm with: node-version: ${{ matrix.node }} - - name: Install Node.js dependencies - run: npm ci - - - name: Run tests - run: npm run test - - - uses: actions/upload-artifact@v2 + - name: Run TS Project linters + uses: wearerequired/lint-action@v2 with: - name: Test Reporters - path: reports/** + github_token: ${{ secrets.github_token }} + # Enable linters + eslint: true + prettier: true + eslint_extensions: ts - eslint: - name: Run TS Project eslint + tests: + name: Run Tests runs-on: ubuntu-latest + strategy: + matrix: + node: [20.x, 22.x] + steps: - name: Check out TS Project Git repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 - - name: Set up Node.js - uses: actions/setup-node@v1 - with: - node-version: 12 + - name: Init nodejs + uses: ./.github/actions/init-npm - - name: Install TS Project dependencies - run: npm install + - name: Run tests + run: npm run test - - name: Run TS Project linters - uses: wearerequired/lint-action@v1 + - uses: actions/upload-artifact@v4 with: - github_token: ${{ secrets.github_token }} - # Enable linters - eslint: true - prettier: true - eslint_extensions: ts + name: Test Reporters ${{ matrix.node }} + path: ./reports/** diff --git a/.nvmrc b/.nvmrc index dae199a..9a2a0e2 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -v12 +v20 From fea0f4adec506df8679fa6ecd86f3548a986ee9c Mon Sep 17 00:00:00 2001 From: almog8k Date: Wed, 2 Jul 2025 13:28:12 +0300 Subject: [PATCH 4/8] feat: update publish workflow to use custom init action and streamline steps --- .github/workflows/publish.yaml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 039dde1..693aee5 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -1,9 +1,10 @@ +name: publish + on: workflow_dispatch: release: types: [published] - branches: [master] - + jobs: publish: runs-on: ubuntu-latest @@ -12,11 +13,12 @@ jobs: packages: write # allow GITHUB_TOKEN to publish packages steps: - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 + - name: Init nodejs + uses: ./.github/actions/init-npm with: - node-version: "20" - - run: npm ci - - run: npm run prepack + node-version: 20.x + - name: Copy resources + run: npm run copy - uses: JS-DevTools/npm-publish@v3 with: token: ${{ secrets.NPM_TOKEN }} From 9a56cebf48616380dab955ad74f0b4a3ab765f86 Mon Sep 17 00:00:00 2001 From: almog8k Date: Wed, 2 Jul 2025 13:30:30 +0300 Subject: [PATCH 5/8] feat: add init-npm action to initialize repo and install dependencies --- .github/actions/init-npm/action.yaml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .github/actions/init-npm/action.yaml diff --git a/.github/actions/init-npm/action.yaml b/.github/actions/init-npm/action.yaml new file mode 100644 index 0000000..76e1c89 --- /dev/null +++ b/.github/actions/init-npm/action.yaml @@ -0,0 +1,21 @@ +name: init-npm +description: 'Initialize the repo with npm and install all the dependencies' +inputs: + node-version: + description: 'Node.js version' + required: true + default: '20.x' +runs: + using: composite + steps: + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: ${{ inputs.node-version }} + cache: npm + - name: Install TS Project dependencies + shell: bash + run: npm ci + - name: build + shell: bash + run: npm run build From b485b5a562fd8bfceec42d8aae8ccb3f0899d699 Mon Sep 17 00:00:00 2001 From: almog8k Date: Wed, 2 Jul 2025 14:43:55 +0300 Subject: [PATCH 6/8] fix: pr issues --- .nvmrc | 2 +- src/http/contentTooLargeError.ts | 2 +- src/http/index.ts | 2 ++ src/http/tooManyRequestsError.ts | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.nvmrc b/.nvmrc index 9a2a0e2..dae199a 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -v20 +v12 diff --git a/src/http/contentTooLargeError.ts b/src/http/contentTooLargeError.ts index 384e9c4..535145c 100644 --- a/src/http/contentTooLargeError.ts +++ b/src/http/contentTooLargeError.ts @@ -8,7 +8,7 @@ export class ContentTooLarge extends HttpError { if (error instanceof Error) { super(error, HttpStatus.REQUEST_TOO_LONG, messageOverride); } else { - super(error, HttpStatus.FORBIDDEN); + super(error, HttpStatus.REQUEST_TOO_LONG); } // Issue: https://github.com/microsoft/TypeScript/issues/10166 diff --git a/src/http/index.ts b/src/http/index.ts index 7e754d6..721e6ba 100644 --- a/src/http/index.ts +++ b/src/http/index.ts @@ -11,3 +11,5 @@ export * from './noContentError'; export * from './unprocessableEntity'; export * from './insufficientStorage'; export * from './methodNotAllowedError'; +export * from './tooManyRequestsError'; +export * from './contentTooLargeError'; diff --git a/src/http/tooManyRequestsError.ts b/src/http/tooManyRequestsError.ts index 13cd234..4cba36a 100644 --- a/src/http/tooManyRequestsError.ts +++ b/src/http/tooManyRequestsError.ts @@ -8,7 +8,7 @@ export class TooManyRequestsError extends HttpError { if (error instanceof Error) { super(error, HttpStatus.TOO_MANY_REQUESTS, messageOverride); } else { - super(error, HttpStatus.FORBIDDEN); + super(error, HttpStatus.TOO_MANY_REQUESTS); } // Issue: https://github.com/microsoft/TypeScript/issues/10166 From 88f47f490d2ef1331f83ae96df8061982ca3a258 Mon Sep 17 00:00:00 2001 From: almog8k Date: Thu, 3 Jul 2025 09:34:15 +0300 Subject: [PATCH 7/8] chore: update nvmrc to v20 --- .nvmrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.nvmrc b/.nvmrc index dae199a..85aee5a 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -v12 +v20 \ No newline at end of file From dcb4927cdd512e928de9b8d9db8555f4f23fc989 Mon Sep 17 00:00:00 2001 From: almog8k Date: Thu, 3 Jul 2025 16:00:47 +0300 Subject: [PATCH 8/8] fix: eof --- .nvmrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.nvmrc b/.nvmrc index 85aee5a..9a2a0e2 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -v20 \ No newline at end of file +v20