diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index 8a0568e..f996842 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -2,6 +2,11 @@ name: Release and Publish on: [push] +permissions: + id-token: write + contents: write + packages: write + env: BRANCH_TAG: "${{ github.ref_name == 'main' && 'latest' || github.ref_name }}" BRANCH: ${{ github.ref_name }} @@ -14,7 +19,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: - node-version: 18 + node-version: 24 - name: Install dependencies run: npm ci - name: Run lint @@ -37,7 +42,7 @@ jobs: - uses: actions/setup-node@v3 with: - node-version: 18 + node-version: 24 - uses: actions/checkout@v3 with: @@ -72,22 +77,20 @@ jobs: git config user.name "fundabot" git commit -a -m "CI: bumps @fundwave/fetch-queue to $VERSION" -m "[skip ci]" - - name: Publish package to gitlab - env: - GITLAB_TOKEN: ${{secrets.GITLAB_TOKEN}} + - name: Build package + run: npm run build + + - name: Publish package to github run: | - echo @fundwave:registry=https://gitlab.com/api/v4/projects/24877554/packages/npm/ > ~/.npmrc - echo //gitlab.com/api/v4/projects/24877554/packages/npm/:_authToken=$GITLAB_TOKEN >> ~/.npmrc + echo "@fundwave:registry=https://npm.pkg.github.com" >> ~/.npmrc + echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" >> ~/.npmrc npm publish --tag $BRANCH_TAG - name: Publish package to npm - if: ${{ github.ref_name == 'main'}} + # if: ${{ github.ref_name == 'main'}} run: | - echo //registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN} > ~/.npmrc - echo registry=https://registry.npmjs.org/ >> ~/.npmrc + echo "@fundwave:registry=https://registry.npmjs.org/" >> ~/.npmrc npm publish --tag $BRANCH_TAG --access public - env: - NODE_AUTH_TOKEN: ${{secrets.NPMJS_TOKEN}} - name: Push changes uses: ad-m/github-push-action@master diff --git a/package.json b/package.json index fde8bf9..240f933 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@fundwave/fetchq", - "version": "1.2.2", + "version": "1.2.4-github-package.1", "description": "Queue for fetch requests", "main": "dist/esm/index.js", "types": "dist/esm/index.d.ts", @@ -11,8 +11,8 @@ }, "scripts": { "build:esm": "tsc --module NodeNext --outDir ./dist/esm", - "build": "tsc --module commonjs --outDir ./dist/cjs", - "prepare": "npm run build && npm run build:esm", + "build:cjs": "tsc --module commonjs --outDir ./dist/cjs", + "build": "npm run build:cjs && npm run build:esm", "pretest": "jest --clearCache", "test": "jest --detectOpenHandles", "lint": "npx eslint src/index.ts", @@ -20,7 +20,7 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/getfundwave/fetch-queue.git" + "url": "git+https://github.com/fundwave/fetch-queue.git" }, "keywords": [ "js", @@ -30,9 +30,9 @@ "author": "The Fundwave Authors", "license": "MIT", "bugs": { - "url": "https://github.com/getfundwave/fetch-queue/issues" + "url": "https://github.com/fundwave/fetch-queue/issues" }, - "homepage": "https://github.com/getfundwave/fetch-queue#readme", + "homepage": "https://github.com/fundwave/fetch-queue#readme", "devDependencies": { "@babel/cli": "^7.23.0", "@babel/core": "^7.23.2", diff --git a/tests/index.test.ts b/tests/index.test.ts index dcc6b83..6b1af79 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -1,7 +1,7 @@ import { FetchQueue } from "../src/index"; import { PreHook } from "../src/interfaces"; -const urls = ["https://httpstat.us/500", "https://dummyjson.com/products/1", "https://dummyjson.com/products/2", "https://dummyjson.com/products/3"]; +const urls = ["https://sandbox.fundwave.com/api/activity/healthchecks", "https://sandbox.fundwave.com/api/user/healthcheck", "https://sandbox.fundwave.com/api/activity/healthcheck", "https://sandbox.fundwave.com/services/api/instance/ssoconfig"]; async function wait(time: number = 1200) { return new Promise((resolve) => { @@ -201,7 +201,7 @@ describe("test case with start and pause queue", () => { expect(fetchQueue.getActiveRequests()).toBe(0); break; case 2: - const regExp = /https:\/\/dummyjson\.com.*/g; + const regExp = /https:\/\/sandbox\.fundwave\.com\/api\/.*\/healthcheck$/g; fetchQueue.emptyQueue(regExp); expect(fetchQueue.getQueueLength()).toBe(0); expect(fetchQueue.getActiveRequests()).toBe(0); @@ -230,15 +230,15 @@ describe("test case with start and pause queue", () => { const fetchQueue = new FetchQueue({ concurrent: 1, - pre: [{ pattern: new RegExp("https://dummyjson.com/products/\\d+"), hook }] + pre: [{ pattern: new RegExp("https://sandbox.fundwave.com/api/user/.*"), hook }] }); fetchQueue.startQueue(); const fetch = fetchQueue.getFetchMethod(); await Promise.allSettled([ - fetch("https://dummyjson.com/products/1"), - fetch("https://dummyjson.com/test"), + fetch("https://sandbox.fundwave.com/api/user/healthcheck"), + fetch("https://sandbox.fundwave.com/api/activity/healthcheck"), ]); expect(hook).toHaveBeenCalledTimes(1); @@ -253,10 +253,10 @@ describe("test case with start and pause queue", () => { const fetchQueue = new FetchQueue({ concurrent: 1, - queuingPatterns: [ new RegExp("https://dummyjson.com/products/*") ], + queuingPatterns: [ new RegExp("https://sandbox.fundwave.com/api/user/.*") ], pre: [ - { pattern: new RegExp("https://dummyjson.com/products/\\d+"), hook: notToBeCalled }, - { pattern: new RegExp("https://dummyjson.com/test"), hook: toBeCalled }, + { pattern: new RegExp("https://sandbox.fundwave.com/api/user/.*"), hook: notToBeCalled }, + { pattern: new RegExp("https://sandbox.fundwave.com/api/activity/healthcheck"), hook: toBeCalled }, ] }); @@ -264,8 +264,8 @@ describe("test case with start and pause queue", () => { fetchQueue.pauseQueue(); const fetch = fetchQueue.getFetchMethod(); - fetch("https://dummyjson.com/products/1"), - await fetch("https://dummyjson.com/test"), + fetch("https://sandbox.fundwave.com/api/user/healthcheck"), + await fetch("https://sandbox.fundwave.com/api/activity/healthcheck"), expect(notToBeCalled).toHaveBeenCalledTimes(0); expect(toBeCalled).toHaveBeenCalled(); @@ -298,7 +298,7 @@ describe("test case with start and pause queue", () => { expect(responses.length).toBe(8); responses.forEach((resp) => { - if (resp.ok) expect(resp.json()).resolves.not.toBeNull(); + if (resp.ok) expect(resp.text()).resolves.not.toBeNull(); }) }, TEST_TIMEOUT); });