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

parrot-fetch

Package Overview
Dependencies
Maintainers
2
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parrot-fetch - npm Package Compare versions

Comparing version 5.0.0-alpha.1 to 5.0.0

18

lib/index.js

@@ -8,7 +8,4 @@ "use strict";

exports.default = init;
var _ParrotFetch = _interopRequireDefault(require("./ParrotFetch"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/*

@@ -29,12 +26,10 @@ * Copyright (c) 2018 American Express Travel Related Services Company, Inc.

/* istanbul ignore next */
var context = typeof global === 'undefined' ? self : global; // eslint-disable-line no-restricted-globals
var contextFetch = context.fetch.bind(context);
var PARROT_STATE = 'PARROT_STATE';
const context = typeof global === 'undefined' ? self : global; // eslint-disable-line no-restricted-globals
const contextFetch = context.fetch.bind(context);
const PARROT_STATE = 'PARROT_STATE';
exports.PARROT_STATE = PARROT_STATE;
function init(scenarios, fetchWrapperParam) {
var fetchWrapper = fetchWrapperParam;
var parrotFetch; // option to mock a fetchClient that is different from the global fetch by passing the fetchClient in through a fetchWrapper object.
const fetchWrapper = fetchWrapperParam;
let parrotFetch;
// option to mock a fetchClient that is different from the global fetch by passing the fetchClient in through a fetchWrapper object.
if (fetchWrapper) {

@@ -47,4 +42,3 @@ parrotFetch = new _ParrotFetch.default(scenarios, contextFetch);

}
return parrotFetch;
}
"use strict";
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
Object.defineProperty(exports, "__esModule", {

@@ -9,95 +7,71 @@ value: true

exports.default = void 0;
var _parrotCore = _interopRequireDefault(require("parrot-core"));
var _urlParse = _interopRequireDefault(require("url-parse"));
var _excluded = ["method"],
_excluded2 = ["pathname", "query"];
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var ParrotFetch = /*#__PURE__*/function (_Parrot) {
_inherits(ParrotFetch, _Parrot);
var _super = _createSuper(ParrotFetch);
function ParrotFetch(scenarios, contextFetch) {
var _this;
_classCallCheck(this, ParrotFetch);
_this = _super.call(this, scenarios);
_defineProperty(_assertThisInitialized(_this), "normalizeRequest", function (input) {
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
_ref$method = _ref.method,
method = _ref$method === void 0 ? 'GET' : _ref$method,
init = _objectWithoutProperties(_ref, _excluded);
var _parse = (0, _urlParse.default)(input, true),
path = _parse.pathname,
query = _parse.query,
parsed = _objectWithoutProperties(_parse, _excluded2);
return _objectSpread(_objectSpread(_objectSpread({}, init), parsed), {}, {
path: path,
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } /*
* Copyright (c) 2018 American Express Travel Related Services Company, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
class ParrotFetch extends _parrotCore.default {
constructor(scenarios, contextFetch) {
super(scenarios);
_defineProperty(this, "normalizeRequest", (input, {
method = 'GET',
...init
} = {}) => {
const {
pathname: path,
query,
...parsed
} = (0, _urlParse.default)(input, true);
const headers = new Headers(init.headers);
let {
body
} = init;
if (headers.get('Content-Type') === 'application/json') {
body = JSON.parse(body);
}
return {
...init,
...parsed,
body,
path,
query: Object.keys(query) && query,
method: method && method.toUpperCase()
};
});
_defineProperty(this, "resolver", (input, init) => response => {
if (!response) {
return this.contextFetch(input, init);
}
const {
body,
status
} = response;
const responseBlob = new Blob([JSON.stringify(body)], {
type: 'application/json'
});
});
_defineProperty(_assertThisInitialized(_this), "resolver", function (input, init) {
return function (response) {
if (!response) {
return _this.contextFetch(input, init);
const responseOptions = {
status,
headers: {
'Content-Type': 'application/json'
}
var body = response.body,
status = response.status;
return Promise.resolve(new Response(new Blob([JSON.stringify(body)], {
status: status,
type: 'application/json'
})));
};
return Promise.resolve(new Response(responseBlob, responseOptions));
});
_this.contextFetch = contextFetch;
return _this;
this.contextFetch = contextFetch;
}
return _createClass(ParrotFetch);
}(_parrotCore.default);
}
var _default = ParrotFetch;
exports.default = _default;
{
"name": "parrot-fetch",
"version": "5.0.0-alpha.1",
"version": "5.0.0",
"contributors": [

@@ -23,12 +23,12 @@ "Jack Cross <jack.cross1@aexp.com>",

"dependencies": {
"parrot-core": "^5.0.0-alpha.1",
"url-parse": "^1.2.0"
"parrot-core": "^5.0.0",
"url-parse": "^1.5.10"
},
"devDependencies": {
"@babel/cli": "^7.8.4",
"@babel/core": "^7.7.7",
"babel-preset-amex": "^3.3.0",
"rimraf": "^3.0.0"
"@babel/cli": "^7.22.10",
"@babel/core": "^7.22.10",
"babel-preset-amex": "^3.6.1",
"rimraf": "^3.0.2"
},
"gitHead": "7b278cf36a1116f542306540b115b14b7a1c2b3c"
"gitHead": "6c0fec5c08acf46c345af36c43272909b209adf7"
}
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