@deenruv/redis-strategy-plugin 1.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/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ # License 1
2
+
3
+ The MIT License
4
+
5
+ Copyright (c) 2025-present Aexol
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8
+
9
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12
+
13
+ # License 2
14
+
15
+ The MIT License
16
+
17
+ Copyright (c) 2018-2025 Michael Bromley
18
+
19
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
20
+
21
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
22
+
23
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # @deenruv/redis-strategy-plugin
2
+
3
+ A session cache strategy plugin that uses Redis as the backing store for Deenruv session data, replacing the default in-memory session cache with a persistent, distributed cache.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @deenruv/redis-strategy-plugin ioredis
9
+ ```
10
+
11
+ ## Configuration
12
+
13
+ ```typescript
14
+ import { RedisSessionCachePlugin } from '@deenruv/redis-strategy-plugin/plugin-server';
15
+
16
+ // In your Deenruv server config:
17
+ plugins: [
18
+ RedisSessionCachePlugin.init({
19
+ redisOptions: {
20
+ host: 'localhost',
21
+ port: 6379,
22
+ },
23
+ // Optional: custom namespace prefix for Redis keys
24
+ namespace: 'deenruv-session-cache',
25
+ // Optional: TTL in seconds (default: 86400 = 24 hours)
26
+ defaultTTL: 86400,
27
+ }),
28
+ ]
29
+ ```
30
+
31
+ ## Features
32
+
33
+ - Redis-backed session cache strategy for distributed deployments
34
+ - Configurable TTL (time-to-live) for cached sessions
35
+ - Custom namespace support for key isolation
36
+ - Automatic session serialization/deserialization
37
+ - Graceful error handling with fallback logging
38
+ - Supports all `ioredis` connection options (clusters, sentinels, TLS, etc.)
39
+
40
+ ## Admin UI
41
+
42
+ This plugin extends the admin UI with a Redis monitoring interface for viewing session cache status.
43
+
44
+ ## API Extensions
45
+
46
+ This plugin does not add any GraphQL API extensions. It operates at the infrastructure level by replacing the session cache strategy.
@@ -0,0 +1,23 @@
1
+ import { CachedSession, SessionCacheStrategy } from "@deenruv/core";
2
+ import { RedisOptions } from "ioredis";
3
+ export interface RedisSessionCachePluginOptions {
4
+ redisOptions: RedisOptions;
5
+ namespace?: string;
6
+ defaultTTL?: number;
7
+ }
8
+ export declare class RedisSessionCacheStrategy implements SessionCacheStrategy {
9
+ private options;
10
+ private client;
11
+ constructor(options: RedisSessionCachePluginOptions);
12
+ init(): void;
13
+ destroy(): Promise<void>;
14
+ get(sessionToken: string): Promise<CachedSession | undefined>;
15
+ set(session: CachedSession): Promise<void>;
16
+ delete(sessionToken: string): Promise<void>;
17
+ clear(): void;
18
+ private namespace;
19
+ }
20
+ export declare class RedisSessionCachePlugin {
21
+ static options: RedisSessionCachePluginOptions;
22
+ static init(options: RedisSessionCachePluginOptions): typeof RedisSessionCachePlugin;
23
+ }
@@ -0,0 +1,78 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { Logger, DeenruvPlugin, } from "@deenruv/core";
8
+ import { Redis } from "ioredis";
9
+ const loggerCtx = "RedisSessionCacheStrategy";
10
+ const DEFAULT_NAMESPACE = "deenruv-session-cache";
11
+ const DEFAULT_TTL = 86400;
12
+ export class RedisSessionCacheStrategy {
13
+ constructor(options) {
14
+ this.options = options;
15
+ }
16
+ init() {
17
+ this.client = new Redis(this.options.redisOptions);
18
+ this.client.on("error", (err) => Logger.error(err.message, loggerCtx, err.stack));
19
+ }
20
+ async destroy() {
21
+ await this.client.quit();
22
+ }
23
+ async get(sessionToken) {
24
+ try {
25
+ const retrieved = await this.client.get(this.namespace(sessionToken));
26
+ if (retrieved) {
27
+ try {
28
+ return JSON.parse(retrieved);
29
+ }
30
+ catch (_a) {
31
+ Logger.error(`Could not parse cached session data`, loggerCtx);
32
+ }
33
+ }
34
+ }
35
+ catch (_b) {
36
+ Logger.error(`Could not get cached session`, loggerCtx);
37
+ }
38
+ }
39
+ async set(session) {
40
+ var _a;
41
+ try {
42
+ await this.client.set(this.namespace(session.token), JSON.stringify(session), "EX", (_a = this.options.defaultTTL) !== null && _a !== void 0 ? _a : DEFAULT_TTL);
43
+ }
44
+ catch (_b) {
45
+ Logger.error(`Could not set cached session`, loggerCtx);
46
+ }
47
+ }
48
+ async delete(sessionToken) {
49
+ try {
50
+ await this.client.del(this.namespace(sessionToken));
51
+ }
52
+ catch (_a) {
53
+ Logger.error(`Could not delete cached session`, loggerCtx);
54
+ }
55
+ }
56
+ clear() {
57
+ // this.client.flushdb();
58
+ }
59
+ namespace(key) {
60
+ var _a;
61
+ return `${(_a = this.options.namespace) !== null && _a !== void 0 ? _a : DEFAULT_NAMESPACE}:${key}`;
62
+ }
63
+ }
64
+ let RedisSessionCachePlugin = class RedisSessionCachePlugin {
65
+ static init(options) {
66
+ this.options = options;
67
+ return this;
68
+ }
69
+ };
70
+ RedisSessionCachePlugin = __decorate([
71
+ DeenruvPlugin({
72
+ configuration: (config) => {
73
+ config.authOptions.sessionCacheStrategy = new RedisSessionCacheStrategy(RedisSessionCachePlugin.options);
74
+ return config;
75
+ },
76
+ })
77
+ ], RedisSessionCachePlugin);
78
+ export { RedisSessionCachePlugin };
@@ -0,0 +1 @@
1
+ export declare const UIPlugin: import("@deenruv/react-ui-devkit").DeenruvUIPlugin<{}>;
@@ -0,0 +1,7 @@
1
+ import { createDeenruvUIPlugin } from "@deenruv/react-ui-devkit";
2
+ export const UIPlugin = createDeenruvUIPlugin({
3
+ version: "1.0.0",
4
+ name: "UI Plugin",
5
+ pages: [],
6
+ navMenuLinks: [],
7
+ });
@@ -0,0 +1,18 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "ESNext",
4
+ "moduleResolution": "node",
5
+ "target": "ES2020",
6
+ "jsx": "react",
7
+ "outDir": "../../dist/plugin-ui",
8
+ "importHelpers": true,
9
+ "declaration": true,
10
+ "resolveJsonModule": true,
11
+ "skipLibCheck": true,
12
+ "strict": true,
13
+ "noImplicitAny": true,
14
+ "esModuleInterop": true,
15
+ "allowSyntheticDefaultImports": true
16
+ },
17
+ "include": ["./**/*.tsx", "./**/*.json", "./**/*.ts"]
18
+ }
@@ -0,0 +1,6 @@
1
+ export declare const AllTypesProps: Record<string, any>;
2
+ export declare const ReturnTypes: Record<string, any>;
3
+ export declare const Ops: {
4
+ query: "Query";
5
+ mutation: "Mutation";
6
+ };