@webex/http-core 3.0.0-beta.8 → 3.0.0-beta.81
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -1
- package/dist/http-error-subtypes.js +2 -147
- package/dist/http-error-subtypes.js.map +1 -1
- package/dist/http-error.js +9 -38
- package/dist/http-error.js.map +1 -1
- package/dist/index.js +5 -29
- package/dist/index.js.map +1 -1
- package/dist/interceptors/http-status.js +7 -30
- package/dist/interceptors/http-status.js.map +1 -1
- package/dist/lib/detect.js +28 -48
- package/dist/lib/detect.js.map +1 -1
- package/dist/lib/interceptor.js +7 -23
- package/dist/lib/interceptor.js.map +1 -1
- package/dist/lib/xhr.js +44 -93
- package/dist/lib/xhr.js.map +1 -1
- package/dist/progress-event.js +0 -7
- package/dist/progress-event.js.map +1 -1
- package/dist/request/index.js +1 -15
- package/dist/request/index.js.map +1 -1
- package/dist/request/request.js +5 -23
- package/dist/request/request.js.map +1 -1
- package/dist/request/request.shim.js +38 -90
- package/dist/request/request.shim.js.map +1 -1
- package/package.json +10 -10
- package/src/http-error-subtypes.js +1 -1
- package/src/http-error.js +15 -23
- package/src/index.js +4 -9
- package/src/interceptors/http-status.js +7 -5
- package/src/lib/detect.js +0 -1
- package/src/lib/interceptor.js +2 -4
- package/src/lib/xhr.js +197 -194
- package/src/progress-event.js +10 -5
- package/src/request/request.js +16 -14
- package/src/request/request.shim.js +47 -38
- package/test/integration/spec/http-error.js +11 -11
- package/test/integration/spec/interceptor.js +20 -13
- package/test/integration/spec/progress-event.js +8 -8
- package/test/integration/spec/request.js +135 -127
- package/test/unit/spec/interceptors/http-status.js +14 -11
package/dist/http-error.js
CHANGED
|
@@ -1,61 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _Reflect$construct = require("@babel/runtime-corejs2/core-js/reflect/construct");
|
|
4
|
-
|
|
5
4
|
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
|
6
|
-
|
|
7
5
|
var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
|
|
8
|
-
|
|
9
6
|
_Object$defineProperty(exports, "__esModule", {
|
|
10
7
|
value: true
|
|
11
8
|
});
|
|
12
|
-
|
|
13
9
|
exports.default = void 0;
|
|
14
|
-
|
|
15
10
|
var _defineProperties = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/define-properties"));
|
|
16
|
-
|
|
17
11
|
var _values = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/values"));
|
|
18
|
-
|
|
19
12
|
var _stringify = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/json/stringify"));
|
|
20
|
-
|
|
21
13
|
var _typeof2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/typeof"));
|
|
22
|
-
|
|
23
14
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/classCallCheck"));
|
|
24
|
-
|
|
25
15
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/createClass"));
|
|
26
|
-
|
|
27
16
|
var _inherits2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/inherits"));
|
|
28
|
-
|
|
29
17
|
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/possibleConstructorReturn"));
|
|
30
|
-
|
|
31
18
|
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/getPrototypeOf"));
|
|
32
|
-
|
|
33
19
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/defineProperty"));
|
|
34
|
-
|
|
35
20
|
var _pick2 = _interopRequireDefault(require("lodash/pick"));
|
|
36
|
-
|
|
37
21
|
var _common = require("@webex/common");
|
|
38
|
-
|
|
39
22
|
var _httpErrorSubtypes = _interopRequireDefault(require("./http-error-subtypes"));
|
|
40
|
-
|
|
41
23
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = _Reflect$construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
|
|
42
|
-
|
|
43
24
|
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; } }
|
|
44
|
-
|
|
45
25
|
/**
|
|
46
26
|
* Base HttpError class. Unlikely to be thrown directly, but handy for general
|
|
47
27
|
* type comparison.
|
|
48
28
|
*/
|
|
49
29
|
var HttpError = /*#__PURE__*/function (_Exception) {
|
|
50
30
|
(0, _inherits2.default)(HttpError, _Exception);
|
|
51
|
-
|
|
52
31
|
var _super = _createSuper(HttpError);
|
|
53
|
-
|
|
54
32
|
function HttpError() {
|
|
55
33
|
(0, _classCallCheck2.default)(this, HttpError);
|
|
56
34
|
return _super.apply(this, arguments);
|
|
57
35
|
}
|
|
58
|
-
|
|
59
36
|
(0, _createClass2.default)(HttpError, [{
|
|
60
37
|
key: "parse",
|
|
61
38
|
value:
|
|
@@ -84,11 +61,9 @@ var HttpError = /*#__PURE__*/function (_Exception) {
|
|
|
84
61
|
*/
|
|
85
62
|
function parse(res) {
|
|
86
63
|
// complexity is high here because of all the default values below.
|
|
87
|
-
|
|
88
64
|
/* eslint complexity: [0] */
|
|
89
65
|
var body = res.body;
|
|
90
66
|
var message;
|
|
91
|
-
|
|
92
67
|
switch ((0, _typeof2.default)(body)) {
|
|
93
68
|
case 'string':
|
|
94
69
|
try {
|
|
@@ -97,20 +72,15 @@ var HttpError = /*#__PURE__*/function (_Exception) {
|
|
|
97
72
|
} catch (err) {
|
|
98
73
|
message = body;
|
|
99
74
|
}
|
|
100
|
-
|
|
101
75
|
break;
|
|
102
|
-
|
|
103
76
|
case 'object':
|
|
104
77
|
message = this.parseObject(body);
|
|
105
78
|
break;
|
|
106
|
-
|
|
107
79
|
default:
|
|
108
80
|
}
|
|
109
|
-
|
|
110
81
|
if (!message) {
|
|
111
82
|
message = this.defaultMessage;
|
|
112
83
|
}
|
|
113
|
-
|
|
114
84
|
(0, _defineProperties.default)(this, {
|
|
115
85
|
body: {
|
|
116
86
|
enumerable: false,
|
|
@@ -163,36 +133,37 @@ var HttpError = /*#__PURE__*/function (_Exception) {
|
|
|
163
133
|
});
|
|
164
134
|
return message;
|
|
165
135
|
}
|
|
136
|
+
|
|
166
137
|
/**
|
|
167
138
|
* Recursively parses an error body looking for a likely error candidate
|
|
168
139
|
* @param {object} body
|
|
169
140
|
* @returns {string}
|
|
170
141
|
*/
|
|
171
|
-
|
|
172
142
|
}, {
|
|
173
143
|
key: "parseObject",
|
|
174
144
|
value: function parseObject(body) {
|
|
175
145
|
// Search body for common names of error strings
|
|
176
|
-
var messages = (0, _values.default)((0, _pick2.default)(body, HttpError.errorKeys));
|
|
146
|
+
var messages = (0, _values.default)((0, _pick2.default)(body, HttpError.errorKeys));
|
|
177
147
|
|
|
148
|
+
// If no error candidate was found, stringify the entire body
|
|
178
149
|
if (messages.length === 0) {
|
|
179
150
|
return (0, _stringify.default)(body, null, 2);
|
|
180
|
-
}
|
|
181
|
-
|
|
151
|
+
}
|
|
182
152
|
|
|
183
|
-
|
|
153
|
+
// Assume the first key found was the error explanation
|
|
154
|
+
var message = messages[0];
|
|
184
155
|
|
|
156
|
+
// If the explanation is an object, recurse and try again
|
|
185
157
|
if ((0, _typeof2.default)(message) === 'object') {
|
|
186
158
|
return this.parseObject(message);
|
|
187
|
-
}
|
|
188
|
-
|
|
159
|
+
}
|
|
189
160
|
|
|
161
|
+
// Return the first key
|
|
190
162
|
return message;
|
|
191
163
|
}
|
|
192
164
|
}]);
|
|
193
165
|
return HttpError;
|
|
194
166
|
}(_common.Exception);
|
|
195
|
-
|
|
196
167
|
exports.default = HttpError;
|
|
197
168
|
(0, _defineProperty2.default)(HttpError, "errorKeys", ['error', 'errorString', 'response', 'errorResponse', 'message', 'msg']);
|
|
198
169
|
(0, _defineProperty2.default)(HttpError, "defaultMessage", 'An error was received while trying to fulfill the request');
|
package/dist/http-error.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["HttpError","res","body","message","JSON","parse","parseObject","err","defaultMessage","enumerable","value","httpVersion","headers","rawHeaders","trailers","rawTrailers","method","url","statusCode","statusMessage","socket","_res","messages","errorKeys","length","Exception","makeSubTypes"],"sources":["http-error.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport {pick} from 'lodash';\nimport {Exception} from '@webex/common';\n\nimport makeSubTypes from './http-error-subtypes';\n\n/**\n * Base HttpError class. Unlikely to be thrown directly, but handy for general\n * type comparison.\n */\nexport default class HttpError extends Exception {\n /**\n * @example Extend via\n * MyError extends HttpError {\n * static errorKeys = HttpError.errorKeys.concat([\n * `key1`,\n * `key2`\n * ])\n * }\n *\n * @type {Array}\n */\n static errorKeys = [
|
|
1
|
+
{"version":3,"names":["HttpError","res","body","message","JSON","parse","parseObject","err","defaultMessage","enumerable","value","httpVersion","headers","rawHeaders","trailers","rawTrailers","method","url","statusCode","statusMessage","socket","_res","messages","errorKeys","length","Exception","makeSubTypes"],"sources":["http-error.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport {pick} from 'lodash';\nimport {Exception} from '@webex/common';\n\nimport makeSubTypes from './http-error-subtypes';\n\n/**\n * Base HttpError class. Unlikely to be thrown directly, but handy for general\n * type comparison.\n */\nexport default class HttpError extends Exception {\n /**\n * @example Extend via\n * MyError extends HttpError {\n * static errorKeys = HttpError.errorKeys.concat([\n * `key1`,\n * `key2`\n * ])\n * }\n *\n * @type {Array}\n */\n static errorKeys = ['error', 'errorString', 'response', 'errorResponse', 'message', 'msg'];\n\n /**\n * Default error string if no error can be extracted from the http response\n * @type {string}\n */\n static defaultMessage = 'An error was received while trying to fulfill the request';\n\n /**\n * Parses HttpResponse objects for useful information (status, headers, etc)\n * as well as attempting to extract a useful error message.\n * @param {HttpResponse} res\n * @returns {string}\n */\n parse(res) {\n // complexity is high here because of all the default values below.\n /* eslint complexity: [0] */\n let {body} = res;\n let message;\n\n switch (typeof body) {\n case 'string':\n try {\n body = JSON.parse(body);\n message = this.parseObject(body);\n } catch (err) {\n message = body;\n }\n break;\n case 'object':\n message = this.parseObject(body);\n break;\n default:\n }\n\n if (!message) {\n message = this.defaultMessage;\n }\n\n Object.defineProperties(this, {\n body: {\n enumerable: false,\n value: body,\n },\n httpVersion: {\n enumerable: false,\n value: res.httpVersion,\n },\n headers: {\n enumerable: false,\n value: res.headers || {},\n },\n rawHeaders: {\n enumerable: false,\n value: res.rawHeaders || [],\n },\n trailers: {\n enumerable: false,\n value: res.trailers || {},\n },\n rawTrailers: {\n enumerable: false,\n value: res.rawTrailers || [],\n },\n method: {\n enumerable: false,\n value: res.method,\n },\n url: {\n enumerable: false,\n value: res.url,\n },\n statusCode: {\n enumerable: false,\n value: res.statusCode,\n },\n statusMessage: {\n enumerable: false,\n value: res.statusMessage,\n },\n socket: {\n enumerable: false,\n value: res.socket,\n },\n _res: {\n enumerable: false,\n value: res,\n },\n });\n\n return message;\n }\n\n /**\n * Recursively parses an error body looking for a likely error candidate\n * @param {object} body\n * @returns {string}\n */\n parseObject(body) {\n // Search body for common names of error strings\n const messages = Object.values(pick(body, HttpError.errorKeys));\n\n // If no error candidate was found, stringify the entire body\n if (messages.length === 0) {\n return JSON.stringify(body, null, 2);\n }\n\n // Assume the first key found was the error explanation\n const message = messages[0];\n\n // If the explanation is an object, recurse and try again\n if (typeof message === 'object') {\n return this.parseObject(message);\n }\n\n // Return the first key\n return message;\n }\n}\n\nmakeSubTypes(HttpError);\nHttpError.makeSubTypes = makeSubTypes;\n"],"mappings":";;;;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U,EAAE,eAAe,EAAE,SAAS,EAAE,KAAK,CAAC;AAAA,8BAZvEA,SAAS,oBAkBJ,2DAA2D;AAkHrF,IAAA0B,0BAAY,EAAC1B,SAAS,CAAC;AACvBA,SAAS,CAAC0B,YAAY,GAAGA,0BAAY"}
|
package/dist/index.js
CHANGED
|
@@ -1,91 +1,68 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
|
4
|
-
|
|
5
4
|
var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
|
|
6
|
-
|
|
7
5
|
_Object$defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
|
-
|
|
11
8
|
_Object$defineProperty(exports, "HttpError", {
|
|
12
9
|
enumerable: true,
|
|
13
10
|
get: function get() {
|
|
14
11
|
return _httpError.default;
|
|
15
12
|
}
|
|
16
13
|
});
|
|
17
|
-
|
|
18
14
|
_Object$defineProperty(exports, "HttpStatusInterceptor", {
|
|
19
15
|
enumerable: true,
|
|
20
16
|
get: function get() {
|
|
21
17
|
return _httpStatus.default;
|
|
22
18
|
}
|
|
23
19
|
});
|
|
24
|
-
|
|
25
20
|
_Object$defineProperty(exports, "Interceptor", {
|
|
26
21
|
enumerable: true,
|
|
27
22
|
get: function get() {
|
|
28
23
|
return _interceptor.default;
|
|
29
24
|
}
|
|
30
25
|
});
|
|
31
|
-
|
|
32
26
|
_Object$defineProperty(exports, "ProgressEvent", {
|
|
33
27
|
enumerable: true,
|
|
34
28
|
get: function get() {
|
|
35
29
|
return _progressEvent.default;
|
|
36
30
|
}
|
|
37
31
|
});
|
|
38
|
-
|
|
39
32
|
exports.defaults = void 0;
|
|
40
|
-
|
|
41
33
|
_Object$defineProperty(exports, "detect", {
|
|
42
34
|
enumerable: true,
|
|
43
35
|
get: function get() {
|
|
44
36
|
return _detect.default;
|
|
45
37
|
}
|
|
46
38
|
});
|
|
47
|
-
|
|
48
39
|
exports.request = void 0;
|
|
49
|
-
|
|
50
40
|
var _getOwnPropertyDescriptor = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/reflect/get-own-property-descriptor"));
|
|
51
|
-
|
|
52
41
|
var _defineProperty = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/reflect/define-property"));
|
|
53
|
-
|
|
54
42
|
var _deleteProperty = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/reflect/delete-property"));
|
|
55
|
-
|
|
56
43
|
var _isString2 = _interopRequireDefault(require("lodash/isString"));
|
|
57
|
-
|
|
58
44
|
var _defaults2 = _interopRequireDefault(require("lodash/defaults"));
|
|
59
|
-
|
|
60
45
|
var _curry2 = _interopRequireDefault(require("lodash/curry"));
|
|
61
|
-
|
|
62
46
|
var _assign2 = _interopRequireDefault(require("lodash/assign"));
|
|
63
|
-
|
|
64
47
|
var _httpStatus = _interopRequireDefault(require("./interceptors/http-status"));
|
|
65
|
-
|
|
66
48
|
var _request2 = _interopRequireDefault(require("./request"));
|
|
67
|
-
|
|
68
49
|
var _progressEvent = _interopRequireDefault(require("./progress-event"));
|
|
69
|
-
|
|
70
50
|
var _interceptor = _interopRequireDefault(require("./lib/interceptor"));
|
|
71
|
-
|
|
72
51
|
var _httpError = _interopRequireDefault(require("./http-error"));
|
|
73
|
-
|
|
74
52
|
var _detect = _interopRequireDefault(require("./lib/detect"));
|
|
75
|
-
|
|
76
53
|
// Curry protorequest so we generate a function with default options built in.
|
|
77
54
|
var protorequest = (0, _curry2.default)(function protorequest(defaultOptions, options) {
|
|
78
55
|
// allow for options to be a string (and therefore expect options in the third
|
|
79
56
|
// position) to match request's api.
|
|
80
57
|
if ((0, _isString2.default)(options)) {
|
|
81
58
|
var uri = options;
|
|
82
|
-
/* eslint prefer-rest-params: [0] */
|
|
83
59
|
|
|
60
|
+
/* eslint prefer-rest-params: [0] */
|
|
84
61
|
options = arguments[2] || {};
|
|
85
62
|
options.uri = uri;
|
|
86
|
-
}
|
|
87
|
-
|
|
63
|
+
}
|
|
88
64
|
|
|
65
|
+
// Hide useless elements from logs
|
|
89
66
|
['download', 'interceptors', 'logger', 'upload'].forEach(function (prop) {
|
|
90
67
|
var descriptor = (0, _getOwnPropertyDescriptor.default)(options, prop);
|
|
91
68
|
descriptor = (0, _assign2.default)({}, descriptor, {
|
|
@@ -95,17 +72,16 @@ var protorequest = (0, _curry2.default)(function protorequest(defaultOptions, op
|
|
|
95
72
|
(0, _defineProperty.default)(options, prop, descriptor);
|
|
96
73
|
});
|
|
97
74
|
(0, _defaults2.default)(options, defaultOptions);
|
|
98
|
-
|
|
99
75
|
if (!options.json && options.json !== false) {
|
|
100
76
|
(0, _deleteProperty.default)(options, 'json');
|
|
101
77
|
}
|
|
102
|
-
|
|
103
78
|
options.logger = options.logger || this.logger || console;
|
|
104
79
|
return (0, _request2.default)(options);
|
|
105
80
|
});
|
|
106
81
|
var defaultOptions = {
|
|
107
82
|
json: true,
|
|
108
|
-
interceptors: [
|
|
83
|
+
interceptors: [
|
|
84
|
+
// Reminder: this is supposed to be an instantiated interceptor.
|
|
109
85
|
_httpStatus.default.create()]
|
|
110
86
|
};
|
|
111
87
|
var defaults = protorequest;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["protorequest","defaultOptions","options","uri","arguments","forEach","prop","descriptor","enumerable","writable","json","logger","console","_request","interceptors","HttpStatusInterceptor","create","defaults","request"],"sources":["index.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport {assign, curry, defaults as lodashDefaults, isString} from 'lodash';\n\nimport HttpStatusInterceptor from './interceptors/http-status';\nimport _request from './request';\n\n// Curry protorequest so we generate a function with default options built in.\nconst protorequest = curry(function protorequest(defaultOptions, options) {\n // allow for options to be a string (and therefore expect options in the third\n // position) to match request's api.\n if (isString(options)) {\n const uri = options;\n\n /* eslint prefer-rest-params: [0] */\n options = arguments[2] || {};\n options.uri = uri;\n }\n\n // Hide useless elements from logs\n [
|
|
1
|
+
{"version":3,"names":["protorequest","defaultOptions","options","uri","arguments","forEach","prop","descriptor","enumerable","writable","json","logger","console","_request","interceptors","HttpStatusInterceptor","create","defaults","request"],"sources":["index.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport {assign, curry, defaults as lodashDefaults, isString} from 'lodash';\n\nimport HttpStatusInterceptor from './interceptors/http-status';\nimport _request from './request';\n\n// Curry protorequest so we generate a function with default options built in.\nconst protorequest = curry(function protorequest(defaultOptions, options) {\n // allow for options to be a string (and therefore expect options in the third\n // position) to match request's api.\n if (isString(options)) {\n const uri = options;\n\n /* eslint prefer-rest-params: [0] */\n options = arguments[2] || {};\n options.uri = uri;\n }\n\n // Hide useless elements from logs\n ['download', 'interceptors', 'logger', 'upload'].forEach((prop) => {\n let descriptor = Reflect.getOwnPropertyDescriptor(options, prop);\n\n descriptor = assign({}, descriptor, {\n enumerable: false,\n writable: true,\n });\n Reflect.defineProperty(options, prop, descriptor);\n });\n\n lodashDefaults(options, defaultOptions);\n\n if (!options.json && options.json !== false) {\n Reflect.deleteProperty(options, 'json');\n }\n\n options.logger = options.logger || this.logger || console;\n\n return _request(options);\n});\n\nconst defaultOptions = {\n json: true,\n interceptors: [\n // Reminder: this is supposed to be an instantiated interceptor.\n HttpStatusInterceptor.create(),\n ],\n};\n\nexport const defaults = protorequest;\nexport const request = protorequest(defaultOptions);\nexport {default as ProgressEvent} from './progress-event';\nexport {default as Interceptor} from './lib/interceptor';\nexport {default as HttpError} from './http-error';\nexport {default as HttpStatusInterceptor} from './interceptors/http-status';\nexport {default as detect} from './lib/detect';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA;AACA;AA8CA;AACA;AACA;AAEA;AAhDA;AACA,IAAMA,YAAY,GAAG,qBAAM,SAASA,YAAY,CAACC,cAAc,EAAEC,O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
-
|
|
5
4
|
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
|
6
|
-
|
|
7
5
|
var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
|
|
8
|
-
|
|
9
6
|
_Object$defineProperty(exports, "__esModule", {
|
|
10
7
|
value: true
|
|
11
8
|
});
|
|
12
|
-
|
|
13
9
|
exports.default = void 0;
|
|
14
|
-
|
|
15
10
|
var _defineProperties = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/define-properties"));
|
|
16
|
-
|
|
17
11
|
var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
|
|
18
|
-
|
|
19
12
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/classCallCheck"));
|
|
20
|
-
|
|
21
13
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/createClass"));
|
|
22
|
-
|
|
23
14
|
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/assertThisInitialized"));
|
|
24
|
-
|
|
25
15
|
var _inherits2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/inherits"));
|
|
26
|
-
|
|
27
16
|
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/possibleConstructorReturn"));
|
|
28
|
-
|
|
29
17
|
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/getPrototypeOf"));
|
|
30
|
-
|
|
31
18
|
var _httpError = _interopRequireDefault(require("../http-error"));
|
|
32
|
-
|
|
33
19
|
var _interceptor = _interopRequireDefault(require("../lib/interceptor"));
|
|
34
|
-
|
|
35
20
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = _Reflect$construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
|
|
36
|
-
|
|
37
21
|
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; } }
|
|
38
|
-
|
|
39
22
|
var LOCUS_REDIRECT_ERROR = 2000002;
|
|
23
|
+
|
|
40
24
|
/**
|
|
41
25
|
* @class
|
|
42
26
|
*/
|
|
43
|
-
|
|
44
27
|
var HttpStatusInterceptor = /*#__PURE__*/function (_Interceptor) {
|
|
45
28
|
(0, _inherits2.default)(HttpStatusInterceptor, _Interceptor);
|
|
46
|
-
|
|
47
29
|
var _super = _createSuper(HttpStatusInterceptor);
|
|
48
|
-
|
|
49
30
|
/**
|
|
50
31
|
* @param {Object} webex
|
|
51
32
|
* @param {Object} options
|
|
@@ -53,7 +34,6 @@ var HttpStatusInterceptor = /*#__PURE__*/function (_Interceptor) {
|
|
|
53
34
|
*/
|
|
54
35
|
function HttpStatusInterceptor(webex, options) {
|
|
55
36
|
var _this;
|
|
56
|
-
|
|
57
37
|
(0, _classCallCheck2.default)(this, HttpStatusInterceptor);
|
|
58
38
|
_this = _super.call(this, webex);
|
|
59
39
|
var ErrorConstructor = options && (options.error || options.ErrorConstructor) || _httpError.default;
|
|
@@ -64,12 +44,11 @@ var HttpStatusInterceptor = /*#__PURE__*/function (_Interceptor) {
|
|
|
64
44
|
});
|
|
65
45
|
return _this;
|
|
66
46
|
}
|
|
47
|
+
|
|
67
48
|
/**
|
|
68
49
|
* @param {Object} options
|
|
69
50
|
* @returns {HttpStatusInterceptor}
|
|
70
51
|
*/
|
|
71
|
-
|
|
72
|
-
|
|
73
52
|
(0, _createClass2.default)(HttpStatusInterceptor, [{
|
|
74
53
|
key: "onResponse",
|
|
75
54
|
value:
|
|
@@ -82,17 +61,16 @@ var HttpStatusInterceptor = /*#__PURE__*/function (_Interceptor) {
|
|
|
82
61
|
if (response.statusCode) {
|
|
83
62
|
if (response.statusCode < 400) {
|
|
84
63
|
return _promise.default.resolve(response);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
64
|
+
}
|
|
65
|
+
// to handle locus redirects
|
|
88
66
|
if (response.statusCode === 404 && response.body && response.body.errorCode === LOCUS_REDIRECT_ERROR) {
|
|
89
67
|
return _promise.default.resolve(response);
|
|
90
68
|
}
|
|
91
|
-
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Note: the extra parenthesis below are required to make sure `new` is
|
|
92
72
|
// applied to the correct method (i.e., the result of `select()`, not
|
|
93
73
|
// `select()` itself).
|
|
94
|
-
|
|
95
|
-
|
|
96
74
|
return _promise.default.reject(new (this.ErrorConstructor.select(response.statusCode))(response));
|
|
97
75
|
}
|
|
98
76
|
}], [{
|
|
@@ -103,6 +81,5 @@ var HttpStatusInterceptor = /*#__PURE__*/function (_Interceptor) {
|
|
|
103
81
|
}]);
|
|
104
82
|
return HttpStatusInterceptor;
|
|
105
83
|
}(_interceptor.default);
|
|
106
|
-
|
|
107
84
|
exports.default = HttpStatusInterceptor;
|
|
108
85
|
//# sourceMappingURL=http-status.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["LOCUS_REDIRECT_ERROR","HttpStatusInterceptor","webex","options","ErrorConstructor","error","HttpError","value","response","statusCode","resolve","body","errorCode","reject","select","Interceptor"],"sources":["http-status.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport HttpError from '../http-error';\nimport Interceptor from '../lib/interceptor';\n\nconst LOCUS_REDIRECT_ERROR = 2000002;\n\n/**\n * @class\n */\nexport default class HttpStatusInterceptor extends Interceptor {\n /**\n * @param {Object} webex\n * @param {Object} options\n * @returns {HttpStatusInterceptor}\n */\n constructor(webex, options) {\n super(webex);\n const ErrorConstructor = options && (options.error || options.ErrorConstructor) || HttpError;\n\n Object.defineProperties(this, {\n ErrorConstructor: {\n value: ErrorConstructor
|
|
1
|
+
{"version":3,"names":["LOCUS_REDIRECT_ERROR","HttpStatusInterceptor","webex","options","ErrorConstructor","error","HttpError","value","response","statusCode","resolve","body","errorCode","reject","select","Interceptor"],"sources":["http-status.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport HttpError from '../http-error';\nimport Interceptor from '../lib/interceptor';\n\nconst LOCUS_REDIRECT_ERROR = 2000002;\n\n/**\n * @class\n */\nexport default class HttpStatusInterceptor extends Interceptor {\n /**\n * @param {Object} webex\n * @param {Object} options\n * @returns {HttpStatusInterceptor}\n */\n constructor(webex, options) {\n super(webex);\n const ErrorConstructor = (options && (options.error || options.ErrorConstructor)) || HttpError;\n\n Object.defineProperties(this, {\n ErrorConstructor: {\n value: ErrorConstructor,\n },\n });\n }\n\n /**\n * @param {Object} options\n * @returns {HttpStatusInterceptor}\n */\n static create(options) {\n return new HttpStatusInterceptor(this, options);\n }\n\n /**\n * @param {Object} options\n * @param {HttpResponse} response\n * @returns {Promise}\n */\n onResponse(options, response) {\n if (response.statusCode) {\n if (response.statusCode < 400) {\n return Promise.resolve(response);\n }\n // to handle locus redirects\n if (\n response.statusCode === 404 &&\n response.body &&\n response.body.errorCode === LOCUS_REDIRECT_ERROR\n ) {\n return Promise.resolve(response);\n }\n }\n\n // Note: the extra parenthesis below are required to make sure `new` is\n // applied to the correct method (i.e., the result of `select()`, not\n // `select()` itself).\n return Promise.reject(new (this.ErrorConstructor.select(response.statusCode))(response));\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAIA;AACA;AAA6C;AAAA;AAE7C,IAAMA,oBAAoB,GAAG,OAAO;;AAEpC;AACA;AACA;AAFA,IAGqBC,qBAAqB;EAAA;EAAA;EACxC;AACF;AACA;AACA;AACA;EACE,+BAAYC,KAAK,EAAEC,OAAO,EAAE;IAAA;IAAA;IAC1B,0BAAMD,KAAK;IACX,IAAME,gBAAgB,GAAID,OAAO,KAAKA,OAAO,CAACE,KAAK,IAAIF,OAAO,CAACC,gBAAgB,CAAC,IAAKE,kBAAS;IAE9F,4EAA8B;MAC5BF,gBAAgB,EAAE;QAChBG,KAAK,EAAEH;MACT;IACF,CAAC,CAAC;IAAC;EACL;;EAEA;AACF;AACA;AACA;EAHE;IAAA;IAAA;IAQA;AACF;AACA;AACA;AACA;IACE,oBAAWD,OAAO,EAAEK,QAAQ,EAAE;MAC5B,IAAIA,QAAQ,CAACC,UAAU,EAAE;QACvB,IAAID,QAAQ,CAACC,UAAU,GAAG,GAAG,EAAE;UAC7B,OAAO,iBAAQC,OAAO,CAACF,QAAQ,CAAC;QAClC;QACA;QACA,IACEA,QAAQ,CAACC,UAAU,KAAK,GAAG,IAC3BD,QAAQ,CAACG,IAAI,IACbH,QAAQ,CAACG,IAAI,CAACC,SAAS,KAAKZ,oBAAoB,EAChD;UACA,OAAO,iBAAQU,OAAO,CAACF,QAAQ,CAAC;QAClC;MACF;;MAEA;MACA;MACA;MACA,OAAO,iBAAQK,MAAM,CAAC,KAAK,IAAI,CAACT,gBAAgB,CAACU,MAAM,CAACN,QAAQ,CAACC,UAAU,CAAC,EAAED,QAAQ,CAAC,CAAC;IAC1F;EAAC;IAAA;IAAA,OA5BD,gBAAcL,OAAO,EAAE;MACrB,OAAO,IAAIF,qBAAqB,CAAC,IAAI,EAAEE,OAAO,CAAC;IACjD;EAAC;EAAA;AAAA,EAvBgDY,oBAAW;AAAA"}
|
package/dist/lib/detect.js
CHANGED
|
@@ -1,25 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
|
4
|
-
|
|
5
4
|
var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
|
|
6
|
-
|
|
7
5
|
_Object$defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
|
-
|
|
11
8
|
exports.default = detect;
|
|
12
|
-
|
|
13
9
|
var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs2/regenerator"));
|
|
14
|
-
|
|
15
10
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/asyncToGenerator"));
|
|
16
|
-
|
|
17
11
|
var _fileType = require("file-type");
|
|
18
|
-
|
|
19
12
|
/*!
|
|
20
13
|
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
21
14
|
*/
|
|
22
|
-
|
|
23
15
|
/**
|
|
24
16
|
* Determine mimeType for the specified buffer;
|
|
25
17
|
* @param {Buffer|Uint8Array|ArrayBuffer} buffer
|
|
@@ -28,50 +20,38 @@ var _fileType = require("file-type");
|
|
|
28
20
|
function detect(_x) {
|
|
29
21
|
return _detect.apply(this, arguments);
|
|
30
22
|
}
|
|
31
|
-
|
|
32
23
|
function _detect() {
|
|
33
24
|
_detect = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(buffer) {
|
|
34
25
|
var fileType;
|
|
35
26
|
return _regenerator.default.wrap(function _callee$(_context) {
|
|
36
|
-
while (1) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
_context.next =
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return _context.abrupt("return", 'application/octet-stream');
|
|
67
|
-
|
|
68
|
-
case 9:
|
|
69
|
-
return _context.abrupt("return", fileType.mime);
|
|
70
|
-
|
|
71
|
-
case 10:
|
|
72
|
-
case "end":
|
|
73
|
-
return _context.stop();
|
|
74
|
-
}
|
|
27
|
+
while (1) switch (_context.prev = _context.next) {
|
|
28
|
+
case 0:
|
|
29
|
+
if (!(!(buffer instanceof Blob) && !(buffer instanceof ArrayBuffer) && !(buffer instanceof Uint8Array))) {
|
|
30
|
+
_context.next = 2;
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
throw new Error('`detect` requires a buffer of type Blob, ArrayBuffer, or Uint8Array');
|
|
34
|
+
case 2:
|
|
35
|
+
if (!(buffer instanceof Blob)) {
|
|
36
|
+
_context.next = 4;
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
return _context.abrupt("return", buffer.type);
|
|
40
|
+
case 4:
|
|
41
|
+
_context.next = 6;
|
|
42
|
+
return (0, _fileType.fromBuffer)(buffer);
|
|
43
|
+
case 6:
|
|
44
|
+
fileType = _context.sent;
|
|
45
|
+
if (fileType) {
|
|
46
|
+
_context.next = 9;
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
return _context.abrupt("return", 'application/octet-stream');
|
|
50
|
+
case 9:
|
|
51
|
+
return _context.abrupt("return", fileType.mime);
|
|
52
|
+
case 10:
|
|
53
|
+
case "end":
|
|
54
|
+
return _context.stop();
|
|
75
55
|
}
|
|
76
56
|
}, _callee);
|
|
77
57
|
}));
|
package/dist/lib/detect.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["detect","buffer","Blob","ArrayBuffer","Uint8Array","Error","type","fromBuffer","fileType","mime"],"sources":["detect.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport {fromBuffer} from 'file-type';\n\n/**\n * Determine mimeType for the specified buffer;\n * @param {Buffer|Uint8Array|ArrayBuffer} buffer\n * @returns {Promise<string>}\n */\nexport default async function detect(buffer) {\n
|
|
1
|
+
{"version":3,"names":["detect","buffer","Blob","ArrayBuffer","Uint8Array","Error","type","fromBuffer","fileType","mime"],"sources":["detect.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport {fromBuffer} from 'file-type';\n\n/**\n * Determine mimeType for the specified buffer;\n * @param {Buffer|Uint8Array|ArrayBuffer} buffer\n * @returns {Promise<string>}\n */\nexport default async function detect(buffer) {\n if (\n !(buffer instanceof Blob) &&\n !(buffer instanceof ArrayBuffer) &&\n !(buffer instanceof Uint8Array)\n ) {\n throw new Error('`detect` requires a buffer of type Blob, ArrayBuffer, or Uint8Array');\n }\n\n if (buffer instanceof Blob) {\n return buffer.type;\n }\n\n // `fromBuffer()` can take a buffer that is either a ArrayBuffer or Uinit8Array\n const fileType = await fromBuffer(buffer);\n\n if (!fileType) {\n return 'application/octet-stream';\n }\n\n return fileType.mime;\n}\n"],"mappings":";;;;;;;;;;AAIA;AAJA;AACA;AACA;AAIA;AACA;AACA;AACA;AACA;AAJA,SAK8BA,MAAM;EAAA;AAAA;AAAA;EAAA,kFAArB,iBAAsBC,MAAM;IAAA;IAAA;MAAA;QAAA;UAAA,MAEvC,EAAEA,MAAM,YAAYC,IAAI,CAAC,IACzB,EAAED,MAAM,YAAYE,WAAW,CAAC,IAChC,EAAEF,MAAM,YAAYG,UAAU,CAAC;YAAA;YAAA;UAAA;UAAA,MAEzB,IAAIC,KAAK,CAAC,qEAAqE,CAAC;QAAA;UAAA,MAGpFJ,MAAM,YAAYC,IAAI;YAAA;YAAA;UAAA;UAAA,iCACjBD,MAAM,CAACK,IAAI;QAAA;UAAA;UAAA,OAIG,IAAAC,oBAAU,EAACN,MAAM,CAAC;QAAA;UAAnCO,QAAQ;UAAA,IAETA,QAAQ;YAAA;YAAA;UAAA;UAAA,iCACJ,0BAA0B;QAAA;UAAA,iCAG5BA,QAAQ,CAACC,IAAI;QAAA;QAAA;UAAA;MAAA;IAAA;EAAA,CACrB;EAAA;AAAA"}
|