Socket
Socket
Sign inDemoInstall

axios-cache-interceptor

Package Overview
Dependencies
Maintainers
1
Versions
78
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

axios-cache-interceptor - npm Package Compare versions

Comparing version 0.9.3 to 0.10.0

dev/index.cjs

32

package.json
{
"name": "axios-cache-interceptor",
"version": "0.9.3",
"version": "0.10.0",
"description": "Cache interceptor for axios",
"main": "./cjs/index.js",
"types": "./cjs/index.d.ts",
"module": "./esm/index.js",
"license": "MIT",
"main": "./dist/index.cjs",
"types": "./dist/index.d.ts",
"module": "./dist/index.mjs",
"exports": {
"./*": "./*",
"./package.json": "./package.json",
".": {
"import": "./esm/index.js",
"require": "./cjs/index.js",
"default": "./umd/index.js"
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
},
"./package.json": "./package.json"
"./dev": {
"import": "./dev/index.mjs",
"require": "./dev/index.cjs"
}
},
"browser": "./umd/index.js",
"jsdelivr": "./umd/index.js",
"unpkg": "./umd/index.js",
"browser": "./dist/index.umd.js",
"jsdelivr": "./dist/index.umd.js",
"unpkg": "./dist/index.umd.js",
"sideEffects": false,

@@ -34,3 +39,2 @@ "runkitExampleFilename": "./examples/runkit.js",

"homepage": "https://axios-cache-interceptor.js.org",
"license": "MIT",
"keywords": [

@@ -54,4 +58,4 @@ "axios",

"@types/webpack": "^5.28.0",
"@typescript-eslint/eslint-plugin": "^5.13.0",
"@typescript-eslint/parser": "^5.13.0",
"@typescript-eslint/eslint-plugin": "^5.14.0",
"@typescript-eslint/parser": "^5.14.0",
"auto-changelog": "^2.4.0",

@@ -58,0 +62,0 @@ "axios": "^0.26.0",

@@ -35,3 +35,3 @@ import type { Method } from 'axios';

*
* @default false
* @default true
*/

@@ -69,6 +69,6 @@ interpretHeader: boolean;

/**
* If the request should handle ETag and If-None-Match support. Use a string to force a
* custom value or true to use the response ETag
* If the request should handle `ETag` and `If-None-Match` support. Use a string to
* force a custom value or true to use the response ETag
*
* @default false
* @default true
* @link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag

@@ -79,6 +79,6 @@ */

/**
* Use If-Modified-Since header in this request. Use a date to force a custom value or
* Use `If-Modified-Since` header in this request. Use a date to force a custom value or
* true to use the last cached timestamp. If never cached before, the header is not set.
*
* @default false
* @default false // The opposite of the resulting `etag` option.
* @link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Modified-Since

@@ -93,4 +93,4 @@ */

*
* **Note**: If the response is treated as error because of invalid status code *(like
* from AxiosRequestConfig#invalidateStatus)*, and this ends up `true`, the cache will
* **Note**: If the response is treated as error because of invalid status code _(like
* from AxiosRequestConfig#invalidateStatus)_, and this ends up `true`, the cache will
* be preserved over the "invalid" request. So, if you want to preserve the response,

@@ -112,3 +112,3 @@ * you can use this predicate:

*
* @default false
* @default true
* @link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#stale-if-error

@@ -115,0 +115,0 @@ */

@@ -61,7 +61,11 @@ import type { AxiosInstance } from 'axios';

axiosCache.waiting = options.waiting || {};
axiosCache.generateKey = options.generateKey || defaultKeyGenerator;
axiosCache.waiting = options.waiting || {};
axiosCache.headerInterpreter = options.headerInterpreter || defaultHeaderInterpreter;
axiosCache.requestInterceptor =
options.requestInterceptor || defaultRequestInterceptor(axiosCache);
axiosCache.responseInterceptor =

@@ -73,12 +77,21 @@ options.responseInterceptor || defaultResponseInterceptor(axiosCache);

axiosCache.defaults.cache = {
update: options.update || {},
ttl: options.ttl ?? 1000 * 60 * 5,
interpretHeader: options.interpretHeader ?? false,
methods: options.methods || ['get'],
cachePredicate: options.cachePredicate || {
statusCheck: (status) => status >= 200 && status < 400
},
etag: options.etag ?? false,
modifiedSince: options.modifiedSince ?? false,
staleIfError: options.staleIfError ?? false,
update: options.update || {}
etag: options.etag ?? true,
// This option is going to be ignored by servers when ETag is enabled
// Checks strict equality to false to avoid undefined-ish values
modifiedSince: options.modifiedSince ?? options.etag === false,
interpretHeader: options.interpretHeader ?? true,
staleIfError: options.staleIfError ?? true
};

@@ -85,0 +98,0 @@

@@ -21,3 +21,3 @@ import { parse } from 'cache-parser';

if (immutable) {
// 1 year is sufficient, as Infinity may cause more problems.
// 1 year is sufficient, as Infinity may cause problems with certain storages.
// It might not be the best way, but a year is better than none.

@@ -24,0 +24,0 @@ return 1000 * 60 * 60 * 24 * 365;

@@ -33,5 +33,4 @@ export * from './cache/axios';

console.error(
'You are using a development build. Make sure to use the correct build in production'
'You are using a development build. Make sure to use the correct build in production\nhttps://axios-cache-interceptor.js.org/#/pages/installing\n\n'
);
console.error('https://axios-cache-interceptor.js.org/#/pages/installing');
}

@@ -1,6 +0,12 @@

import type { AxiosStorage } from '..';
import { buildStorage } from './build';
import type { StorageValue } from './types';
import type { AxiosStorage, StorageValue } from './types';
/**
* Modern function to natively deep clone
*
* @link https://caniuse.com/mdn-api_structuredclone (07/03/2022 -> 59.4%)
*/
declare const structuredClone: (<T>(value: T) => T) | undefined;
/**
* Creates a simple in-memory storage. This means that if you need to persist data between

@@ -26,11 +32,29 @@ * page or server reloads, this will not help.

* ```
*
* @param {boolean} cloneData If the data returned by `find()` should be cloned to avoid
* mutating the original data outside the `set()` method.
*/
export function buildMemoryStorage() {
export function buildMemoryStorage(cloneData = false) {
const storage = buildStorage({
find: (key) => storage.data[key],
set: (key, value) => {
storage.data[key] = value;
},
remove: (key) => {
delete storage.data[key];
},
find: (key) => {
const value = storage.data[key];
if (cloneData && value !== undefined) {
/* istanbul ignore if 'only available on super recent browsers' */
if (typeof structuredClone === 'function') {
return structuredClone(value);
}
return JSON.parse(JSON.stringify(value)) as StorageValue;
}
return value;
}

@@ -37,0 +61,0 @@ }) as MemoryStorage;

@@ -13,5 +13,5 @@ import type { CacheAxiosResponse } from '../cache/axios';

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const value = entries[cacheKey]!;
const updater = entries[cacheKey]!;
if (value === 'delete') {
if (updater === 'delete') {
await storage.remove(cacheKey);

@@ -21,9 +21,9 @@ continue;

const oldValue = await storage.get(cacheKey);
const value = await storage.get(cacheKey);
if (oldValue.state === 'loading') {
if (value.state === 'loading') {
continue;
}
const newValue = await value(oldValue, data);
const newValue = await updater(value, data);

@@ -35,8 +35,6 @@ if (newValue === 'delete') {

if (newValue === 'ignore') {
continue;
if (newValue !== 'ignore') {
await storage.set(cacheKey, newValue);
}
await storage.set(cacheKey, newValue);
}
}
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