@webex/http-core 3.5.0 → 3.6.0-next.1
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/request/index.js +6 -0
- package/dist/request/index.js.map +1 -1
- package/package.json +11 -11
- package/src/request/index.js +13 -4
- package/test/unit/spec/index.js +0 -1
- package/test/unit/spec/request/index.js +58 -0
package/dist/request/index.js
CHANGED
|
@@ -29,6 +29,12 @@ function request(options) {
|
|
|
29
29
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
30
30
|
args[_key] = arguments[_key];
|
|
31
31
|
}
|
|
32
|
+
// if provided own request function, use that instead
|
|
33
|
+
// there are use cases where developer may want to provide whatever request promise they wish
|
|
34
|
+
// for example, may even use window.postMessages for parent iframe uses cases
|
|
35
|
+
if (options.request) {
|
|
36
|
+
return options.request.apply(options, [options].concat(args));
|
|
37
|
+
}
|
|
32
38
|
return _request2.default.apply(void 0, [options].concat(args));
|
|
33
39
|
}).then(function () {
|
|
34
40
|
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_events","require","_request2","_interopRequireDefault","_utils","request","options","url","uri","headers","download","EventEmitter","upload","intercept","interceptors","then","_len","arguments","length","args","Array","_key","
|
|
1
|
+
{"version":3,"names":["_events","require","_request2","_interopRequireDefault","_utils","request","options","url","uri","headers","download","EventEmitter","upload","intercept","interceptors","then","_len","arguments","length","args","Array","_key","apply","concat","_request","_len2","_key2","slice","reverse"],"sources":["index.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport {EventEmitter} from 'events';\n\nimport _request from './request';\nimport {intercept} from './utils';\n\n/**\n * @param {Object} options\n * @returns {Promise}\n */\nexport default function request(options) {\n if (options.url) {\n options.uri = options.url;\n options.url = null;\n }\n\n options.headers = options.headers || {};\n\n options.download = new EventEmitter();\n options.upload = new EventEmitter();\n\n return intercept(options, options.interceptors, 'Request')\n .then((...args) => {\n // if provided own request function, use that instead\n // there are use cases where developer may want to provide whatever request promise they wish\n // for example, may even use window.postMessages for parent iframe uses cases\n if (options.request) {\n return options.request(options, ...args);\n }\n\n return _request(options, ...args);\n })\n .then((...args) => {\n return intercept(options, options.interceptors.slice().reverse(), 'Response', ...args);\n });\n}\n"],"mappings":";;;;;;;;AAIA,IAAAA,OAAA,GAAAC,OAAA;AAEA,IAAAC,SAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAPA;AACA;AACA;;AAOA;AACA;AACA;AACA;AACe,SAASI,OAAOA,CAACC,OAAO,EAAE;EACvC,IAAIA,OAAO,CAACC,GAAG,EAAE;IACfD,OAAO,CAACE,GAAG,GAAGF,OAAO,CAACC,GAAG;IACzBD,OAAO,CAACC,GAAG,GAAG,IAAI;EACpB;EAEAD,OAAO,CAACG,OAAO,GAAGH,OAAO,CAACG,OAAO,IAAI,CAAC,CAAC;EAEvCH,OAAO,CAACI,QAAQ,GAAG,IAAIC,oBAAY,CAAC,CAAC;EACrCL,OAAO,CAACM,MAAM,GAAG,IAAID,oBAAY,CAAC,CAAC;EAEnC,OAAO,IAAAE,gBAAS,EAACP,OAAO,EAAEA,OAAO,CAACQ,YAAY,EAAE,SAAS,CAAC,CACvDC,IAAI,CAAC,YAAa;IAAA,SAAAC,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAATC,IAAI,OAAAC,KAAA,CAAAJ,IAAA,GAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA;MAAJF,IAAI,CAAAE,IAAA,IAAAJ,SAAA,CAAAI,IAAA;IAAA;IACZ;IACA;IACA;IACA,IAAIf,OAAO,CAACD,OAAO,EAAE;MACnB,OAAOC,OAAO,CAACD,OAAO,CAAAiB,KAAA,CAAfhB,OAAO,GAASA,OAAO,EAAAiB,MAAA,CAAKJ,IAAI,EAAC;IAC1C;IAEA,OAAOK,iBAAQ,CAAAF,KAAA,UAAChB,OAAO,EAAAiB,MAAA,CAAKJ,IAAI,EAAC;EACnC,CAAC,CAAC,CACDJ,IAAI,CAAC,YAAa;IAAA,SAAAU,KAAA,GAAAR,SAAA,CAAAC,MAAA,EAATC,IAAI,OAAAC,KAAA,CAAAK,KAAA,GAAAC,KAAA,MAAAA,KAAA,GAAAD,KAAA,EAAAC,KAAA;MAAJP,IAAI,CAAAO,KAAA,IAAAT,SAAA,CAAAS,KAAA;IAAA;IACZ,OAAOb,gBAAS,CAAAS,KAAA,UAAChB,OAAO,EAAEA,OAAO,CAACQ,YAAY,CAACa,KAAK,CAAC,CAAC,CAACC,OAAO,CAAC,CAAC,EAAE,UAAU,EAAAL,MAAA,CAAKJ,IAAI,EAAC;EACxF,CAAC,CAAC;AACN"}
|
package/package.json
CHANGED
|
@@ -28,21 +28,21 @@
|
|
|
28
28
|
"@webex/eslint-config-legacy": "0.0.0",
|
|
29
29
|
"@webex/jest-config-legacy": "0.0.0",
|
|
30
30
|
"@webex/legacy-tools": "0.0.0",
|
|
31
|
-
"@webex/test-helper-chai": "3.
|
|
32
|
-
"@webex/test-helper-file": "3.
|
|
33
|
-
"@webex/test-helper-make-local-url": "3.
|
|
34
|
-
"@webex/test-helper-mocha": "3.
|
|
35
|
-
"@webex/test-helper-mock-webex": "3.
|
|
36
|
-
"@webex/test-helper-test-users": "3.
|
|
31
|
+
"@webex/test-helper-chai": "3.6.0-next.1",
|
|
32
|
+
"@webex/test-helper-file": "3.6.0-next.1",
|
|
33
|
+
"@webex/test-helper-make-local-url": "3.6.0-next.1",
|
|
34
|
+
"@webex/test-helper-mocha": "3.6.0-next.1",
|
|
35
|
+
"@webex/test-helper-mock-webex": "3.6.0-next.1",
|
|
36
|
+
"@webex/test-helper-test-users": "3.6.0-next.1",
|
|
37
37
|
"eslint": "^8.24.0",
|
|
38
38
|
"prettier": "^2.7.1",
|
|
39
39
|
"sinon": "^9.2.4"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@webex/common": "3.
|
|
43
|
-
"@webex/internal-plugin-device": "3.
|
|
44
|
-
"@webex/test-helper-test-users": "3.
|
|
45
|
-
"@webex/webex-core": "3.
|
|
42
|
+
"@webex/common": "3.6.0-next.1",
|
|
43
|
+
"@webex/internal-plugin-device": "3.6.0-next.1",
|
|
44
|
+
"@webex/test-helper-test-users": "3.6.0-next.1",
|
|
45
|
+
"@webex/webex-core": "3.6.0-next.1",
|
|
46
46
|
"file-type": "^16.0.1",
|
|
47
47
|
"global": "^4.4.0",
|
|
48
48
|
"is-function": "^1.0.1",
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"test:style": "eslint ./src/**/*.*",
|
|
64
64
|
"test:unit": "webex-legacy-tools test --unit --runner jest"
|
|
65
65
|
},
|
|
66
|
-
"version": "3.
|
|
66
|
+
"version": "3.6.0-next.1"
|
|
67
67
|
}
|
package/src/request/index.js
CHANGED
|
@@ -23,8 +23,17 @@ export default function request(options) {
|
|
|
23
23
|
options.upload = new EventEmitter();
|
|
24
24
|
|
|
25
25
|
return intercept(options, options.interceptors, 'Request')
|
|
26
|
-
.then((...args) =>
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
.then((...args) => {
|
|
27
|
+
// if provided own request function, use that instead
|
|
28
|
+
// there are use cases where developer may want to provide whatever request promise they wish
|
|
29
|
+
// for example, may even use window.postMessages for parent iframe uses cases
|
|
30
|
+
if (options.request) {
|
|
31
|
+
return options.request(options, ...args);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return _request(options, ...args);
|
|
35
|
+
})
|
|
36
|
+
.then((...args) => {
|
|
37
|
+
return intercept(options, options.interceptors.slice().reverse(), 'Response', ...args);
|
|
38
|
+
});
|
|
30
39
|
}
|
package/test/unit/spec/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {assert} from '@webex/test-helper-chai';
|
|
2
2
|
import sinon from 'sinon';
|
|
3
3
|
|
|
4
|
-
import * as utils from '@webex/http-core/src/request/utils';
|
|
5
4
|
import WebexTrackingIdInterceptor from '@webex/webex-core/src/interceptors/webex-tracking-id';
|
|
6
5
|
import UserAgentInterceptor from '@webex/webex-core/src/interceptors/webex-user-agent';
|
|
7
6
|
import {protoprepareFetchOptions, setTimingsAndFetch} from '@webex/http-core/src/index';
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import {assert} from '@webex/test-helper-chai';
|
|
2
|
+
import sinon from 'sinon';
|
|
3
|
+
import {EventEmitter} from 'events';
|
|
4
|
+
import request from '@webex/http-core/src/request';
|
|
5
|
+
import * as requestModule from '../../../../src/request/request';
|
|
6
|
+
import * as utils from '../../../../src/request/utils';
|
|
7
|
+
|
|
8
|
+
describe('request', () => {
|
|
9
|
+
let interceptStub;
|
|
10
|
+
let requestStub;
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
interceptStub = sinon.spy(utils, 'intercept');
|
|
14
|
+
requestStub = sinon.stub(requestModule, 'default');
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
afterEach(() => {
|
|
18
|
+
sinon.restore();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('should modify options and call _request if no custom request function is provided', async () => {
|
|
22
|
+
const options = {
|
|
23
|
+
url: 'http://example.com',
|
|
24
|
+
headers: {},
|
|
25
|
+
interceptors: [],
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
requestStub.resolves('response');
|
|
29
|
+
|
|
30
|
+
const result = await request(options);
|
|
31
|
+
|
|
32
|
+
assert.strictEqual(result, 'response');
|
|
33
|
+
assert.strictEqual(options.uri, 'http://example.com');
|
|
34
|
+
assert.isNull(options.url);
|
|
35
|
+
assert.deepEqual(options.headers, {});
|
|
36
|
+
assert.instanceOf(options.download, EventEmitter);
|
|
37
|
+
assert.instanceOf(options.upload, EventEmitter);
|
|
38
|
+
assert.isTrue(interceptStub.calledTwice);
|
|
39
|
+
assert.isTrue(requestStub.calledOnceWith(options));
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should use custom request function if provided', async () => {
|
|
43
|
+
const customRequest = sinon.stub().resolves('custom response');
|
|
44
|
+
const options = {
|
|
45
|
+
url: 'http://example.com',
|
|
46
|
+
headers: {},
|
|
47
|
+
interceptors: [],
|
|
48
|
+
request: customRequest,
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const result = await request(options);
|
|
52
|
+
|
|
53
|
+
assert.strictEqual(result, 'custom response');
|
|
54
|
+
assert.isTrue(customRequest.calledOnceWith(options));
|
|
55
|
+
assert.isTrue(interceptStub.calledTwice);
|
|
56
|
+
assert.isFalse(requestStub.called);
|
|
57
|
+
});
|
|
58
|
+
});
|