rajt 0.0.40 → 0.0.41
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/package.json +3 -2
- package/src/auth/token.ts +15 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rajt",
|
|
3
3
|
"description": "A serverless bundler layer, fully typed for AWS Lambda (Node.js and LLRT) and Cloudflare Workers.",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.41",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"exports": {
|
|
@@ -52,7 +52,8 @@
|
|
|
52
52
|
"plur": "^5.1.0",
|
|
53
53
|
"tsconfig-paths": "^4.2.0",
|
|
54
54
|
"tsx": "^4.19.3",
|
|
55
|
-
"typescript": "^5.8.3"
|
|
55
|
+
"typescript": "^5.8.3",
|
|
56
|
+
"ua-parser-js": "^2.0.4"
|
|
56
57
|
},
|
|
57
58
|
"devDependencies": {
|
|
58
59
|
"bun-types": "^1.2.14"
|
package/src/auth/token.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Envir } from 't0n'
|
|
2
2
|
import { Token as Factory } from 'cripta'
|
|
3
|
+
import { UAParser } from 'ua-parser-js'
|
|
3
4
|
import c from '../context'
|
|
4
5
|
|
|
5
6
|
export class Token {
|
|
@@ -45,6 +46,8 @@ export class Token {
|
|
|
45
46
|
return Factory.parse(token)
|
|
46
47
|
.issuedBy(host)
|
|
47
48
|
.permittedFor(host)
|
|
49
|
+
.withClaim('u', this.userAgent())
|
|
50
|
+
.withClaim('i', this.ip())
|
|
48
51
|
}
|
|
49
52
|
|
|
50
53
|
static create(user: any, exp: number = 7200) {
|
|
@@ -56,6 +59,8 @@ export class Token {
|
|
|
56
59
|
.permittedFor(host)
|
|
57
60
|
.issuedAt(time)
|
|
58
61
|
.expiresAt(time + exp)
|
|
62
|
+
.withClaim('u', this.userAgent())
|
|
63
|
+
.withClaim('i', this.ip())
|
|
59
64
|
.body(user)
|
|
60
65
|
}
|
|
61
66
|
|
|
@@ -81,4 +86,14 @@ export class Token {
|
|
|
81
86
|
return ''
|
|
82
87
|
}
|
|
83
88
|
}
|
|
89
|
+
|
|
90
|
+
static userAgent() {
|
|
91
|
+
if (!c?.userAgent) return 0
|
|
92
|
+
const { browser, device, os } = UAParser(c.userAgent)
|
|
93
|
+
return (browser?.name || '') + (browser?.major || '') + (device?.model || '') + (os?.name || '')
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
static ip() {
|
|
97
|
+
return c?.ip || 0
|
|
98
|
+
}
|
|
84
99
|
}
|