@tozielinski/next-upstash-nonce 1.1.4 → 1.2.1
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/.github/workflows/publish.yml +7 -12
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +21 -0
- package/package.json +1 -1
- package/src/index.js +4 -8
- package/src/index.ts +5 -5
- package/dist/index.d.ts +0 -29
- package/dist/index.js +0 -66
|
@@ -6,15 +6,13 @@ on:
|
|
|
6
6
|
- "v*.*.*"
|
|
7
7
|
|
|
8
8
|
permissions:
|
|
9
|
-
|
|
9
|
+
id-token: write
|
|
10
|
+
contents: write
|
|
10
11
|
|
|
11
12
|
jobs:
|
|
12
13
|
publish:
|
|
13
14
|
name: Publish package to npm
|
|
14
15
|
runs-on: ubuntu-latest
|
|
15
|
-
permissions:
|
|
16
|
-
id-token: write
|
|
17
|
-
contents: write
|
|
18
16
|
steps:
|
|
19
17
|
- uses: actions/checkout@v4
|
|
20
18
|
|
|
@@ -24,11 +22,8 @@ jobs:
|
|
|
24
22
|
node-version: "20"
|
|
25
23
|
registry-url: "https://registry.npmjs.org/"
|
|
26
24
|
|
|
27
|
-
- name:
|
|
28
|
-
run: npm
|
|
29
|
-
|
|
30
|
-
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
- name: Publish to npm via Trusted Publishing
|
|
34
|
-
run: npm publish --access public
|
|
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
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.2.1](https://github.com/tozielinski/next-upstash-nonce/compare/v1.2.0...v1.2.1) (2025-11-21)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* error in npm publish ([d337519](https://github.com/tozielinski/next-upstash-nonce/commit/d3375198b2bcabd846c5f7d04cb44e2059a71462))
|
|
9
|
+
|
|
10
|
+
## [1.2.0](https://github.com/tozielinski/next-upstash-nonce/compare/v1.1.5...v1.2.0) (2025-11-21)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
* replaced crypto by uuid ([38e2076](https://github.com/tozielinski/next-upstash-nonce/commit/38e2076fe5139848e05c37d3961eec01d84cc346))
|
|
16
|
+
|
|
17
|
+
## [1.1.5](https://github.com/tozielinski/next-upstash-nonce/compare/v1.1.4...v1.1.5) (2025-11-21)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* npm publish error ([fbcfc50](https://github.com/tozielinski/next-upstash-nonce/commit/fbcfc50f73a1a193b9ef38ea3618f373995d7b53))
|
|
23
|
+
|
|
3
24
|
## [1.1.4](https://github.com/tozielinski/next-upstash-nonce/compare/v1.1.3...v1.1.4) (2025-11-21)
|
|
4
25
|
|
|
5
26
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
'use server';
|
|
2
2
|
"use strict";
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
-
};
|
|
6
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
4
|
exports.NonceManager = void 0;
|
|
8
|
-
|
|
9
|
-
const crypto_1 = __importDefault(require("crypto"));
|
|
5
|
+
const uuid_1 = require("uuid");
|
|
10
6
|
class NonceManager {
|
|
11
7
|
redis;
|
|
12
8
|
length;
|
|
@@ -24,9 +20,9 @@ class NonceManager {
|
|
|
24
20
|
* and returns the nonce string.
|
|
25
21
|
*/
|
|
26
22
|
async create() {
|
|
27
|
-
const buffer =
|
|
28
|
-
const nonce = buffer.toString("hex");
|
|
29
|
-
|
|
23
|
+
// const buffer = crypto.randomBytes(this.length);
|
|
24
|
+
// const nonce = buffer.toString("hex");
|
|
25
|
+
const nonce = (0, uuid_1.v4)();
|
|
30
26
|
const key = this.prefix + nonce;
|
|
31
27
|
// console.log("creating nonce:", nonce);
|
|
32
28
|
// set with ttl (nx not required — collisions extremely unlikely)
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use server'
|
|
2
2
|
|
|
3
3
|
import { Redis } from "@upstash/redis";
|
|
4
|
-
|
|
5
|
-
import crypto from "crypto";
|
|
4
|
+
import {v4 as uuid} from "uuid";
|
|
5
|
+
// import crypto from "crypto";
|
|
6
6
|
|
|
7
7
|
export type NonceOptions = {
|
|
8
8
|
length?: number; // bytes
|
|
@@ -31,9 +31,9 @@ export class NonceManager {
|
|
|
31
31
|
* and returns the nonce string.
|
|
32
32
|
*/
|
|
33
33
|
async create(): Promise<string> {
|
|
34
|
-
const buffer = crypto.randomBytes(this.length);
|
|
35
|
-
const nonce = buffer.toString("hex");
|
|
36
|
-
|
|
34
|
+
// const buffer = crypto.randomBytes(this.length);
|
|
35
|
+
// const nonce = buffer.toString("hex");
|
|
36
|
+
const nonce = uuid();
|
|
37
37
|
const key = this.prefix + nonce;
|
|
38
38
|
|
|
39
39
|
// console.log("creating nonce:", nonce);
|
package/dist/index.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Redis } from "@upstash/redis";
|
|
2
|
-
export type NonceOptions = {
|
|
3
|
-
length?: number;
|
|
4
|
-
ttlSeconds?: number;
|
|
5
|
-
prefix?: string;
|
|
6
|
-
};
|
|
7
|
-
export declare class NonceManager {
|
|
8
|
-
private redis;
|
|
9
|
-
private length;
|
|
10
|
-
private ttlSeconds;
|
|
11
|
-
private prefix;
|
|
12
|
-
constructor(redis: Redis, opts?: NonceOptions);
|
|
13
|
-
/**
|
|
14
|
-
* generates a new, secure nonce,
|
|
15
|
-
* inserts it into Redis with a TTL,
|
|
16
|
-
* and returns the nonce string.
|
|
17
|
-
*/
|
|
18
|
-
create(): Promise<string>;
|
|
19
|
-
/**
|
|
20
|
-
* verifies a nonce and deletes it from Redis,
|
|
21
|
-
* returning true if the nonce exists and has not expired.
|
|
22
|
-
*/
|
|
23
|
-
verifyAndDelete(nonce: string): Promise<boolean>;
|
|
24
|
-
/**
|
|
25
|
-
* Optional: delete a nonce from Redis manually
|
|
26
|
-
*/
|
|
27
|
-
delete(nonce: string): Promise<void>;
|
|
28
|
-
}
|
|
29
|
-
export default NonceManager;
|
package/dist/index.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
'use server';
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.NonceManager = void 0;
|
|
5
|
-
const uuid_1 = require("uuid");
|
|
6
|
-
class NonceManager {
|
|
7
|
-
constructor(redis, opts = {}) {
|
|
8
|
-
this.redis = redis;
|
|
9
|
-
this.length = opts.length ?? 32; // default 32 bytes -> 64 hex chars
|
|
10
|
-
this.ttlSeconds = opts.ttlSeconds ?? 60 * 5; // default 5 minutes
|
|
11
|
-
this.prefix = opts.prefix ?? "nonce:";
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* generates a new, secure nonce,
|
|
15
|
-
* inserts it into Redis with a TTL,
|
|
16
|
-
* and returns the nonce string.
|
|
17
|
-
*/
|
|
18
|
-
async create() {
|
|
19
|
-
// const buffer = crypto.randomBytes(this.length);
|
|
20
|
-
// const nonce = buffer.toString("hex");
|
|
21
|
-
const nonce = (0, uuid_1.v4)();
|
|
22
|
-
const key = this.prefix + nonce;
|
|
23
|
-
// console.log("creating nonce:", nonce);
|
|
24
|
-
// set with ttl (nx not required — collisions extremely unlikely)
|
|
25
|
-
await this.redis.set(key, "1", { ex: this.ttlSeconds });
|
|
26
|
-
return nonce;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* verifies a nonce and deletes it from Redis,
|
|
30
|
-
* returning true if the nonce exists and has not expired.
|
|
31
|
-
*/
|
|
32
|
-
async verifyAndDelete(nonce) {
|
|
33
|
-
if (!nonce)
|
|
34
|
-
return false;
|
|
35
|
-
// const key = this.prefix + nonce;
|
|
36
|
-
//
|
|
37
|
-
// const script = `
|
|
38
|
-
// local v = redis.call('GET', KEYS[1])
|
|
39
|
-
// if v then
|
|
40
|
-
// redis.call('DEL', KEYS[1])
|
|
41
|
-
// return v
|
|
42
|
-
// end
|
|
43
|
-
// return nil
|
|
44
|
-
// `;
|
|
45
|
-
try {
|
|
46
|
-
const res = await this.redis.get(`nonce:${nonce}`);
|
|
47
|
-
// const res = await (this.redis as any).eval(script, { keys: [key] });
|
|
48
|
-
if (res)
|
|
49
|
-
await this.redis.del(`nonce:${nonce}`);
|
|
50
|
-
return res !== null;
|
|
51
|
-
}
|
|
52
|
-
catch (err) {
|
|
53
|
-
console.error("verifyAndDelete error:", err);
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Optional: delete a nonce from Redis manually
|
|
59
|
-
*/
|
|
60
|
-
async delete(nonce) {
|
|
61
|
-
const key = this.prefix + nonce;
|
|
62
|
-
await this.redis.del(key);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
exports.NonceManager = NonceManager;
|
|
66
|
-
exports.default = NonceManager;
|