@webex/http-core 3.0.0-beta.196 → 3.0.0-beta.197
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/dist/index.js +31 -1
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
- package/src/index.js +30 -0
- package/test/unit/spec/index.js +23 -1
package/dist/index.js
CHANGED
|
@@ -36,7 +36,7 @@ _Object$defineProperty(exports, "detect", {
|
|
|
36
36
|
return _detect.default;
|
|
37
37
|
}
|
|
38
38
|
});
|
|
39
|
-
exports.request = exports.protoprepareFetchOptions = void 0;
|
|
39
|
+
exports.setTimingsAndFetch = exports.request = exports.protoprepareFetchOptions = void 0;
|
|
40
40
|
var _getOwnPropertyDescriptor = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/reflect/get-own-property-descriptor"));
|
|
41
41
|
var _defineProperty = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/reflect/define-property"));
|
|
42
42
|
var _deleteProperty = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/reflect/delete-property"));
|
|
@@ -96,7 +96,37 @@ var protoprepareFetchOptions = (0, _curry2.default)(function protoprepareFetchOp
|
|
|
96
96
|
options.logger = options.logger || this.logger || console;
|
|
97
97
|
return (0, _utils.prepareFetchOptions)(options);
|
|
98
98
|
});
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Sets the $timings value(s) before the request/fetch.
|
|
102
|
+
* This function is only useful if you are about to send a request
|
|
103
|
+
* using prepared fetch options; normally it is done in webex.request();
|
|
104
|
+
*
|
|
105
|
+
* @param {any} options
|
|
106
|
+
* @returns {any} the updated options object
|
|
107
|
+
*/
|
|
99
108
|
exports.protoprepareFetchOptions = protoprepareFetchOptions;
|
|
109
|
+
var setRequestTimings = function setRequestTimings(options) {
|
|
110
|
+
var now = new Date().getTime();
|
|
111
|
+
options.$timings = options.$timings || {};
|
|
112
|
+
options.$timings.requestStart = now;
|
|
113
|
+
options.$timings.networkStart = now;
|
|
114
|
+
return options;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Submits a metric from pre-built request options via the fetch API. Updates
|
|
119
|
+
* the "$timings" values to Date.now() since the existing times were set when
|
|
120
|
+
* the options were built (not submitted).
|
|
121
|
+
*
|
|
122
|
+
* @param {any} options - the pre-built request options for submitting a metric
|
|
123
|
+
* @returns {Promise} promise that resolves to a response object
|
|
124
|
+
*/
|
|
125
|
+
var setTimingsAndFetch = function setTimingsAndFetch(options) {
|
|
126
|
+
// call the fetch API
|
|
127
|
+
return fetch(setRequestTimings(options));
|
|
128
|
+
};
|
|
129
|
+
exports.setTimingsAndFetch = setTimingsAndFetch;
|
|
100
130
|
var defaultOptions = {
|
|
101
131
|
json: true,
|
|
102
132
|
interceptors: [
|
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","protoprepareFetchOptions","_prepareFetchOptions","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';\nimport {prepareFetchOptions as _prepareFetchOptions} from './request/utils';\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\nexport const protoprepareFetchOptions = curry(function protoprepareFetchOptions(\n defaultOptions,\n options\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 _prepareFetchOptions(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;AACA;
|
|
1
|
+
{"version":3,"names":["protorequest","defaultOptions","options","uri","arguments","forEach","prop","descriptor","enumerable","writable","json","logger","console","_request","protoprepareFetchOptions","_prepareFetchOptions","setRequestTimings","now","Date","getTime","$timings","requestStart","networkStart","setTimingsAndFetch","fetch","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';\nimport {prepareFetchOptions as _prepareFetchOptions} from './request/utils';\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\nexport const protoprepareFetchOptions = curry(function protoprepareFetchOptions(\n defaultOptions,\n options\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 _prepareFetchOptions(options);\n});\n\n/**\n * Sets the $timings value(s) before the request/fetch.\n * This function is only useful if you are about to send a request\n * using prepared fetch options; normally it is done in webex.request();\n *\n * @param {any} options\n * @returns {any} the updated options object\n */\nconst setRequestTimings = (options) => {\n const now = new Date().getTime();\n options.$timings = options.$timings || {};\n options.$timings.requestStart = now;\n options.$timings.networkStart = now;\n\n return options;\n};\n\n/**\n * Submits a metric from pre-built request options via the fetch API. Updates\n * the \"$timings\" values to Date.now() since the existing times were set when\n * the options were built (not submitted).\n *\n * @param {any} options - the pre-built request options for submitting a metric\n * @returns {Promise} promise that resolves to a response object\n */\nexport const setTimingsAndFetch = (options) => {\n // call the fetch API\n return fetch(setRequestTimings(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;AACA;AAsGA;AACA;AACA;AAEA;AAxGA;AACA,IAAMA,YAAY,GAAG,qBAAM,SAASA,YAAY,CAACC,cAAc,EAAEC,OAAO,EAAE;EACxE;EACA;EACA,IAAI,wBAASA,OAAO,CAAC,EAAE;IACrB,IAAMC,GAAG,GAAGD,OAAO;;IAEnB;IACAA,OAAO,GAAGE,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAC5BF,OAAO,CAACC,GAAG,GAAGA,GAAG;EACnB;;EAEA;EACA,CAAC,UAAU,EAAE,cAAc,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAACE,OAAO,CAAC,UAACC,IAAI,EAAK;IACjE,IAAIC,UAAU,GAAG,uCAAiCL,OAAO,EAAEI,IAAI,CAAC;IAEhEC,UAAU,GAAG,sBAAO,CAAC,CAAC,EAAEA,UAAU,EAAE;MAClCC,UAAU,EAAE,KAAK;MACjBC,QAAQ,EAAE;IACZ,CAAC,CAAC;IACF,6BAAuBP,OAAO,EAAEI,IAAI,EAAEC,UAAU,CAAC;EACnD,CAAC,CAAC;EAEF,wBAAeL,OAAO,EAAED,cAAc,CAAC;EAEvC,IAAI,CAACC,OAAO,CAACQ,IAAI,IAAIR,OAAO,CAACQ,IAAI,KAAK,KAAK,EAAE;IAC3C,6BAAuBR,OAAO,EAAE,MAAM,CAAC;EACzC;EAEAA,OAAO,CAACS,MAAM,GA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,GAAG;EAEnC,OAAOf,OAAO;AAChB,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,IAAMqB,kBAAkB,GAAG,SAArBA,kBAAkB,CAAIrB,OAAO,EAAK;EAC7C;EACA,OAAOsB,KAAK,CAACR,iBAAiB,CAACd,OAAO,CAAC,CAAC;AAC1C,CAAC;AAAC;AAEF,IAAMD,cAAc,GAAG;EACrBS,IAAI,EAAE,IAAI;EACVe,YAAY,EAAE;EACZ;EACAC,mBAAqB,CAACC,MAAM,EAAE;AAElC,CAAC;AAEM,IAAMC,QAAQ,GAAG5B,YAAY;AAAC;AAC9B,IAAM6B,OAAO,GAAG7B,YAAY,CAACC,cAAc,CAAC;AAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webex/http-core",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.197",
|
|
4
4
|
"description": "Core HTTP library for the Cisco Webex",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -24,18 +24,18 @@
|
|
|
24
24
|
]
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@webex/test-helper-chai": "3.0.0-beta.
|
|
28
|
-
"@webex/test-helper-file": "3.0.0-beta.
|
|
29
|
-
"@webex/test-helper-make-local-url": "3.0.0-beta.
|
|
30
|
-
"@webex/test-helper-mocha": "3.0.0-beta.
|
|
27
|
+
"@webex/test-helper-chai": "3.0.0-beta.197",
|
|
28
|
+
"@webex/test-helper-file": "3.0.0-beta.197",
|
|
29
|
+
"@webex/test-helper-make-local-url": "3.0.0-beta.197",
|
|
30
|
+
"@webex/test-helper-mocha": "3.0.0-beta.197",
|
|
31
31
|
"sinon": "^9.2.4"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@webex/common": "3.0.0-beta.
|
|
35
|
-
"@webex/http-core": "3.0.0-beta.
|
|
36
|
-
"@webex/internal-plugin-device": "3.0.0-beta.
|
|
37
|
-
"@webex/test-helper-test-users": "3.0.0-beta.
|
|
38
|
-
"@webex/webex-core": "3.0.0-beta.
|
|
34
|
+
"@webex/common": "3.0.0-beta.197",
|
|
35
|
+
"@webex/http-core": "3.0.0-beta.197",
|
|
36
|
+
"@webex/internal-plugin-device": "3.0.0-beta.197",
|
|
37
|
+
"@webex/test-helper-test-users": "3.0.0-beta.197",
|
|
38
|
+
"@webex/webex-core": "3.0.0-beta.197",
|
|
39
39
|
"file-type": "^16.0.1",
|
|
40
40
|
"global": "^4.4.0",
|
|
41
41
|
"is-function": "^1.0.1",
|
package/src/index.js
CHANGED
|
@@ -68,6 +68,36 @@ export const protoprepareFetchOptions = curry(function protoprepareFetchOptions(
|
|
|
68
68
|
return _prepareFetchOptions(options);
|
|
69
69
|
});
|
|
70
70
|
|
|
71
|
+
/**
|
|
72
|
+
* Sets the $timings value(s) before the request/fetch.
|
|
73
|
+
* This function is only useful if you are about to send a request
|
|
74
|
+
* using prepared fetch options; normally it is done in webex.request();
|
|
75
|
+
*
|
|
76
|
+
* @param {any} options
|
|
77
|
+
* @returns {any} the updated options object
|
|
78
|
+
*/
|
|
79
|
+
const setRequestTimings = (options) => {
|
|
80
|
+
const now = new Date().getTime();
|
|
81
|
+
options.$timings = options.$timings || {};
|
|
82
|
+
options.$timings.requestStart = now;
|
|
83
|
+
options.$timings.networkStart = now;
|
|
84
|
+
|
|
85
|
+
return options;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Submits a metric from pre-built request options via the fetch API. Updates
|
|
90
|
+
* the "$timings" values to Date.now() since the existing times were set when
|
|
91
|
+
* the options were built (not submitted).
|
|
92
|
+
*
|
|
93
|
+
* @param {any} options - the pre-built request options for submitting a metric
|
|
94
|
+
* @returns {Promise} promise that resolves to a response object
|
|
95
|
+
*/
|
|
96
|
+
export const setTimingsAndFetch = (options) => {
|
|
97
|
+
// call the fetch API
|
|
98
|
+
return fetch(setRequestTimings(options));
|
|
99
|
+
};
|
|
100
|
+
|
|
71
101
|
const defaultOptions = {
|
|
72
102
|
json: true,
|
|
73
103
|
interceptors: [
|
package/test/unit/spec/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import sinon from 'sinon';
|
|
|
4
4
|
import * as utils from '@webex/http-core/src/request/utils';
|
|
5
5
|
import WebexTrackingIdInterceptor from '@webex/webex-core/src/interceptors/webex-tracking-id';
|
|
6
6
|
import UserAgentInterceptor from '@webex/webex-core/src/interceptors/webex-user-agent';
|
|
7
|
-
import {protoprepareFetchOptions} from '@webex/http-core/src/index';
|
|
7
|
+
import {protoprepareFetchOptions, setTimingsAndFetch} from '@webex/http-core/src/index';
|
|
8
8
|
|
|
9
9
|
describe('http-core index tests', () => {
|
|
10
10
|
describe('#protoprepareFetchOptions()', () => {
|
|
@@ -31,4 +31,26 @@ describe('http-core index tests', () => {
|
|
|
31
31
|
assert.isArray(options.interceptors);
|
|
32
32
|
});
|
|
33
33
|
});
|
|
34
|
+
|
|
35
|
+
describe('#setTimingsAndFetch()', () => {
|
|
36
|
+
const now = Date.now();
|
|
37
|
+
let stubbedFetch;
|
|
38
|
+
|
|
39
|
+
beforeEach(() => {
|
|
40
|
+
global.fetch = sinon.stub();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('calls fetch with expected options', async () => {
|
|
44
|
+
sinon.useFakeTimers(now);
|
|
45
|
+
const options = {};
|
|
46
|
+
|
|
47
|
+
const newOptions = setTimingsAndFetch(options);
|
|
48
|
+
|
|
49
|
+
sinon.assert.calledOnce(global.fetch);
|
|
50
|
+
sinon.assert.calledWith(global.fetch, {
|
|
51
|
+
$timings: {requestStart: now, networkStart: now},
|
|
52
|
+
});
|
|
53
|
+
sinon.restore();
|
|
54
|
+
});
|
|
55
|
+
});
|
|
34
56
|
});
|