@deenruv/apollo-cache 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/apollo-cache
2
+
3
+ Server-side response caching plugin for Deenruv, powered by Apollo Server's response cache and cache control plugins. It enables HTTP-level caching of GraphQL responses with session-aware cache keys.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @deenruv/apollo-cache
9
+ ```
10
+
11
+ ## Configuration
12
+
13
+ ```typescript
14
+ import { ApolloCachePlugin } from '@deenruv/apollo-cache';
15
+
16
+ // In your Deenruv server config:
17
+ plugins: [
18
+ ApolloCachePlugin.init({
19
+ cacheControlOptions: {
20
+ defaultMaxAge: 60,
21
+ },
22
+ responseCacheOptions: {
23
+ // Optional: custom session ID extraction
24
+ sessionId: async (req) => {
25
+ // Default implementation extracts session from cookies
26
+ return null;
27
+ },
28
+ },
29
+ }),
30
+ ]
31
+ ```
32
+
33
+ ## Features
34
+
35
+ - Integrates Apollo Server response cache plugin for full-response caching
36
+ - Configurable cache control options (default max age, scope, etc.)
37
+ - Session-aware caching with automatic cookie-based session ID extraction
38
+ - Supports custom session ID resolution for authenticated/personalized responses
39
+
40
+ ## Admin UI
41
+
42
+ This plugin is server-only and does not add any admin UI extensions.
43
+
44
+ ## API Extensions
45
+
46
+ This plugin does not add any GraphQL API extensions. It operates at the Apollo Server plugin level, adding cache control headers and response caching behavior to existing queries.
@@ -0,0 +1,5 @@
1
+ import { type ApolloCachePluginOptions } from "./types.js";
2
+ export declare class ApolloCachePlugin {
3
+ static options: ApolloCachePluginOptions;
4
+ static init(options?: ApolloCachePluginOptions): typeof ApolloCachePlugin;
5
+ }
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ 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;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
11
+ var ApolloCachePlugin_1;
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.ApolloCachePlugin = void 0;
14
+ const core_1 = require("@deenruv/core");
15
+ const options_js_1 = require("./options.js");
16
+ const server_plugin_response_cache_1 = __importDefault(require("@apollo/server-plugin-response-cache"));
17
+ const cacheControl_1 = require("@apollo/server/plugin/cacheControl");
18
+ const utils_js_1 = require("./utils.js");
19
+ let ApolloCachePlugin = ApolloCachePlugin_1 = class ApolloCachePlugin {
20
+ static init(options = {
21
+ cacheControlOptions: {},
22
+ responseCacheOptions: {},
23
+ }) {
24
+ this.options = options;
25
+ return ApolloCachePlugin_1;
26
+ }
27
+ };
28
+ exports.ApolloCachePlugin = ApolloCachePlugin;
29
+ ApolloCachePlugin.options = {
30
+ cacheControlOptions: {},
31
+ responseCacheOptions: {},
32
+ };
33
+ exports.ApolloCachePlugin = ApolloCachePlugin = ApolloCachePlugin_1 = __decorate([
34
+ (0, core_1.DeenruvPlugin)({
35
+ compatibility: "^0.0.1",
36
+ imports: [core_1.PluginCommonModule],
37
+ providers: [
38
+ {
39
+ provide: options_js_1.APOLLO_CACHE_PLUGIN_OPTIONS,
40
+ useFactory: () => ApolloCachePlugin.options,
41
+ },
42
+ ],
43
+ configuration: (config) => {
44
+ const { sessionId = async (req) => {
45
+ var _a, _b;
46
+ const cookies = (0, utils_js_1.parseCookie)((_b = (_a = req.request.http) === null || _a === void 0 ? void 0 : _a.headers.get("cookie")) !== null && _b !== void 0 ? _b : "");
47
+ if (cookies.session && cookies["session.sig"])
48
+ return `${cookies.session}.${cookies["session.sig"]}`;
49
+ return null;
50
+ }, } = ApolloCachePlugin.options.responseCacheOptions;
51
+ config.apiOptions.apolloServerPlugins.push((0, cacheControl_1.ApolloServerPluginCacheControl)(Object.assign({}, ApolloCachePlugin.options.cacheControlOptions)));
52
+ config.apiOptions.apolloServerPlugins.push((0, server_plugin_response_cache_1.default)(Object.assign(Object.assign({}, ApolloCachePlugin.options.responseCacheOptions), { sessionId })));
53
+ return config;
54
+ },
55
+ })
56
+ ], ApolloCachePlugin);
@@ -0,0 +1 @@
1
+ export declare const APOLLO_CACHE_PLUGIN_OPTIONS: unique symbol;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.APOLLO_CACHE_PLUGIN_OPTIONS = void 0;
4
+ exports.APOLLO_CACHE_PLUGIN_OPTIONS = Symbol("APOLLO_CACHE_PLUGIN_OPTIONS");
@@ -0,0 +1,7 @@
1
+ import { BaseContext } from "@apollo/server";
2
+ import { ApolloServerPluginResponseCacheOptions } from "@apollo/server-plugin-response-cache";
3
+ import { ApolloServerPluginCacheControlOptions } from "@apollo/server/plugin/cacheControl";
4
+ export type ApolloCachePluginOptions = {
5
+ responseCacheOptions: ApolloServerPluginResponseCacheOptions<BaseContext>;
6
+ cacheControlOptions: ApolloServerPluginCacheControlOptions;
7
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export declare const parseCookie: (str: string) => Record<string, string>;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseCookie = void 0;
4
+ const parseCookie = (str) => str
5
+ .split(";")
6
+ .map((v) => v.split("="))
7
+ .reduce((acc, v) => {
8
+ if (v) {
9
+ acc[decodeURIComponent(v[0].trim())] =
10
+ v[1] && decodeURIComponent(v[1].trim());
11
+ }
12
+ return acc;
13
+ }, {});
14
+ exports.parseCookie = parseCookie;
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@deenruv/apollo-cache",
3
+ "version": "1.0.0",
4
+ "homepage": "https://deenruv.com/",
5
+ "license": "MIT",
6
+ "files": [
7
+ "dist/**/*"
8
+ ],
9
+ "main": "./dist/plugin-server/index.js",
10
+ "exports": {
11
+ ".": "./dist/plugin-server/index.js",
12
+ "./plugin-server": "./dist/plugin-server/index.js"
13
+ },
14
+ "peerDependencies": {
15
+ "@deenruv/core": "^0.1.0",
16
+ "@apollo/server": "^4.10.4"
17
+ },
18
+ "dependencies": {
19
+ "@apollo/server-plugin-response-cache": "^4.1.3",
20
+ "@nestjs/graphql": "^12.2.0"
21
+ },
22
+ "devDependencies": {
23
+ "rimraf": "^5.0.10",
24
+ "@deenruv/core": "^1.0.0"
25
+ },
26
+ "scripts": {
27
+ "build": "rimraf dist && tsc --build",
28
+ "watch": "tsc --build --watch",
29
+ "lint": "eslint .",
30
+ "lint:fix": "eslint --fix ."
31
+ }
32
+ }