Skip to content

Commit

Permalink
Build 1: types not working
Browse files Browse the repository at this point in the history
  • Loading branch information
rushabhhere committed Jul 28, 2024
1 parent 1ea385f commit 07687f2
Show file tree
Hide file tree
Showing 6 changed files with 2,238 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/main.yml
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
36 changes: 36 additions & 0 deletions .github/workflows/publish.yml
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 }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
dist
.env
45 changes: 45 additions & 0 deletions index.ts
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;
44 changes: 44 additions & 0 deletions package.json
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"
}
}
Loading

0 comments on commit 07687f2

Please sign in to comment.