Socket
Socket
Sign inDemoInstall

@mashroom/mashroom-browser-cache

Package Overview
Dependencies
0
Maintainers
1
Versions
89
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @mashroom/mashroom-browser-cache

Mashroom services to control browser caching


Version published
Maintainers
1
Install size
8.17 kB
Created

Changelog

Source

2.6.0 (April 6, 2024)

  • Supply Chain Safety: Generate npm provenance statements when publishing (via Github Actions workflow)
  • Supply Chain Safety: Disabled all dependency lifecycle scripts by default
  • HTTP Proxy: Added support for transforming the request/response body. Proxy interceptors can now return streamTransformers (implementing stream.Transform) that can be used to compress/encrypt the communication to backend servers. See #116. Example:
    export default class MyInterceptor implements MashroomHttpProxyInterceptor {
       async interceptRequest(targetUri) {
           if (targetUri.startsWith('https://my-backend-server.com')) {
               return {
                   addHeaders: {
                       'content-encoding': 'gzip',
                   },
                   streamTransformers: [
                       zlib.createGzip(),
                   ],
               };
           }
       }
       async interceptResponse(targetUri, existingHeaders) {
           if (targetUri.startsWith('https://my-backend-server.com') && existingHeaders['content-encoding'] === 'gzip') {
               return {
                   removeHeaders: [
                       'content-encoding',
                   ],
                   streamTransformers: [
                       zlib.createGunzip(),
                   ],
               };
           }
       }
    }
    
  • HTTP Proxy: Removed request based proxy implementation because the module is deprecated for over 4 years now
  • Upgrade to Express 4.19 + all other libraries upgraded
  • HTTP Portal: Fixed the problem that remote subscriptions can receive the same message multiple times if subscription patterns overlap See #115

Readme

Source

Mashroom Browser Cache

Plugin for Mashroom Server, a Microfrontend Integration Platform.

This plugin adds a Service to manage cache control headers. It also allows to disable the cache globally.

Usage

If node_modules/@mashroom is configured as plugin path just add @mashroom/mashroom-browser-cache as dependency.

After that you can use the service like this:

import type {MashroomCacheControlService} from '@mashroom/mashroom-browser-cache/type-definitions';

export default async (req: Request, res: Response) => {

    const cacheControlService: MashroomCacheControlService = req.pluginContext.services.browserCache.cacheControl;
    await cacheControlService.addCacheControlHeader('ONLY_FOR_ANONYMOUS_USERS', req, res);

    // ..
};

You can override the default config in your Mashroom config file like this:

{
  "plugins": {
        "Mashroom Cache Control Services": {
            "disabled": false,
            "maxAgeSec": 31536000
        }
    }
}
  • disabled: Disable browser caching (default: false)
  • maxAgeSec: Max age in seconds (default: 31536000 (30d))

Services

MashroomCacheControlService

The Cache Control service is accessible through pluginContext.services.browserCache.cacheControl

Interface:

export interface MashroomCacheControlService {
    /**
     * Add the Cache-Control header based on the policy and authentication status.
     */
     addCacheControlHeader(cachingPolicy: CachingPolicy, request: Request, response: Response): void;

    /**
     * Remove a previously set Cache-Control header
     */
     removeCacheControlHeader(response: Response): void;
}

Caching Policies are:

export type CachingPolicy =  'SHARED' | 'PRIVATE_IF_AUTHENTICATED' | 'NEVER' | 'ONLY_FOR_ANONYMOUS_USERS';

FAQs

Last updated on 06 Apr 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc