-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(inception): initial working version
- Loading branch information
0 parents
commit e35edea
Showing
12 changed files
with
9,537 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
name: Node build, test and publish | ||
|
||
on: | ||
pull_request: | ||
types: [assigned, opened, synchronize, reopened] | ||
push: | ||
branches: | ||
- main | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
prepare: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Cleanup stale actions | ||
uses: styfle/cancel-workflow-action@0.11.0 | ||
with: | ||
access_token: ${{ github.token }} | ||
|
||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Use Node.js 18 | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 20 | ||
cache: yarn | ||
- name: npm install, lint, build, and test | ||
run: | | ||
yarn install --immutable | ||
yarn lint | ||
yarn build | ||
yarn test | ||
env: | ||
CI: true | ||
|
||
publish-npm: | ||
needs: build | ||
if: github.ref == 'refs/heads/main' | ||
permissions: | ||
contents: write | ||
issues: write | ||
id-token: write | ||
pull-requests: write | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v1 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 20 | ||
cache: yarn | ||
- run: yarn install --immutable | ||
- run: yarn build | ||
- name: Release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
NPM_TOKEN: ${{ secrets.SESAMECARE_OSS_NPM_TOKEN }} | ||
run: | | ||
yarn dlx semantic-release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# Custom | ||
src/generated | ||
.transpiled | ||
.nyc_output | ||
.eslintcache | ||
|
||
# TypeScript incremental compilation cache | ||
*.tsbuildinfo | ||
|
||
# Stock | ||
*.seed | ||
*.log | ||
*.csv | ||
*.dat | ||
*.out | ||
*.pid | ||
*.gz | ||
*.orig | ||
|
||
work | ||
/build | ||
pids | ||
logs | ||
results | ||
coverage | ||
lib-cov | ||
html-report | ||
xunit.xml | ||
node_modules | ||
npm-debug.log | ||
|
||
.project | ||
.idea | ||
.settings | ||
.iml | ||
*.sublime-workspace | ||
*.sublime-project | ||
|
||
.DS_Store* | ||
ehthumbs.db | ||
Icon? | ||
Thumbs.db | ||
.AppleDouble | ||
.LSOverride | ||
.Spotlight-V100 | ||
.Trashes | ||
|
||
.yarn/* | ||
!.yarn/patches | ||
!.yarn/plugins | ||
!.yarn/releases | ||
!.yarn/sdks | ||
!.yarn/versions | ||
|
||
.node_repl_history | ||
|
||
# TypeScript incremental compilation cache | ||
*.tsbuildinfo | ||
# Added by coconfig | ||
.eslintignore | ||
.npmignore | ||
tsconfig.json | ||
tsconfig.build.json | ||
.prettierrc.js | ||
.eslintrc.js | ||
.commitlintrc.json | ||
vitest.config.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"files.exclude": { | ||
"**/.git": true, | ||
"**/.svn": true, | ||
"**/.hg": true, | ||
"**/CVS": true, | ||
"**/.DS_Store": true, | ||
"**/Thumbs.db": true, | ||
"**/.retool_types/**": true, | ||
"**/*tsconfig.json": true, | ||
".cache": true, | ||
"retool.config.json": true | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
nodeLinker: node-modules | ||
|
||
plugins: | ||
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs | ||
spec: "@yarnpkg/plugin-interactive-tools" | ||
|
||
yarnPath: .yarn/releases/yarn-3.7.0.cjs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# rate-limit | ||
|
||
|
||
|
||
This project has been made with @sesamecare/create. You should write a glowing and detailed README about | ||
all the things your package does. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"routing": { | ||
"openapi": false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { describe, expect, test } from 'vitest'; | ||
import { getReusableApp } from '@openapi-typescript-infra/service-tester'; | ||
import { useService } from '@openapi-typescript-infra/service'; | ||
|
||
import { RateLimiters } from '../src/index'; | ||
|
||
describe('Basic function', () => { | ||
test('should limit things', async () => { | ||
const key = `test-${Date.now()}`; | ||
const app = await getReusableApp({ name: 'test', service: useService, rootDirectory: __dirname }); | ||
const rateLimiter = new RateLimiters(app, 'memory', { | ||
default: { | ||
points: 10, | ||
duration: 1, | ||
blockDuration: 1, | ||
}, | ||
}); | ||
|
||
const keys = { default: key }; | ||
expect(rateLimiter.instances.default, 'should get a valid rate limiter').toBeDefined(); | ||
let status = await rateLimiter.getRemainingPoints(keys); | ||
expect(status.default?.remainingPoints).toBeUndefined(); | ||
expect((await rateLimiter.isLimited(keys)).isLimited).toBe(false); | ||
|
||
status = await rateLimiter.consume({ default: key }); | ||
expect(status.default?.remainingPoints).toBe(9); | ||
|
||
status = await rateLimiter.getRemainingPoints(keys); | ||
expect(status.default?.remainingPoints).toBe(9); | ||
|
||
status = await rateLimiter.consume(keys, 9); | ||
expect(status.default?.remainingPoints).toBe(0); | ||
|
||
let limit = await rateLimiter.isLimited(keys); | ||
expect(limit.isLimited).toBe(true); | ||
expect(limit.causes).toEqual(['default']); | ||
|
||
limit = await rateLimiter.consumeAndCheckLimit(keys); | ||
expect(limit.isLimited).toBe(true); | ||
expect(limit.causes).toEqual(['default']); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
{ | ||
"name": "@sesamecare-oss/rate-limit", | ||
"version": "0.0.0", | ||
"description": "", | ||
"main": "build/index.js", | ||
"types": "build/index.d.ts", | ||
"author": "Developers <developers@sesamecare.com>", | ||
"license": "UNLICENSED", | ||
"packageManager": "yarn@3.7.0", | ||
"scripts": { | ||
"build": "tsc -p tsconfig.build.json", | ||
"clean": "yarn dlx rimraf ./dist", | ||
"lint": "eslint .", | ||
"postinstall": "coconfig", | ||
"test": "vitest" | ||
}, | ||
"keywords": [ | ||
"typescript", | ||
"sesame" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/sesamecare/rate-limit.git" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"release": { | ||
"branches": [ | ||
"main" | ||
], | ||
"plugins": [ | ||
"@semantic-release/commit-analyzer", | ||
"@semantic-release/release-notes-generator", | ||
[ | ||
"@semantic-release/exec", | ||
{ | ||
"publishCmd": "yarn dlx pinst --disable" | ||
} | ||
], | ||
"@semantic-release/npm", | ||
"@semantic-release/github" | ||
] | ||
}, | ||
"config": { | ||
"coconfig": "@openapi-typescript-infra/coconfig" | ||
}, | ||
"devDependencies": { | ||
"@openapi-typescript-infra/coconfig": "^4.3.0", | ||
"@openapi-typescript-infra/service-tester": "^4.0.3", | ||
"@semantic-release/exec": "^6.0.3", | ||
"@semantic-release/github": "^9.2.6", | ||
"@types/node": "^20.11.5", | ||
"@typescript-eslint/eslint-plugin": "^6.19.1", | ||
"@typescript-eslint/parser": "^6.19.1", | ||
"coconfig": "^1.4.1", | ||
"eslint": "^8.56.0", | ||
"eslint-config-prettier": "^9.1.0", | ||
"eslint-import-resolver-typescript": "^3.6.1", | ||
"eslint-plugin-import": "^2.29.1", | ||
"typescript": "^5.3.3", | ||
"vitest": "^1.2.1" | ||
}, | ||
"dependencies": { | ||
"@openapi-typescript-infra/service": "^4.12.1", | ||
"ioredis": "^5.3.2", | ||
"rate-limiter-flexible": "^4.0.0" | ||
} | ||
} |
Oops, something went wrong.