@tozielinski/next-upstash-nonce 1.2.1 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/package.json +3 -3
- package/.github/workflows/publish.yml +0 -29
- package/.github/workflows/release-please.yml +0 -27
- package/.release-please-config.json +0 -9
- package/.release-please-manifest.json +0 -3
- package/src/index.ts +0 -85
- package/tsconfig.json +0 -13
- /package/{src → dist}/index.js +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.2.3](https://github.com/tozielinski/next-upstash-nonce/compare/v1.2.2...v1.2.3) (2025-11-21)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* dist folder was missing on build ([8afc1d5](https://github.com/tozielinski/next-upstash-nonce/commit/8afc1d5a0add63b1779a08cc4b1e4249ba3cfed9))
|
|
9
|
+
|
|
10
|
+
## [1.2.2](https://github.com/tozielinski/next-upstash-nonce/compare/v1.2.1...v1.2.2) (2025-11-21)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* add .npmignore ([4aafa2c](https://github.com/tozielinski/next-upstash-nonce/commit/4aafa2c9f4081c44030babbeb35c8a5573ef6c3b))
|
|
16
|
+
|
|
3
17
|
## [1.2.1](https://github.com/tozielinski/next-upstash-nonce/compare/v1.2.0...v1.2.1) (2025-11-21)
|
|
4
18
|
|
|
5
19
|
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tozielinski/next-upstash-nonce",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
4
4
|
"description": "Create, store, verify and delete nonces in Redis by Upstash for Next.js",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"access": "public"
|
|
9
9
|
},
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
name: Publish to npm
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
tags:
|
|
6
|
-
- "v*.*.*"
|
|
7
|
-
|
|
8
|
-
permissions:
|
|
9
|
-
id-token: write
|
|
10
|
-
contents: write
|
|
11
|
-
|
|
12
|
-
jobs:
|
|
13
|
-
publish:
|
|
14
|
-
name: Publish package to npm
|
|
15
|
-
runs-on: ubuntu-latest
|
|
16
|
-
steps:
|
|
17
|
-
- uses: actions/checkout@v4
|
|
18
|
-
|
|
19
|
-
- name: Setup Node
|
|
20
|
-
uses: actions/setup-node@v4
|
|
21
|
-
with:
|
|
22
|
-
node-version: "20"
|
|
23
|
-
registry-url: "https://registry.npmjs.org/"
|
|
24
|
-
|
|
25
|
-
- name: Update npm
|
|
26
|
-
run: npm i -g npm@latest
|
|
27
|
-
- run: npm ci
|
|
28
|
-
- run: npm run build
|
|
29
|
-
- run: npm publish --access public
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
name: Release Please
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches:
|
|
6
|
-
- main
|
|
7
|
-
|
|
8
|
-
permissions:
|
|
9
|
-
contents: write
|
|
10
|
-
pull-requests: write
|
|
11
|
-
|
|
12
|
-
jobs:
|
|
13
|
-
release:
|
|
14
|
-
runs-on: ubuntu-latest
|
|
15
|
-
|
|
16
|
-
steps:
|
|
17
|
-
- uses: actions/checkout@v4
|
|
18
|
-
|
|
19
|
-
- name: Run Release Please
|
|
20
|
-
uses: googleapis/release-please-action@v4
|
|
21
|
-
with:
|
|
22
|
-
token: ${{ secrets.GH_PAT }}
|
|
23
|
-
release-type: node
|
|
24
|
-
path: "." # das root package
|
|
25
|
-
config-file: .release-please-config.json
|
|
26
|
-
manifest-file: .release-please-manifest.json
|
|
27
|
-
|
package/src/index.ts
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
'use server'
|
|
2
|
-
|
|
3
|
-
import { Redis } from "@upstash/redis";
|
|
4
|
-
import {v4 as uuid} from "uuid";
|
|
5
|
-
// import crypto from "crypto";
|
|
6
|
-
|
|
7
|
-
export type NonceOptions = {
|
|
8
|
-
length?: number; // bytes
|
|
9
|
-
ttlSeconds?: number; // Time-to-live in Redis
|
|
10
|
-
prefix?: string;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export class NonceManager {
|
|
14
|
-
private redis: Redis;
|
|
15
|
-
private length: number;
|
|
16
|
-
private ttlSeconds: number;
|
|
17
|
-
private prefix: string;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
constructor(redis: Redis, opts: NonceOptions = {}) {
|
|
21
|
-
this.redis = redis;
|
|
22
|
-
this.length = opts.length ?? 32; // default 32 bytes -> 64 hex chars
|
|
23
|
-
this.ttlSeconds = opts.ttlSeconds ?? 60 * 5; // default 5 minutes
|
|
24
|
-
this.prefix = opts.prefix ?? "nonce:";
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* generates a new, secure nonce,
|
|
30
|
-
* inserts it into Redis with a TTL,
|
|
31
|
-
* and returns the nonce string.
|
|
32
|
-
*/
|
|
33
|
-
async create(): Promise<string> {
|
|
34
|
-
// const buffer = crypto.randomBytes(this.length);
|
|
35
|
-
// const nonce = buffer.toString("hex");
|
|
36
|
-
const nonce = uuid();
|
|
37
|
-
const key = this.prefix + nonce;
|
|
38
|
-
|
|
39
|
-
// console.log("creating nonce:", nonce);
|
|
40
|
-
// set with ttl (nx not required — collisions extremely unlikely)
|
|
41
|
-
await this.redis.set(key, "1", { ex: this.ttlSeconds });
|
|
42
|
-
return nonce;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* verifies a nonce and deletes it from Redis,
|
|
48
|
-
* returning true if the nonce exists and has not expired.
|
|
49
|
-
*/
|
|
50
|
-
async verifyAndDelete(nonce: string): Promise<boolean> {
|
|
51
|
-
if (!nonce) return false;
|
|
52
|
-
// const key = this.prefix + nonce;
|
|
53
|
-
//
|
|
54
|
-
// const script = `
|
|
55
|
-
// local v = redis.call('GET', KEYS[1])
|
|
56
|
-
// if v then
|
|
57
|
-
// redis.call('DEL', KEYS[1])
|
|
58
|
-
// return v
|
|
59
|
-
// end
|
|
60
|
-
// return nil
|
|
61
|
-
// `;
|
|
62
|
-
|
|
63
|
-
try {
|
|
64
|
-
const res = await (this.redis as any).get(`nonce:${nonce}`);
|
|
65
|
-
// const res = await (this.redis as any).eval(script, { keys: [key] });
|
|
66
|
-
if (res) await this.redis.del(`nonce:${nonce}`);
|
|
67
|
-
return res !== null;
|
|
68
|
-
} catch (err) {
|
|
69
|
-
console.error("verifyAndDelete error:", err);
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Optional: delete a nonce from Redis manually
|
|
77
|
-
*/
|
|
78
|
-
async delete(nonce: string): Promise<void> {
|
|
79
|
-
const key = this.prefix + nonce;
|
|
80
|
-
await this.redis.del(key);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
export default NonceManager;
|
package/tsconfig.json
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2022",
|
|
4
|
-
"module": "NodeNext",
|
|
5
|
-
"moduleResolution": "NodeNext",
|
|
6
|
-
"esModuleInterop": true,
|
|
7
|
-
"forceConsistentCasingInFileNames": true,
|
|
8
|
-
"strict": true,
|
|
9
|
-
"skipLibCheck": true,
|
|
10
|
-
"types": ["node"]
|
|
11
|
-
},
|
|
12
|
-
"include": ["src"]
|
|
13
|
-
}
|
/package/{src → dist}/index.js
RENAMED
|
File without changes
|