Skip to content
This repository has been archived by the owner on Mar 9, 2024. It is now read-only.

Commit

Permalink
Add responseType as a configurable option for browser/electron-based …
Browse files Browse the repository at this point in the history
…scenarios
  • Loading branch information
peterver committed Nov 18, 2018
1 parent 7190f7f commit 1c6c800
Show file tree
Hide file tree
Showing 22 changed files with 632 additions and 486 deletions.
91 changes: 91 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic
Versioning](https://semver.org/spec/v2.0.0.html).

## [1.5.0] - 2018-11-18
### Improved
- Updated outdated packages, moved to gulp 4 and @babel

### Added
- Added responseType as a configurable option for browser/electron based scenarios

### Breaking
- Removed `version` function in Net

### Added
- Started a changelog
- Added badges for downloads/version to Readme

## [1.4.1] - 2017-11-22
### Fixed
- Fixed issue where scenario selection went haywire in specific circumstances

## [1.4.0] - 2017-11-20
### Improved
- Improved readme in regards to options for data payloads on post/put calls

### Added
- Added scenario selection for Electron environment

## [1.3.3] - 2017-10-23
### Fixed
- Fixed wrong documentation in readme

## [1.3.2] - 2017-10-21
### Fixed
- Fixed issue where Scenario blueprint was imported instead of Respond

## [1.3.1] - 2017-10-21
### Fixed
- Fixed issue where Scenario blueprint was imported instead of Respond

## [1.3.0] - 2017-10-20
### Added
- Prebuild net into a dist folder to prevent people having to build locally
- Add scenario selection for Nodejs

### Improved
- Cleanup codebase for readability

### Breaking
- Remove responseType as a configurable options

## [1.2.6] - 2017-10-18
### Fixed
- minor bugfixes

## [1.2.5] - 2017-10-18
### Fixed
- minor bugfixes

## [1.2.4] - 2017-10-17
### Fixed
- minor bugfixes

## [1.2.3] - 2017-10-17
### Fixed
- minor bugfixes

## [1.2.2] - 2017-10-17
### Fixed
- minor bugfixes

## [1.2.1] - 2017-10-17
### Fixed
- Fix issue with key definitions

## [1.2.0] - 2017-10-16
### Added
- Add progress handling
- Allow data to be passed to request
- Add querystring parameters as option

### Improved
- Improve folder/filter structure for better readability

## [1.1.0] - 2017-08-21
### Added
- Add MIT License
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ Sets the timeout in ms to be used for the xhr call
- **withCredentials**<br> (default: false)
Sets the withCredentials property of the xhr call

- **responseType**<br> (default:'')
Sets the response type to be used for the xhr call (**will only be applied when using Net in browser/electron** not in node), possible options:
`arraybuffer,blob,document,json,text`

## Response :
The response object has the following keys
Expand Down
26 changes: 16 additions & 10 deletions dist/blueprints/Response.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
'use strict';

// Parses the response to a request and returns an object of form {status, data, headers, options}

Object.defineProperty(exports, "__esModule", {
value: !0
value: true
});
exports.default = void 0;

var _constants = require("../constants");

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

// Parses the response to a request and returns an object of form {status, data, headers, options}
var Response = function Response(code) {
var msg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
var data = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
var headers = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
var msg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
var data = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
var headers = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};

_classCallCheck(this, Response);
_classCallCheck(this, Response);

this.status = code && msg ? { code: code, msg: msg } : undefined;
this.data = (headers['content-type'] || '').indexOf('application/json') > -1 ? JSON.parse(data) : data;
this.headers = headers;
this.status = code && msg ? {
code: code,
msg: msg
} : undefined;
this.data = options.responseType === _constants.RESPONSE_TYPES.JSON || (headers['content-type'] || '').indexOf('application/json') > -1 ? JSON.parse(data) : data;
this.headers = headers;
};

exports.default = Response;
43 changes: 24 additions & 19 deletions dist/blueprints/Scenario.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: !0
value: true
});

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || !1; descriptor.configurable = !0; if ("value" in descriptor) descriptor.writable = !0; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
exports.default = void 0;

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Scenario = function () {
function Scenario() {
_classCallCheck(this, Scenario);
}
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); return Constructor; }

_createClass(Scenario, null, [{
key: 'run',
value: function run(options, cb) {
return new Promise(function (resolve, reject) {
try {
cb(resolve, reject);
} catch (err) {
reject(err);
}
});
var Scenario =
/*#__PURE__*/
function () {
function Scenario() {
_classCallCheck(this, Scenario);
}

_createClass(Scenario, null, [{
key: "run",
value: function run(options, cb) {
return new Promise(function (resolve, reject) {
try {
cb(resolve, reject);
} catch (err) {
reject(err);
}
}]);
});
}
}]);

return Scenario;
return Scenario;
}();

exports.default = Scenario;
41 changes: 25 additions & 16 deletions dist/constants.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
'use strict';

// VERBS
'use strict'; // VERBS

Object.defineProperty(exports, "__esModule", {
value: !0
value: true
});
exports.RESPONSE_TYPES = exports.METHODS_ALLOWED_BODY = exports.METHOD = void 0;

var _Object$freeze;

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }); } else { obj[key] = value; } return obj; }
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 METHOD = exports.METHOD = Object.freeze({
GET: 'Get',
PUT: 'Put',
PATCH: 'Patch',
POST: 'Post',
DELETE: 'Delete',
HEAD: 'Head',
OPTIONS: 'Options'
});
var METHOD = Object.freeze({
GET: 'Get',
PUT: 'Put',
PATCH: 'Patch',
POST: 'Post',
DELETE: 'Delete',
HEAD: 'Head',
OPTIONS: 'Options'
}); // VERBS Allowed to send data in body

// VERBS Allowed to send data in body
var METHODS_ALLOWED_BODY = exports.METHODS_ALLOWED_BODY = Object.freeze((_Object$freeze = {}, _defineProperty(_Object$freeze, METHOD.PUT, !0), _defineProperty(_Object$freeze, METHOD.POST, !0), _defineProperty(_Object$freeze, METHOD.PATCH, !0), _Object$freeze));
exports.METHOD = METHOD;
var METHODS_ALLOWED_BODY = Object.freeze((_Object$freeze = {}, _defineProperty(_Object$freeze, METHOD.PUT, true), _defineProperty(_Object$freeze, METHOD.POST, true), _defineProperty(_Object$freeze, METHOD.PATCH, true), _Object$freeze)); // RESPONSE TYPES

exports.METHODS_ALLOWED_BODY = METHODS_ALLOWED_BODY;
var RESPONSE_TYPES = Object.freeze({
ARRAY_BUFFER: 'arraybuffer',
BLOB: 'blob',
DOCUMENT: 'document',
JSON: 'json',
TEXT: 'text'
});
exports.RESPONSE_TYPES = RESPONSE_TYPES;
Loading

0 comments on commit 1c6c800

Please sign in to comment.