@tozielinski/next-upstash-nonce 0.1.4 → 1.1.5

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.
@@ -0,0 +1,34 @@
1
+ name: Publish to npm
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - "v*.*.*"
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ publish:
13
+ name: Publish package to npm
14
+ runs-on: ubuntu-latest
15
+ permissions:
16
+ id-token: write
17
+ contents: write
18
+ steps:
19
+ - uses: actions/checkout@v4
20
+
21
+ - name: Setup Node
22
+ uses: actions/setup-node@v4
23
+ with:
24
+ node-version: "20"
25
+ registry-url: "https://registry.npmjs.org/"
26
+
27
+ - name: Install dependencies
28
+ run: npm ci
29
+
30
+ - name: Build
31
+ run: npm run build
32
+
33
+ - name: Publish to npm via Trusted Publishing
34
+ run: npm publish --access public
@@ -0,0 +1,27 @@
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
+
@@ -0,0 +1,9 @@
1
+ {
2
+ "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json",
3
+ "release-type": "node",
4
+ "packages": {
5
+ ".": {
6
+ "component": "next-upstash-nonce"
7
+ }
8
+ }
9
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ ".": "1.1.5"
3
+ }
package/CHANGELOG.md ADDED
@@ -0,0 +1,44 @@
1
+ # Changelog
2
+
3
+ ## [1.1.5](https://github.com/tozielinski/next-upstash-nonce/compare/v1.1.4...v1.1.5) (2025-11-21)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * npm publish error ([fbcfc50](https://github.com/tozielinski/next-upstash-nonce/commit/fbcfc50f73a1a193b9ef38ea3618f373995d7b53))
9
+
10
+ ## [1.1.4](https://github.com/tozielinski/next-upstash-nonce/compare/v1.1.3...v1.1.4) (2025-11-21)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * try to implement auto-merge ([49705cf](https://github.com/tozielinski/next-upstash-nonce/commit/49705cf1227cb2c8fc294600d0f7b308a6e865ca))
16
+
17
+ ## [1.1.3](https://github.com/tozielinski/next-upstash-nonce/compare/v1.1.2...v1.1.3) (2025-11-21)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * changed back to crypto ([b7db377](https://github.com/tozielinski/next-upstash-nonce/commit/b7db3770cf13f0473b9c566a2e8812276cea43fb))
23
+ * try to implement auto-merge ([3155121](https://github.com/tozielinski/next-upstash-nonce/commit/31551211d8c2cfeb4b33ce6f45a3fb7959ac7934))
24
+
25
+ ## [1.1.2](https://github.com/tozielinski/next-upstash-nonce/compare/v1.1.1...v1.1.2) (2025-11-21)
26
+
27
+
28
+ ### Bug Fixes
29
+
30
+ * enable trusted publisher on npm ([48ea331](https://github.com/tozielinski/next-upstash-nonce/commit/48ea331c423e2bb4df7c558ebf4b6a1673529ead))
31
+
32
+ ## [1.1.1](https://github.com/tozielinski/next-upstash-nonce/compare/v1.1.0...v1.1.1) (2025-11-21)
33
+
34
+
35
+ ### Bug Fixes
36
+
37
+ * initialize release flow ([fee5eb3](https://github.com/tozielinski/next-upstash-nonce/commit/fee5eb36ba3e904ee07a1970c2d82546babbc61b))
38
+
39
+ ## [1.1.0](https://github.com/tozielinski/next-upstash-nonce/compare/v1.0.0...v1.1.0) (2025-11-21)
40
+
41
+
42
+ ### Features
43
+
44
+ * initialize release flow ([70274c3](https://github.com/tozielinski/next-upstash-nonce/commit/70274c3610ebf02f080e513eee8626774e84a977))
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # next-upstash-nonce
2
2
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
3
+ [![npm version](https://img.shields.io/npm/v/%40tozielinski%2Fnext-upstash-nonce)](https://www.npmjs.com/package/@tozielinski/next-upstash-nonce)
3
4
 
4
-
5
- Create, store, verify and delete nonces in Redis by Upstash for Next.js
5
+ ## Create, store, verify and delete nonces in Redis by Upstash for Next.js
6
6
 
7
7
  # Quick Start
8
8
  ### Install the package:
package/dist/index.d.ts CHANGED
@@ -11,17 +11,18 @@ export declare class NonceManager {
11
11
  private prefix;
12
12
  constructor(redis: Redis, opts?: NonceOptions);
13
13
  /**
14
- * Generiert einen neuen, kryptographisch sicheren Nonce,
15
- * speichert ihn in Redis und gibt ihn zurück.
14
+ * generates a new, secure nonce,
15
+ * inserts it into Redis with a TTL,
16
+ * and returns the nonce string.
16
17
  */
17
18
  create(): Promise<string>;
18
19
  /**
19
- * Verifiziert einen Nonce: prüft ob vorhanden, und löscht ihn atomisch.
20
- * Gibt true zurück, wenn Validierung erfolgreich war (Nonce existierte und wurde entfernt).
20
+ * verifies a nonce and deletes it from Redis,
21
+ * returning true if the nonce exists and has not expired.
21
22
  */
22
23
  verifyAndDelete(nonce: string): Promise<boolean>;
23
24
  /**
24
- * Optional: entferne einen Nonce ohne Verifizierung
25
+ * Optional: delete a nonce from Redis manually
25
26
  */
26
27
  delete(nonce: string): Promise<void>;
27
28
  }
package/dist/index.js CHANGED
@@ -1,11 +1,8 @@
1
1
  "use strict";
2
2
  'use server';
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
- const crypto_1 = __importDefault(require("crypto"));
5
+ const uuid_1 = require("uuid");
9
6
  class NonceManager {
10
7
  constructor(redis, opts = {}) {
11
8
  this.redis = redis;
@@ -14,21 +11,23 @@ class NonceManager {
14
11
  this.prefix = opts.prefix ?? "nonce:";
15
12
  }
16
13
  /**
17
- * Generiert einen neuen, kryptographisch sicheren Nonce,
18
- * speichert ihn in Redis und gibt ihn zurück.
14
+ * generates a new, secure nonce,
15
+ * inserts it into Redis with a TTL,
16
+ * and returns the nonce string.
19
17
  */
20
18
  async create() {
21
- const buffer = crypto_1.default.randomBytes(this.length);
22
- const nonce = buffer.toString("hex");
19
+ // const buffer = crypto.randomBytes(this.length);
20
+ // const nonce = buffer.toString("hex");
21
+ const nonce = (0, uuid_1.v4)();
23
22
  const key = this.prefix + nonce;
24
- console.log("creating nonce:", nonce);
23
+ // console.log("creating nonce:", nonce);
25
24
  // set with ttl (nx not required — collisions extremely unlikely)
26
25
  await this.redis.set(key, "1", { ex: this.ttlSeconds });
27
26
  return nonce;
28
27
  }
29
28
  /**
30
- * Verifiziert einen Nonce: prüft ob vorhanden, und löscht ihn atomisch.
31
- * Gibt true zurück, wenn Validierung erfolgreich war (Nonce existierte und wurde entfernt).
29
+ * verifies a nonce and deletes it from Redis,
30
+ * returning true if the nonce exists and has not expired.
32
31
  */
33
32
  async verifyAndDelete(nonce) {
34
33
  if (!nonce)
@@ -56,7 +55,7 @@ class NonceManager {
56
55
  }
57
56
  }
58
57
  /**
59
- * Optional: entferne einen Nonce ohne Verifizierung
58
+ * Optional: delete a nonce from Redis manually
60
59
  */
61
60
  async delete(nonce) {
62
61
  const key = this.prefix + nonce;
package/package.json CHANGED
@@ -1,11 +1,17 @@
1
1
  {
2
2
  "name": "@tozielinski/next-upstash-nonce",
3
- "version": "0.1.4",
3
+ "version": "1.1.5",
4
4
  "description": "Create, store, verify and delete nonces in Redis by Upstash for Next.js",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
7
10
  "scripts": {
8
- "build": "tsc"
11
+ "build": "tsc",
12
+ "test": "vitest run",
13
+ "typecheck": "tsc --noEmit",
14
+ "prepublishOnly": "npm run build"
9
15
  },
10
16
  "repository": {
11
17
  "type": "git",
@@ -26,10 +32,12 @@
26
32
  "homepage": "https://github.com/tozielinski/next-upstash-nonce#readme",
27
33
  "dependencies": {
28
34
  "@upstash/redis": "1.22.0",
29
- "crypto": "^1.0.1"
35
+ "crypto": "^1.0.1",
36
+ "uuid": "^13.0.0"
30
37
  },
31
38
  "devDependencies": {
32
- "@types/node": "^20.0.0",
33
- "typescript": "^5.0.0"
39
+ "@types/node": "^20.19.25",
40
+ "typescript": "^5.0.0",
41
+ "vitest": "^4.0.12"
34
42
  }
35
43
  }
package/src/index.js ADDED
@@ -0,0 +1,70 @@
1
+ 'use server';
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.NonceManager = void 0;
5
+ const uuid_1 = require("uuid");
6
+ class NonceManager {
7
+ redis;
8
+ length;
9
+ ttlSeconds;
10
+ prefix;
11
+ constructor(redis, opts = {}) {
12
+ this.redis = redis;
13
+ this.length = opts.length ?? 32; // default 32 bytes -> 64 hex chars
14
+ this.ttlSeconds = opts.ttlSeconds ?? 60 * 5; // default 5 minutes
15
+ this.prefix = opts.prefix ?? "nonce:";
16
+ }
17
+ /**
18
+ * generates a new, secure nonce,
19
+ * inserts it into Redis with a TTL,
20
+ * and returns the nonce string.
21
+ */
22
+ async create() {
23
+ // const buffer = crypto.randomBytes(this.length);
24
+ // const nonce = buffer.toString("hex");
25
+ const nonce = (0, uuid_1.v4)();
26
+ const key = this.prefix + nonce;
27
+ // console.log("creating nonce:", nonce);
28
+ // set with ttl (nx not required — collisions extremely unlikely)
29
+ await this.redis.set(key, "1", { ex: this.ttlSeconds });
30
+ return nonce;
31
+ }
32
+ /**
33
+ * verifies a nonce and deletes it from Redis,
34
+ * returning true if the nonce exists and has not expired.
35
+ */
36
+ async verifyAndDelete(nonce) {
37
+ if (!nonce)
38
+ return false;
39
+ // const key = this.prefix + nonce;
40
+ //
41
+ // const script = `
42
+ // local v = redis.call('GET', KEYS[1])
43
+ // if v then
44
+ // redis.call('DEL', KEYS[1])
45
+ // return v
46
+ // end
47
+ // return nil
48
+ // `;
49
+ try {
50
+ const res = await this.redis.get(`nonce:${nonce}`);
51
+ // const res = await (this.redis as any).eval(script, { keys: [key] });
52
+ if (res)
53
+ await this.redis.del(`nonce:${nonce}`);
54
+ return res !== null;
55
+ }
56
+ catch (err) {
57
+ console.error("verifyAndDelete error:", err);
58
+ return false;
59
+ }
60
+ }
61
+ /**
62
+ * Optional: delete a nonce from Redis manually
63
+ */
64
+ async delete(nonce) {
65
+ const key = this.prefix + nonce;
66
+ await this.redis.del(key);
67
+ }
68
+ }
69
+ exports.NonceManager = NonceManager;
70
+ exports.default = NonceManager;
package/src/index.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  'use server'
2
2
 
3
3
  import { Redis } from "@upstash/redis";
4
- import crypto from "crypto";
4
+ import {v4 as uuid} from "uuid";
5
+ // import crypto from "crypto";
5
6
 
6
7
  export type NonceOptions = {
7
8
  length?: number; // bytes
@@ -25,15 +26,17 @@ export class NonceManager {
25
26
 
26
27
 
27
28
  /**
28
- * Generiert einen neuen, kryptographisch sicheren Nonce,
29
- * speichert ihn in Redis und gibt ihn zurück.
29
+ * generates a new, secure nonce,
30
+ * inserts it into Redis with a TTL,
31
+ * and returns the nonce string.
30
32
  */
31
33
  async create(): Promise<string> {
32
- const buffer = crypto.randomBytes(this.length);
33
- const nonce = buffer.toString("hex");
34
+ // const buffer = crypto.randomBytes(this.length);
35
+ // const nonce = buffer.toString("hex");
36
+ const nonce = uuid();
34
37
  const key = this.prefix + nonce;
35
38
 
36
- console.log("creating nonce:", nonce);
39
+ // console.log("creating nonce:", nonce);
37
40
  // set with ttl (nx not required — collisions extremely unlikely)
38
41
  await this.redis.set(key, "1", { ex: this.ttlSeconds });
39
42
  return nonce;
@@ -41,8 +44,8 @@ console.log("creating nonce:", nonce);
41
44
 
42
45
 
43
46
  /**
44
- * Verifiziert einen Nonce: prüft ob vorhanden, und löscht ihn atomisch.
45
- * Gibt true zurück, wenn Validierung erfolgreich war (Nonce existierte und wurde entfernt).
47
+ * verifies a nonce and deletes it from Redis,
48
+ * returning true if the nonce exists and has not expired.
46
49
  */
47
50
  async verifyAndDelete(nonce: string): Promise<boolean> {
48
51
  if (!nonce) return false;
@@ -70,7 +73,7 @@ console.log("creating nonce:", nonce);
70
73
 
71
74
 
72
75
  /**
73
- * Optional: entferne einen Nonce ohne Verifizierung
76
+ * Optional: delete a nonce from Redis manually
74
77
  */
75
78
  async delete(nonce: string): Promise<void> {
76
79
  const key = this.prefix + nonce;
package/tsconfig.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "target": "es2020",
4
- "module": "commonjs",
5
- "declaration": true,
6
- "outDir": "dist",
7
- "strict": true,
3
+ "target": "ES2022",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
8
6
  "esModuleInterop": true,
9
- "forceConsistentCasingInFileNames": true
7
+ "forceConsistentCasingInFileNames": true,
8
+ "strict": true,
9
+ "skipLibCheck": true,
10
+ "types": ["node"]
10
11
  },
11
- "include": ["src/**/*"]
12
+ "include": ["src"]
12
13
  }