@nemigo/server 1.5.0 → 2.0.0
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/dist/jwt.d.ts +7 -2
- package/dist/jwt.js +1 -1
- package/dist/redis.d.ts +9 -6
- package/dist/redis.js +2 -4
- package/package.json +12 -12
package/dist/jwt.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CanBePromise } from "@nemigo/helpers/types";
|
|
2
|
+
import type { IStorageSetOptions } from "@nemigo/storage/types";
|
|
2
3
|
export interface JWToken<PayloadData> {
|
|
3
4
|
/**
|
|
4
5
|
* Полезная нагрузка токена
|
|
@@ -13,6 +14,10 @@ export interface JWToken<PayloadData> {
|
|
|
13
14
|
*/
|
|
14
15
|
iat: number;
|
|
15
16
|
}
|
|
17
|
+
export interface IJWTStorage {
|
|
18
|
+
has(key: string): CanBePromise<boolean>;
|
|
19
|
+
set(name: string, value: "INVALIDATED", options?: IStorageSetOptions): CanBePromise;
|
|
20
|
+
}
|
|
16
21
|
export interface ConstructJWT {
|
|
17
22
|
signature: string;
|
|
18
23
|
/**
|
|
@@ -20,7 +25,7 @@ export interface ConstructJWT {
|
|
|
20
25
|
*/
|
|
21
26
|
expired?: number;
|
|
22
27
|
}
|
|
23
|
-
export declare class JWT<PayloadData, Storage extends
|
|
28
|
+
export declare class JWT<PayloadData, Storage extends IJWTStorage = IJWTStorage> {
|
|
24
29
|
storage: Storage;
|
|
25
30
|
ctx: ConstructJWT;
|
|
26
31
|
constructor(storage: Storage, ctx: ConstructJWT);
|
package/dist/jwt.js
CHANGED
|
@@ -36,7 +36,7 @@ export class JWT {
|
|
|
36
36
|
if (invalidated)
|
|
37
37
|
return;
|
|
38
38
|
const decoded = await this.decode(token);
|
|
39
|
-
if (decoded
|
|
39
|
+
if (decoded?.exp) {
|
|
40
40
|
const now = Math.floor(Date.now() / 1000);
|
|
41
41
|
const remaining = decoded.exp - now;
|
|
42
42
|
if (remaining > 0) {
|
package/dist/redis.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IStorage,
|
|
1
|
+
import type { IStorage, IStoragePanic, IStorageValue } from "@nemigo/storage/types";
|
|
2
2
|
import type { RedisClientType } from "@redis/client";
|
|
3
3
|
export interface ConstructRedisStorage {
|
|
4
4
|
client: RedisClientType;
|
|
@@ -6,10 +6,15 @@ export interface ConstructRedisStorage {
|
|
|
6
6
|
prefix?: string;
|
|
7
7
|
ttl_seconds?: number;
|
|
8
8
|
}
|
|
9
|
-
export
|
|
9
|
+
export interface IRedisStorageSetOptions {
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* - при `undefined` будет использован `ttl_seconds` хранилища
|
|
12
|
+
* - при `null` элементы не устаревают
|
|
12
13
|
*/
|
|
14
|
+
ttl_seconds?: number | null;
|
|
15
|
+
prefix?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare class RedisStorage implements IStorage<boolean> {
|
|
13
18
|
ttl_seconds?: number;
|
|
14
19
|
prefix: string;
|
|
15
20
|
panic?: IStoragePanic<boolean>;
|
|
@@ -18,8 +23,6 @@ export declare class RedisStorage implements IStorage<boolean> {
|
|
|
18
23
|
__toKey(name: string, prefix?: string): string;
|
|
19
24
|
has(name: string, prefix?: string): Promise<boolean>;
|
|
20
25
|
get<T extends IStorageValue>(name: string, prefix?: string): Promise<T | undefined>;
|
|
21
|
-
set(name: string, value: IStorageValue, options?:
|
|
22
|
-
prefix?: string;
|
|
23
|
-
}): Promise<void>;
|
|
26
|
+
set(name: string, value: IStorageValue, options?: IRedisStorageSetOptions): Promise<void>;
|
|
24
27
|
delete(name: string, prefix?: string): Promise<boolean>;
|
|
25
28
|
}
|
package/dist/redis.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
export class RedisStorage {
|
|
2
|
-
/**
|
|
3
|
-
* TTL хранилища для быстрого использования
|
|
4
|
-
*/
|
|
5
2
|
ttl_seconds;
|
|
6
3
|
prefix;
|
|
7
4
|
panic;
|
|
@@ -37,7 +34,8 @@ export class RedisStorage {
|
|
|
37
34
|
async set(name, value, options = {}) {
|
|
38
35
|
try {
|
|
39
36
|
const key = this.__toKey(name, options.prefix);
|
|
40
|
-
const
|
|
37
|
+
const ttl_seconds = options.ttl_seconds === null ? undefined : (options.ttl_seconds ?? options.ttl_seconds);
|
|
38
|
+
const result = await this.client.set(key, JSON.stringify(value), { EX: ttl_seconds });
|
|
41
39
|
if (result !== "OK")
|
|
42
40
|
return await this.panic?.onset?.(new Error(`Redis SET returned: ${result}`));
|
|
43
41
|
}
|
package/package.json
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nemigo/server",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Vlad Logvin",
|
|
7
7
|
"email": "vlad.logvin84@gmail.com"
|
|
8
8
|
},
|
|
9
9
|
"type": "module",
|
|
10
|
-
"engines": {
|
|
11
|
-
"node": ">=22",
|
|
12
|
-
"pnpm": ">=10.9.0"
|
|
13
|
-
},
|
|
14
10
|
"scripts": {
|
|
15
11
|
"build": "svelte-package && rimraf .svelte-kit",
|
|
16
12
|
"check": "tsc --noemit",
|
|
17
|
-
"
|
|
18
|
-
"
|
|
13
|
+
"eslint": "eslint ./",
|
|
14
|
+
"eslint:fix": "eslint --fix ./",
|
|
15
|
+
"lint": "biome lint",
|
|
16
|
+
"lint:fix": "biome lint --fix --unsafe",
|
|
17
|
+
"lint:fix:unsafe": "biome lint --fix --unsafe",
|
|
18
|
+
"format": "biome check --write --linter-enabled=false"
|
|
19
19
|
},
|
|
20
20
|
"exports": {
|
|
21
21
|
"./jwt": {
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"@nemigo/helpers": ">=
|
|
32
|
-
"@nemigo/storage": ">=
|
|
31
|
+
"@nemigo/helpers": ">=2.0.0",
|
|
32
|
+
"@nemigo/storage": ">=2.0.0"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@redis/client": "5.9.0",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"jsonwebtoken": "9.0.2"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@nemigo/configs": "
|
|
41
|
-
"@nemigo/helpers": "
|
|
42
|
-
"@nemigo/storage": "
|
|
40
|
+
"@nemigo/configs": "2.0.0",
|
|
41
|
+
"@nemigo/helpers": "2.0.0",
|
|
42
|
+
"@nemigo/storage": "2.0.0"
|
|
43
43
|
}
|
|
44
44
|
}
|