-
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.
- Loading branch information
1 parent
1ea385f
commit 07687f2
Showing
6 changed files
with
2,238 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,21 @@ | ||
name: CI | ||
on: | ||
push: | ||
branches: | ||
- '**' | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: pnpm/action-setup@v2 | ||
with: | ||
version: 9 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18.x | ||
cache: 'pnpm' | ||
|
||
- run: pnpm install --frozen-lockfile | ||
- run: pnpm run lint && pnpm run build |
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,36 @@ | ||
name: Publish | ||
on: | ||
workflow_run: | ||
workflows: [CI] | ||
branches: [main] | ||
types: [completed] | ||
|
||
concurrency: ${{ github.workflow }}-${{ github.ref }} | ||
|
||
permissions: | ||
contents: write | ||
pull-requests: write | ||
|
||
jobs: | ||
publish: | ||
if: ${{ github.event.workflow_run.conclusion == 'success' }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: pnpm/action-setup@v2 | ||
with: | ||
version: 9 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18.x | ||
cache: 'pnpm' | ||
|
||
- run: pnpm install --frozen-lockfile | ||
- name: Create Release Pull Request or Publish | ||
id: changesets | ||
uses: changesets/action@v1 | ||
with: | ||
publish: pnpm run release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
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,3 @@ | ||
node_modules | ||
dist | ||
.env |
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,45 @@ | ||
import { OTPStore } from '@otp-forge/otp-forge'; | ||
import type { | ||
RedisClientType, | ||
RedisFunctions, | ||
RedisModules, | ||
RedisScripts, | ||
} from '@redis/client'; | ||
|
||
type RedisClient = RedisClientType<RedisFunctions, RedisModules, RedisScripts>; | ||
|
||
class RedisStore extends OTPStore { | ||
private client: RedisClient; | ||
|
||
constructor(client: RedisClient) { | ||
super(); | ||
this.client = client; | ||
} | ||
|
||
async get(key: string): Promise<[number, Date] | undefined> { | ||
const value = await this.client.get(key); | ||
|
||
if (!value) { | ||
return undefined; | ||
} | ||
|
||
const data = JSON.parse(value); | ||
return data; | ||
} | ||
|
||
async set(key: string, otp: number, ttl: number) { | ||
// await this.client.lset(key, [otp, new Date(Date.now())], { EX: ttl }); | ||
// set an array value: [otp, new Date(Date.now() + ttl * 1000)] in redis | ||
await this.client.set( | ||
key, | ||
JSON.stringify([otp, new Date(Date.now() + ttl * 1000)]), | ||
{ EX: ttl } | ||
); | ||
} | ||
|
||
async del(key: string) { | ||
await this.client.del(key); | ||
} | ||
} | ||
|
||
export default RedisStore; |
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,44 @@ | ||
{ | ||
"name": "@otp-forge/redis-store", | ||
"version": "0.0.1", | ||
"description": "Officially supported Redis store for https://www.npmjs.com/package/@otp-forge/otp-forge.", | ||
"main": "dist/index.js", | ||
"module": "dist/index.mjs", | ||
"types": "dist/index.d.ts", | ||
"scripts": { | ||
"lint": "tsc", | ||
"build": "tsup index.ts --format cjs,esm", | ||
"release": "pnpm run build && changeset publish" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/otp-forge/redis-store.git" | ||
}, | ||
"keywords": [ | ||
"redis", | ||
"store", | ||
"otp", | ||
"password" | ||
], | ||
"author": "Rushabh Javeri <[email protected]>", | ||
"contributors": [ | ||
"Manan Gandhi <[email protected]>" | ||
], | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/otp-forge/redis-store/issues" | ||
}, | ||
"homepage": "https://github.com/otp-forge/redis-store#readme", | ||
"devDependencies": { | ||
"@changesets/cli": "^2.27.7", | ||
"@otp-forge/otp-forge": "^1.0.2", | ||
"@redis/client": "^1.5.17", | ||
"@types/node": "^20.14.12", | ||
"tsup": "^8.2.3", | ||
"typescript": "^5.5.4" | ||
}, | ||
"peerDependencies": { | ||
"@otp-forge/otp-forge": ">=1", | ||
"@redis/client": ">=1" | ||
} | ||
} |
Oops, something went wrong.