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

@americanexpress/fetch-enhancers

Package Overview
Dependencies
Maintainers
5
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@americanexpress/fetch-enhancers - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

7

CHANGELOG.md

@@ -0,1 +1,8 @@

## [1.0.3](https://github.com/americanexpress/fetch-enhancers/compare/v1.0.2...v1.0.3) (2020-09-08)
### Bug Fixes
* **createBrowserLikeFetch:** expires defaults to undefined ([#10](https://github.com/americanexpress/fetch-enhancers/issues/10)) ([4c82621](https://github.com/americanexpress/fetch-enhancers/commit/4c8262192227998627b208c9043d7261d48b33b4))
## [1.0.2](https://github.com/americanexpress/fetch-enhancers/compare/v1.0.1...v1.0.2) (2020-08-28)

@@ -2,0 +9,0 @@

73

es/fetch-enhancers.js

@@ -105,58 +105,2 @@ import abortController from 'abort-controller';

function _slicedToArray(arr, i) {
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
}
function _arrayWithHoles(arr) {
if (Array.isArray(arr)) return arr;
}
function _iterableToArrayLimit(arr, i) {
if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
var _arr = [];
var _n = true;
var _d = false;
var _e = undefined;
try {
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
_arr.push(_s.value);
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally {
try {
if (!_n && _i["return"] != null) _i["return"]();
} finally {
if (_d) throw _e;
}
}
return _arr;
}
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
/*

@@ -374,5 +318,6 @@ * Copyright 2020 American Express Travel Related Services Company, Inc

var key = cookie.key,
valueRaw = cookie.value,
cookieOptions = _objectWithoutProperties(cookie, ["key", "value"]);
var _cookie$toJSON = cookie.toJSON(),
key = _cookie$toJSON.key,
valueRaw = _cookie$toJSON.value,
cookieOptions = _objectWithoutProperties(_cookie$toJSON, ["key", "value"]);

@@ -384,11 +329,3 @@ try {

if (cookieDomain && ".".concat(cookieDomain).endsWith(".".concat(hostname.split('.').slice(-2).join('.')))) {
// remove null values from cookieOptions
var filteredOptions = Object.fromEntries(Object.entries(cookieOptions).filter(function (_ref2) {
var _ref3 = _slicedToArray(_ref2, 2),
propertyValue = _ref3[1];
return propertyValue != null;
}));
var expressCookieOptions = _objectSpread2(_objectSpread2({}, filteredOptions), filteredOptions.maxAge ? {
var expressCookieOptions = _objectSpread2(_objectSpread2({}, cookieOptions), cookieOptions.maxAge ? {
maxAge: cookieOptions.maxAge * 1e3

@@ -395,0 +332,0 @@ } : undefined);

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

"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("abort-controller")),r=e(require("tough-cookie"));function o(...e){const t=Error.apply(this,e);this.name="TimeoutError",this.message=t.message,this.stack=t.stack}o.prototype=Object.create(Error.prototype,{constructor:{value:o}});var n=o;var i=function(e){return r=>(o,i={})=>{const s=new t,c=s.signal,a=i.signal,u=i.timeout||e;let l;return a&&a.addEventListener("abort",function e(t,r){return()=>{t.abort(),r.removeEventListener("abort",e(t,r))}}(s,a)),Promise.race([r(o,{...i,signal:c}),new Promise((e,t)=>{setTimeout(()=>{l=!0,s.abort(),t(new n(`${o} after ${u}ms`))},u)})]).catch(e=>{if("AbortError"===e.name&&l)throw new n(`${o} after ${u}ms`);throw e})}};const s=(e,t)=>(Object.keys(t).forEach(r=>{Object.prototype.hasOwnProperty.call(e,r)&&"object"==typeof e[r]&&!Array.isArray(e[r])?s(e[r],t[r]):e[r]=t[r]}),e);var c=(e,...t)=>(t.forEach(t=>s(e,t)),e);const{CookieJar:a,parse:u}=r,l=()=>0;var h={createTimeoutFetch:i,createBrowserLikeFetch:function({headers:e={},hostname:t,res:r={cookie:l},setCookie:o,trustedDomains:n=[]}={}){r.cookie=o||r.cookie;const i=new a;return o=>(s,a={})=>{let l={...a};if(a.credentials&&((e,t)=>t.some(t=>new RegExp(t).test(e)))(s,n)){const t=((...e)=>e.filter(e=>e).join("; "))(e.cookie,i.getCookieStringSync(s));l=c(l,{headers:t?{...e,cookie:t}:e})}return o(s,l).then(e=>{if(a.credentials&&t){(e.headers.raw()["set-cookie"]||[]).forEach(e=>{const o=u(e),{key:n,value:c,...a}=o;try{const e=decodeURIComponent(c),u=a.domain;if(u&&("."+u).endsWith("."+t.split(".").slice(-2).join("."))){const t=Object.fromEntries(Object.entries(a).filter(([,e])=>null!=e)),o={...t,...t.maxAge?{maxAge:1e3*a.maxAge}:void 0};r.cookie(n,e,o)}i.setCookieSync(o,s)}catch(e){console.warn(`Warning: failed to set cookie "${n}" from path "${s}" with the following error, "${e.message}"`)}})}return e})}}},f=h.createTimeoutFetch,m=h.createBrowserLikeFetch;exports.createBrowserLikeFetch=m,exports.createTimeoutFetch=f,exports.default=h;
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("abort-controller")),o=e(require("tough-cookie"));function r(...e){const t=Error.apply(this,e);this.name="TimeoutError",this.message=t.message,this.stack=t.stack}r.prototype=Object.create(Error.prototype,{constructor:{value:r}});var a=r;var n=function(e){return o=>(r,n={})=>{const s=new t,c=s.signal,i=n.signal,u=n.timeout||e;let h;return i&&i.addEventListener("abort",function e(t,o){return()=>{t.abort(),o.removeEventListener("abort",e(t,o))}}(s,i)),Promise.race([o(r,{...n,signal:c}),new Promise((e,t)=>{setTimeout(()=>{h=!0,s.abort(),t(new a(`${r} after ${u}ms`))},u)})]).catch(e=>{if("AbortError"===e.name&&h)throw new a(`${r} after ${u}ms`);throw e})}};const s=(e,t)=>(Object.keys(t).forEach(o=>{Object.prototype.hasOwnProperty.call(e,o)&&"object"==typeof e[o]&&!Array.isArray(e[o])?s(e[o],t[o]):e[o]=t[o]}),e);var c=(e,...t)=>(t.forEach(t=>s(e,t)),e);const{CookieJar:i,parse:u}=o,h=()=>0;var l={createTimeoutFetch:n,createBrowserLikeFetch:function({headers:e={},hostname:t,res:o={cookie:h},setCookie:r,trustedDomains:a=[]}={}){o.cookie=r||o.cookie;const n=new i;return r=>(s,i={})=>{let h={...i};if(i.credentials&&((e,t)=>t.some(t=>new RegExp(t).test(e)))(s,a)){const t=((...e)=>e.filter(e=>e).join("; "))(e.cookie,n.getCookieStringSync(s));h=c(h,{headers:t?{...e,cookie:t}:e})}return r(s,h).then(e=>{if(i.credentials&&t){(e.headers.raw()["set-cookie"]||[]).forEach(e=>{const r=u(e),{key:a,value:c,...i}=r.toJSON();try{const e=decodeURIComponent(c),u=i.domain;if(u&&("."+u).endsWith("."+t.split(".").slice(-2).join("."))){const t={...i,...i.maxAge?{maxAge:1e3*i.maxAge}:void 0};o.cookie(a,e,t)}n.setCookieSync(r,s)}catch(e){console.warn(`Warning: failed to set cookie "${a}" from path "${s}" with the following error, "${e.message}"`)}})}return e})}}},m=l.createTimeoutFetch,f=l.createBrowserLikeFetch;exports.createBrowserLikeFetch=f,exports.createTimeoutFetch=m,exports.default=l;
{
"name": "@americanexpress/fetch-enhancers",
"version": "1.0.2",
"version": "1.0.3",
"description": "Set of enhancers to extend fetch",

@@ -5,0 +5,0 @@ "main": "lib/fetch-enhancers.js",

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