@tozielinski/next-upstash-nonce 0.1.4 → 1.1.4
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 +34 -0
- package/.github/workflows/release-please.yml +27 -0
- package/.release-please-config.json +9 -0
- package/.release-please-manifest.json +3 -0
- package/CHANGELOG.md +37 -0
- package/README.md +2 -2
- package/dist/index.d.ts +6 -5
- package/dist/index.js +11 -12
- package/package.json +13 -5
- package/src/index.js +74 -0
- package/src/index.ts +9 -6
- package/tsconfig.json +8 -7
|
@@ -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
|
+
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [1.1.4](https://github.com/tozielinski/next-upstash-nonce/compare/v1.1.3...v1.1.4) (2025-11-21)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* try to implement auto-merge ([49705cf](https://github.com/tozielinski/next-upstash-nonce/commit/49705cf1227cb2c8fc294600d0f7b308a6e865ca))
|
|
9
|
+
|
|
10
|
+
## [1.1.3](https://github.com/tozielinski/next-upstash-nonce/compare/v1.1.2...v1.1.3) (2025-11-21)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* changed back to crypto ([b7db377](https://github.com/tozielinski/next-upstash-nonce/commit/b7db3770cf13f0473b9c566a2e8812276cea43fb))
|
|
16
|
+
* try to implement auto-merge ([3155121](https://github.com/tozielinski/next-upstash-nonce/commit/31551211d8c2cfeb4b33ce6f45a3fb7959ac7934))
|
|
17
|
+
|
|
18
|
+
## [1.1.2](https://github.com/tozielinski/next-upstash-nonce/compare/v1.1.1...v1.1.2) (2025-11-21)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Bug Fixes
|
|
22
|
+
|
|
23
|
+
* enable trusted publisher on npm ([48ea331](https://github.com/tozielinski/next-upstash-nonce/commit/48ea331c423e2bb4df7c558ebf4b6a1673529ead))
|
|
24
|
+
|
|
25
|
+
## [1.1.1](https://github.com/tozielinski/next-upstash-nonce/compare/v1.1.0...v1.1.1) (2025-11-21)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Bug Fixes
|
|
29
|
+
|
|
30
|
+
* initialize release flow ([fee5eb3](https://github.com/tozielinski/next-upstash-nonce/commit/fee5eb36ba3e904ee07a1970c2d82546babbc61b))
|
|
31
|
+
|
|
32
|
+
## [1.1.0](https://github.com/tozielinski/next-upstash-nonce/compare/v1.0.0...v1.1.0) (2025-11-21)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
### Features
|
|
36
|
+
|
|
37
|
+
* 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
|
[](https://opensource.org/licenses/MIT)
|
|
3
|
+
[](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
|
-
*
|
|
15
|
-
*
|
|
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
|
-
*
|
|
20
|
-
*
|
|
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:
|
|
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
|
|
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
|
-
*
|
|
18
|
-
*
|
|
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 =
|
|
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
|
-
*
|
|
31
|
-
*
|
|
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:
|
|
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": "
|
|
3
|
+
"version": "1.1.4",
|
|
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.
|
|
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,74 @@
|
|
|
1
|
+
'use server';
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.NonceManager = void 0;
|
|
8
|
+
// import {v4 as uuid} from "uuid";
|
|
9
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
10
|
+
class NonceManager {
|
|
11
|
+
redis;
|
|
12
|
+
length;
|
|
13
|
+
ttlSeconds;
|
|
14
|
+
prefix;
|
|
15
|
+
constructor(redis, opts = {}) {
|
|
16
|
+
this.redis = redis;
|
|
17
|
+
this.length = opts.length ?? 32; // default 32 bytes -> 64 hex chars
|
|
18
|
+
this.ttlSeconds = opts.ttlSeconds ?? 60 * 5; // default 5 minutes
|
|
19
|
+
this.prefix = opts.prefix ?? "nonce:";
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* generates a new, secure nonce,
|
|
23
|
+
* inserts it into Redis with a TTL,
|
|
24
|
+
* and returns the nonce string.
|
|
25
|
+
*/
|
|
26
|
+
async create() {
|
|
27
|
+
const buffer = crypto_1.default.randomBytes(this.length);
|
|
28
|
+
const nonce = buffer.toString("hex");
|
|
29
|
+
// const nonce = uuid();
|
|
30
|
+
const key = this.prefix + nonce;
|
|
31
|
+
// console.log("creating nonce:", nonce);
|
|
32
|
+
// set with ttl (nx not required — collisions extremely unlikely)
|
|
33
|
+
await this.redis.set(key, "1", { ex: this.ttlSeconds });
|
|
34
|
+
return nonce;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* verifies a nonce and deletes it from Redis,
|
|
38
|
+
* returning true if the nonce exists and has not expired.
|
|
39
|
+
*/
|
|
40
|
+
async verifyAndDelete(nonce) {
|
|
41
|
+
if (!nonce)
|
|
42
|
+
return false;
|
|
43
|
+
// const key = this.prefix + nonce;
|
|
44
|
+
//
|
|
45
|
+
// const script = `
|
|
46
|
+
// local v = redis.call('GET', KEYS[1])
|
|
47
|
+
// if v then
|
|
48
|
+
// redis.call('DEL', KEYS[1])
|
|
49
|
+
// return v
|
|
50
|
+
// end
|
|
51
|
+
// return nil
|
|
52
|
+
// `;
|
|
53
|
+
try {
|
|
54
|
+
const res = await this.redis.get(`nonce:${nonce}`);
|
|
55
|
+
// const res = await (this.redis as any).eval(script, { keys: [key] });
|
|
56
|
+
if (res)
|
|
57
|
+
await this.redis.del(`nonce:${nonce}`);
|
|
58
|
+
return res !== null;
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
console.error("verifyAndDelete error:", err);
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Optional: delete a nonce from Redis manually
|
|
67
|
+
*/
|
|
68
|
+
async delete(nonce) {
|
|
69
|
+
const key = this.prefix + nonce;
|
|
70
|
+
await this.redis.del(key);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.NonceManager = NonceManager;
|
|
74
|
+
exports.default = NonceManager;
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use server'
|
|
2
2
|
|
|
3
3
|
import { Redis } from "@upstash/redis";
|
|
4
|
+
// import {v4 as uuid} from "uuid";
|
|
4
5
|
import crypto from "crypto";
|
|
5
6
|
|
|
6
7
|
export type NonceOptions = {
|
|
@@ -25,15 +26,17 @@ export class NonceManager {
|
|
|
25
26
|
|
|
26
27
|
|
|
27
28
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
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
34
|
const buffer = crypto.randomBytes(this.length);
|
|
33
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
|
-
*
|
|
45
|
-
*
|
|
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:
|
|
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": "
|
|
4
|
-
"module": "
|
|
5
|
-
"
|
|
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
|
}
|