@financial-times/n-fastly-purger
TypeScript icon, indicating that this package has built-in type declarations

4.1.0 • Public • Published

n-fastly-purger

Lightweight, asynchronous Fastly purger.

npm i -P @financial-times/n-fastly-purger

Usage

import FastlyPurger from '@financial-times/n-fastly-purger';

const Fastly = new FastlyPurger({
    serviceId: 'fastlyServiceId',
    fastlyKey: 'fastlyAPIKey',
    timeout: 1000, // optional
    agent: new Agent({ keepAlive: true }), // optional; https agent
    silentMode: true, // optional; defaults to false
    loggerFn: sandbox.stub(), // optional
    logLevel: 'all' // optional; defaults to 'errors'
});

Options

Silent mode

  • silentMode: true: silent failure on purge error and boolean responses
  • silentMode: false: throw errors for failed purges; return JSON response from Fastly (status: ok and purge ID)

Logging

  • logLevel: 'errors': only log purge errors (default)
  • logLevel: 'all': log successful purges and purge errors
Logger function

A function to output logs; e.g.:

import logger from '@financial-times/n-logger'; 
// or n-serverless-logger

const Fastly = new FastlyPurger({ ...
    loggerFn: logger.error
});

Methods

Fastly.purgeKey('my-surrogate-key'); // purge a single key
Fastly.purgeKeys(['key-1', 'key-2']); // purge multiple surrogate keys
Fastly.purgeAll(); // purge the entire service
Fastly.purgeUrl('https://foo.com/bar'); // purge a single URL

Readme

Keywords

none

Package Sidebar

Install

npm i @financial-times/n-fastly-purger

Weekly Downloads

6

Version

4.1.0

License

ISC

Unpacked Size

869 kB

Total Files

37

Last publish

Collaborators

  • robertboulton
  • seraph2000
  • hamza.samih
  • notlee
  • emmalewis
  • aendra
  • the-ft
  • rowanmanning
  • chee
  • alexwilson