Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mashroom/mashroom-browser-cache

Package Overview
Dependencies
Maintainers
1
Versions
92
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mashroom/mashroom-browser-cache - npm Package Compare versions

Comparing version 1.6.1 to 1.6.2

7

dist/mashroom-bootstrap-services.js

@@ -15,3 +15,2 @@ "use strict";

disabled,
disabledWhenAuthenticated,
maxAgeSec

@@ -21,7 +20,7 @@ } = pluginConfig;

const {
serverConfig,
serverInfo,
loggerFactory
} = pluginContext;
const devMode = serverConfig.pluginPackageFolders && serverConfig.pluginPackageFolders.some(ppf => ppf.devMode);
const cacheControl = new _MashroomCacheControlService.default(devMode, disabled, disabledWhenAuthenticated, maxAgeSec, loggerFactory);
const devMode = serverInfo.devMode;
const cacheControl = new _MashroomCacheControlService.default(devMode, disabled, maxAgeSec, loggerFactory);
return {

@@ -28,0 +27,0 @@ cacheControl

@@ -10,6 +10,5 @@ "use strict";

class MashroomCacheControlService {
constructor(devMode, disabled, disabledWhenAuthenticated, maxAgeSec, loggerFactory) {
this._disabled = disabled;
this._disabledWhenAuthenticated = disabledWhenAuthenticated;
this._maxAgeSec = maxAgeSec;
constructor(devMode, disabled, maxAgeSec, loggerFactory) {
this.maxAgeSec = maxAgeSec;
this.disabled = disabled;
const logger = loggerFactory('mashroom.browserCache.service');

@@ -19,7 +18,7 @@

logger.info('Disabling browser cache because some packages are in dev mode');
this._disabled = true;
this.disabled = true;
}
}
async addCacheControlHeader(request, response) {
async addCacheControlHeader(resourceCanContainSensitiveInformation, request, response) {
const logger = request.pluginContext.loggerFactory('mashroom.browserCache.service');

@@ -32,4 +31,5 @@

if (this._disabled) {
response.set(CACHE_CONTROL_HEADER_NAME, 'no-cache, no-store, must-revalidate');
if (this.disabled) {
this._disableCache(response);
return;

@@ -44,12 +44,12 @@ }

const authenticated = !!user;
publicResource = !authenticated;
if (this._disabledWhenAuthenticated && authenticated) {
response.set(CACHE_CONTROL_HEADER_NAME, 'no-cache, no-store, must-revalidate');
if (resourceCanContainSensitiveInformation && authenticated) {
this._disableCache(response);
return;
}
publicResource = !authenticated;
}
response.set(CACHE_CONTROL_HEADER_NAME, `${publicResource ? 'public' : 'private'}, max-age=${this._maxAgeSec}`);
response.set(CACHE_CONTROL_HEADER_NAME, `${publicResource ? 'public' : 'private'}, max-age=${this.maxAgeSec}`);
}

@@ -61,4 +61,10 @@

_disableCache(res) {
res.set(CACHE_CONTROL_HEADER_NAME, 'no-cache, no-store, max-age=0'); // Older clients
res.set('Pragma', 'no');
}
}
exports.default = MashroomCacheControlService;

@@ -7,3 +7,3 @@ {

"license": "MIT",
"version": "1.6.1",
"version": "1.6.2",
"files": [

@@ -15,7 +15,10 @@ "dist/**",

"@babel/cli": "^7.12.1",
"@mashroom/mashroom": "1.6.1",
"@mashroom/mashroom-security": "1.6.1",
"@mashroom/mashroom-utils": "1.6.1",
"@mashroom/mashroom": "1.6.2",
"@mashroom/mashroom-security": "1.6.2",
"@mashroom/mashroom-utils": "1.6.2",
"@types/jest": "^26.0.15",
"@types/node": "^14.14.6",
"eslint": "^7.13.0",
"jest": "^26.6.3"
"jest": "^26.6.3",
"typescript": "^4.0.5"
},

@@ -28,8 +31,9 @@ "jest": {

],
"testRegex": "(\\.(test|spec))\\.js$"
"testRegex": "(\\.(test|spec))\\.ts$"
},
"scripts": {
"lint": "eslint src test --fix",
"lint": "eslint src test --ext \".ts\" --fix",
"type-check": "tsc --noEmit",
"test": "jest",
"build": "babel src -d dist"
"build": "babel src -d dist --extensions \".ts\""
},

@@ -46,3 +50,2 @@ "mashroom": {

"disabled": false,
"disabledWhenAuthenticated": false,
"maxAgeSec": 1800

@@ -49,0 +52,0 @@ }

@@ -35,3 +35,2 @@

"disabled": false,
"disabledWhenAuthenticated": false,
"maxAgeSec": 1800

@@ -43,3 +42,2 @@ }

* _disabled_: Disable browser caching (default: false)
* _disabledWhenAuthenticated_: Disable browser caching when the user is authenticated (default: false)
* _maxAgeSec_: Max age in seconds (default: 1800)

@@ -57,16 +55,19 @@

export interface MashroomCacheControlService {
/**
* Add the Cache-Control header based on the settings and authentication status.
* The resourceCanContainSensitiveInformation parameter defines if the resource could contain some sensitive user data
* and the caching should be disabled if a user is authenticated.
*/
addCacheControlHeader(
resourceCanContainSensitiveInformation: boolean,
request: ExpressRequest,
response: ExpressResponse,
): Promise<void>;
/**
* Add the Cache-Control header based on the settings and authentication status
*/
addCacheControlHeader(request: ExpressRequest, response: ExpressResponse): Promise<void>;
/**
* Remove a previously set Cache-Control header
*/
/**
* Remove a previously set Cache-Control header
*/
removeCacheControlHeader(response: ExpressResponse): void;
}
```

@@ -1,2 +0,1 @@

/* eslint-disable */

@@ -7,5 +6,8 @@ import type {ExpressRequest, ExpressResponse} from '@mashroom/mashroom/type-definitions';

/**
* Add the Cache-Control header based on the settings and authentication status
* Add the Cache-Control header based on the settings and authentication status.
* The resourceCanContainSensitiveInformation parameter defines if the resource could contain some sensitive user data
* and the caching should be disabled if a user is authenticated.
*/
addCacheControlHeader(
resourceCanContainSensitiveInformation: boolean,
request: ExpressRequest,

@@ -12,0 +14,0 @@ response: ExpressResponse,

@@ -8,5 +8,7 @@ // @flow

/**
* Add the Cache-Control header based on the settings and authentication status
* Add the Cache-Control header based on the settings and authentication status.
* The resourceCanContainSensitiveInformation parameter defines if the resource could contain some sensitive user data
* and the caching should be disabled if a user is authenticated.
*/
addCacheControlHeader(request: ExpressRequest, response: ExpressResponse): Promise<void>;
addCacheControlHeader(resourceCanContainSensitiveInformation: boolean, request: ExpressRequest, response: ExpressResponse): Promise<void>;

@@ -13,0 +15,0 @@ /**

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc