@webex/http-core 2.59.3-next.1 → 2.59.4

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.
Files changed (43) hide show
  1. package/.eslintrc.js +6 -6
  2. package/README.md +64 -64
  3. package/babel.config.js +3 -3
  4. package/dist/http-error-subtypes.js +57 -57
  5. package/dist/http-error-subtypes.js.map +1 -1
  6. package/dist/http-error.js +25 -25
  7. package/dist/http-error.js.map +1 -1
  8. package/dist/index.js.map +1 -1
  9. package/dist/interceptors/http-status.js +13 -13
  10. package/dist/interceptors/http-status.js.map +1 -1
  11. package/dist/lib/detect.js +6 -6
  12. package/dist/lib/detect.js.map +1 -1
  13. package/dist/lib/interceptor.js +34 -34
  14. package/dist/lib/interceptor.js.map +1 -1
  15. package/dist/lib/xhr.js +2 -2
  16. package/dist/lib/xhr.js.map +1 -1
  17. package/dist/progress-event.js +6 -6
  18. package/dist/progress-event.js.map +1 -1
  19. package/dist/request/index.js +11 -11
  20. package/dist/request/index.js.map +1 -1
  21. package/dist/request/request.js +14 -14
  22. package/dist/request/request.js.map +1 -1
  23. package/dist/request/request.shim.js +65 -65
  24. package/dist/request/request.shim.js.map +1 -1
  25. package/jest.config.js +3 -3
  26. package/package.json +17 -18
  27. package/process +1 -1
  28. package/src/http-error-subtypes.js +187 -187
  29. package/src/http-error.js +147 -147
  30. package/src/index.js +58 -58
  31. package/src/interceptors/http-status.js +63 -63
  32. package/src/lib/detect.js +33 -33
  33. package/src/lib/interceptor.js +95 -95
  34. package/src/lib/xhr.js +258 -258
  35. package/src/progress-event.js +37 -37
  36. package/src/request/index.js +62 -62
  37. package/src/request/request.js +109 -109
  38. package/src/request/request.shim.js +304 -304
  39. package/test/integration/spec/http-error.js +188 -188
  40. package/test/integration/spec/interceptor.js +71 -71
  41. package/test/integration/spec/progress-event.js +83 -83
  42. package/test/integration/spec/request.js +310 -310
  43. package/test/unit/spec/interceptors/http-status.js +49 -49
@@ -1,188 +1,188 @@
1
- /*!
2
- * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
- */
4
-
5
- import {assert} from '@webex/test-helper-chai';
6
- import {HttpError} from '@webex/http-core';
7
-
8
- describe('http-core', () => {
9
- describe('HttpError', () => {
10
- it('has subtypes for all standard http errors', () => {
11
- assert.property(HttpError, 'BadRequest');
12
- assert.property(HttpError, 'Unauthorized');
13
- assert.property(HttpError, 'PaymentRequired');
14
- assert.property(HttpError, 'Forbidden');
15
- assert.property(HttpError, 'NotFound');
16
- assert.property(HttpError, 'MethodNotAllowed');
17
- assert.property(HttpError, 'NotAcceptable');
18
- assert.property(HttpError, 'ProxyAuthenticationRequired');
19
- assert.property(HttpError, 'RequestTimeout');
20
- assert.property(HttpError, 'Conflict');
21
- assert.property(HttpError, 'Gone');
22
- assert.property(HttpError, 'LengthRequired');
23
- assert.property(HttpError, 'PreconditionFailed');
24
- assert.property(HttpError, 'RequestEntityTooLarge');
25
- assert.property(HttpError, 'RequestUriTooLong');
26
- assert.property(HttpError, 'UnsupportedMediaType');
27
- assert.property(HttpError, 'RequestRangeNotSatisfiable');
28
- assert.property(HttpError, 'ExpectationFailed');
29
- assert.property(HttpError, 'TooManyRequests');
30
- assert.property(HttpError, 'InternalServerError');
31
- assert.property(HttpError, 'NotImplemented');
32
- assert.property(HttpError, 'BadGateway');
33
- assert.property(HttpError, 'ServiceUnavailable');
34
- assert.property(HttpError, 'GatewayTimeout');
35
- assert.property(HttpError, 'HttpVersionNotSupported');
36
- assert.property(HttpError, 'TooManyRequests');
37
- });
38
-
39
- it('has a subtype for network or CORS errors', () => {
40
- assert.property(HttpError, 'NetworkOrCORSError');
41
- });
42
-
43
- it('maps http status codes to their corresponding Error types', () => {
44
- assert.equal(HttpError[0], HttpError.NetworkOrCORSError);
45
- assert.equal(HttpError[400], HttpError.BadRequest);
46
- assert.equal(HttpError[401], HttpError.Unauthorized);
47
- assert.equal(HttpError[402], HttpError.PaymentRequired);
48
- assert.equal(HttpError[403], HttpError.Forbidden);
49
- assert.equal(HttpError[404], HttpError.NotFound);
50
- assert.equal(HttpError[405], HttpError.MethodNotAllowed);
51
- assert.equal(HttpError[406], HttpError.NotAcceptable);
52
- assert.equal(HttpError[407], HttpError.ProxyAuthenticationRequired);
53
- assert.equal(HttpError[408], HttpError.RequestTimeout);
54
- assert.equal(HttpError[409], HttpError.Conflict);
55
- assert.equal(HttpError[410], HttpError.Gone);
56
- assert.equal(HttpError[411], HttpError.LengthRequired);
57
- assert.equal(HttpError[412], HttpError.PreconditionFailed);
58
- assert.equal(HttpError[413], HttpError.RequestEntityTooLarge);
59
- assert.equal(HttpError[414], HttpError.RequestUriTooLong);
60
- assert.equal(HttpError[415], HttpError.UnsupportedMediaType);
61
- assert.equal(HttpError[416], HttpError.RequestRangeNotSatisfiable);
62
- assert.equal(HttpError[417], HttpError.ExpectationFailed);
63
- assert.equal(HttpError[429], HttpError.TooManyRequests);
64
- assert.equal(HttpError[500], HttpError.InternalServerError);
65
- assert.equal(HttpError[501], HttpError.NotImplemented);
66
- assert.equal(HttpError[502], HttpError.BadGateway);
67
- assert.equal(HttpError[503], HttpError.ServiceUnavailable);
68
- assert.equal(HttpError[504], HttpError.GatewayTimeout);
69
- assert.equal(HttpError[505], HttpError.HttpVersionNotSupported);
70
- });
71
-
72
- it('falls back to a default error message', () => {
73
- const res = {
74
- statusCode: 400,
75
- };
76
-
77
- const error = new HttpError(res);
78
-
79
- assert.equal(error.message, 'An error was received while trying to fulfill the request');
80
- });
81
-
82
- it('parses string responses', () => {
83
- const message = 'an error occurred';
84
- const res = {
85
- statusCode: 400,
86
- body: message,
87
- };
88
-
89
- const error = new HttpError(res);
90
-
91
- assert.equal(error.message, message);
92
- });
93
-
94
- it('parses JSON responses', () => {
95
- const message = {
96
- data: 'an error',
97
- };
98
-
99
- const res = {
100
- statusCode: 400,
101
- body: message,
102
- };
103
-
104
- const error = new HttpError(res);
105
-
106
- assert.equal(error.message, JSON.stringify(message, null, 2));
107
- });
108
-
109
- it('parses stringified JSON responses', () => {
110
- const message = JSON.stringify({
111
- data: 'an error',
112
- });
113
-
114
- const res = {
115
- statusCode: 400,
116
- body: message,
117
- };
118
-
119
- const error = new HttpError(res);
120
-
121
- assert.equal(error.message, JSON.stringify(JSON.parse(message), null, 2));
122
- });
123
-
124
- it('parses JSON responses for candidate error messages', () => {
125
- const message = 'an error occurred';
126
- const res = {
127
- statusCode: 400,
128
- body: {
129
- error: message,
130
- },
131
- };
132
-
133
- const error = new HttpError(res);
134
-
135
- assert.equal(error.message, message);
136
- });
137
-
138
- it('parses JSON responses for candidate error messages recursively', () => {
139
- const message = 'an error occurred';
140
- const res = {
141
- statusCode: 400,
142
- body: {
143
- error: {
144
- errorString: message,
145
- },
146
- },
147
- };
148
-
149
- const error = new HttpError(res);
150
-
151
- assert.equal(error.message, message);
152
- });
153
-
154
- describe('.select()', () => {
155
- it('determines the correct Error object for the specified status code', () => {
156
- assert.equal(HttpError.select(), HttpError);
157
- assert.equal(HttpError.select(0), HttpError.NetworkOrCORSError);
158
- assert.equal(HttpError.select(400), HttpError.BadRequest);
159
- assert.equal(HttpError.select(401), HttpError.Unauthorized);
160
- assert.equal(HttpError.select(402), HttpError.PaymentRequired);
161
- assert.equal(HttpError.select(403), HttpError.Forbidden);
162
- assert.equal(HttpError.select(404), HttpError.NotFound);
163
- assert.equal(HttpError.select(405), HttpError.MethodNotAllowed);
164
- assert.equal(HttpError.select(406), HttpError.NotAcceptable);
165
- assert.equal(HttpError.select(407), HttpError.ProxyAuthenticationRequired);
166
- assert.equal(HttpError.select(408), HttpError.RequestTimeout);
167
- assert.equal(HttpError.select(409), HttpError.Conflict);
168
- assert.equal(HttpError.select(410), HttpError.Gone);
169
- assert.equal(HttpError.select(411), HttpError.LengthRequired);
170
- assert.equal(HttpError.select(412), HttpError.PreconditionFailed);
171
- assert.equal(HttpError.select(413), HttpError.RequestEntityTooLarge);
172
- assert.equal(HttpError.select(414), HttpError.RequestUriTooLong);
173
- assert.equal(HttpError.select(415), HttpError.UnsupportedMediaType);
174
- assert.equal(HttpError.select(416), HttpError.RequestRangeNotSatisfiable);
175
- assert.equal(HttpError.select(417), HttpError.ExpectationFailed);
176
- assert.equal(HttpError.select(499), HttpError.BadRequest);
177
- assert.equal(HttpError.select(500), HttpError.InternalServerError);
178
- assert.equal(HttpError.select(501), HttpError.NotImplemented);
179
- assert.equal(HttpError.select(502), HttpError.BadGateway);
180
- assert.equal(HttpError.select(503), HttpError.ServiceUnavailable);
181
- assert.equal(HttpError.select(504), HttpError.GatewayTimeout);
182
- assert.equal(HttpError.select(505), HttpError.HttpVersionNotSupported);
183
- assert.equal(HttpError.select(599), HttpError.InternalServerError);
184
- assert.equal(HttpError.select(600), HttpError);
185
- });
186
- });
187
- });
188
- });
1
+ /*!
2
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+
5
+ import {assert} from '@webex/test-helper-chai';
6
+ import {HttpError} from '@webex/http-core';
7
+
8
+ describe('http-core', () => {
9
+ describe('HttpError', () => {
10
+ it('has subtypes for all standard http errors', () => {
11
+ assert.property(HttpError, 'BadRequest');
12
+ assert.property(HttpError, 'Unauthorized');
13
+ assert.property(HttpError, 'PaymentRequired');
14
+ assert.property(HttpError, 'Forbidden');
15
+ assert.property(HttpError, 'NotFound');
16
+ assert.property(HttpError, 'MethodNotAllowed');
17
+ assert.property(HttpError, 'NotAcceptable');
18
+ assert.property(HttpError, 'ProxyAuthenticationRequired');
19
+ assert.property(HttpError, 'RequestTimeout');
20
+ assert.property(HttpError, 'Conflict');
21
+ assert.property(HttpError, 'Gone');
22
+ assert.property(HttpError, 'LengthRequired');
23
+ assert.property(HttpError, 'PreconditionFailed');
24
+ assert.property(HttpError, 'RequestEntityTooLarge');
25
+ assert.property(HttpError, 'RequestUriTooLong');
26
+ assert.property(HttpError, 'UnsupportedMediaType');
27
+ assert.property(HttpError, 'RequestRangeNotSatisfiable');
28
+ assert.property(HttpError, 'ExpectationFailed');
29
+ assert.property(HttpError, 'TooManyRequests');
30
+ assert.property(HttpError, 'InternalServerError');
31
+ assert.property(HttpError, 'NotImplemented');
32
+ assert.property(HttpError, 'BadGateway');
33
+ assert.property(HttpError, 'ServiceUnavailable');
34
+ assert.property(HttpError, 'GatewayTimeout');
35
+ assert.property(HttpError, 'HttpVersionNotSupported');
36
+ assert.property(HttpError, 'TooManyRequests');
37
+ });
38
+
39
+ it('has a subtype for network or CORS errors', () => {
40
+ assert.property(HttpError, 'NetworkOrCORSError');
41
+ });
42
+
43
+ it('maps http status codes to their corresponding Error types', () => {
44
+ assert.equal(HttpError[0], HttpError.NetworkOrCORSError);
45
+ assert.equal(HttpError[400], HttpError.BadRequest);
46
+ assert.equal(HttpError[401], HttpError.Unauthorized);
47
+ assert.equal(HttpError[402], HttpError.PaymentRequired);
48
+ assert.equal(HttpError[403], HttpError.Forbidden);
49
+ assert.equal(HttpError[404], HttpError.NotFound);
50
+ assert.equal(HttpError[405], HttpError.MethodNotAllowed);
51
+ assert.equal(HttpError[406], HttpError.NotAcceptable);
52
+ assert.equal(HttpError[407], HttpError.ProxyAuthenticationRequired);
53
+ assert.equal(HttpError[408], HttpError.RequestTimeout);
54
+ assert.equal(HttpError[409], HttpError.Conflict);
55
+ assert.equal(HttpError[410], HttpError.Gone);
56
+ assert.equal(HttpError[411], HttpError.LengthRequired);
57
+ assert.equal(HttpError[412], HttpError.PreconditionFailed);
58
+ assert.equal(HttpError[413], HttpError.RequestEntityTooLarge);
59
+ assert.equal(HttpError[414], HttpError.RequestUriTooLong);
60
+ assert.equal(HttpError[415], HttpError.UnsupportedMediaType);
61
+ assert.equal(HttpError[416], HttpError.RequestRangeNotSatisfiable);
62
+ assert.equal(HttpError[417], HttpError.ExpectationFailed);
63
+ assert.equal(HttpError[429], HttpError.TooManyRequests);
64
+ assert.equal(HttpError[500], HttpError.InternalServerError);
65
+ assert.equal(HttpError[501], HttpError.NotImplemented);
66
+ assert.equal(HttpError[502], HttpError.BadGateway);
67
+ assert.equal(HttpError[503], HttpError.ServiceUnavailable);
68
+ assert.equal(HttpError[504], HttpError.GatewayTimeout);
69
+ assert.equal(HttpError[505], HttpError.HttpVersionNotSupported);
70
+ });
71
+
72
+ it('falls back to a default error message', () => {
73
+ const res = {
74
+ statusCode: 400,
75
+ };
76
+
77
+ const error = new HttpError(res);
78
+
79
+ assert.equal(error.message, 'An error was received while trying to fulfill the request');
80
+ });
81
+
82
+ it('parses string responses', () => {
83
+ const message = 'an error occurred';
84
+ const res = {
85
+ statusCode: 400,
86
+ body: message,
87
+ };
88
+
89
+ const error = new HttpError(res);
90
+
91
+ assert.equal(error.message, message);
92
+ });
93
+
94
+ it('parses JSON responses', () => {
95
+ const message = {
96
+ data: 'an error',
97
+ };
98
+
99
+ const res = {
100
+ statusCode: 400,
101
+ body: message,
102
+ };
103
+
104
+ const error = new HttpError(res);
105
+
106
+ assert.equal(error.message, JSON.stringify(message, null, 2));
107
+ });
108
+
109
+ it('parses stringified JSON responses', () => {
110
+ const message = JSON.stringify({
111
+ data: 'an error',
112
+ });
113
+
114
+ const res = {
115
+ statusCode: 400,
116
+ body: message,
117
+ };
118
+
119
+ const error = new HttpError(res);
120
+
121
+ assert.equal(error.message, JSON.stringify(JSON.parse(message), null, 2));
122
+ });
123
+
124
+ it('parses JSON responses for candidate error messages', () => {
125
+ const message = 'an error occurred';
126
+ const res = {
127
+ statusCode: 400,
128
+ body: {
129
+ error: message,
130
+ },
131
+ };
132
+
133
+ const error = new HttpError(res);
134
+
135
+ assert.equal(error.message, message);
136
+ });
137
+
138
+ it('parses JSON responses for candidate error messages recursively', () => {
139
+ const message = 'an error occurred';
140
+ const res = {
141
+ statusCode: 400,
142
+ body: {
143
+ error: {
144
+ errorString: message,
145
+ },
146
+ },
147
+ };
148
+
149
+ const error = new HttpError(res);
150
+
151
+ assert.equal(error.message, message);
152
+ });
153
+
154
+ describe('.select()', () => {
155
+ it('determines the correct Error object for the specified status code', () => {
156
+ assert.equal(HttpError.select(), HttpError);
157
+ assert.equal(HttpError.select(0), HttpError.NetworkOrCORSError);
158
+ assert.equal(HttpError.select(400), HttpError.BadRequest);
159
+ assert.equal(HttpError.select(401), HttpError.Unauthorized);
160
+ assert.equal(HttpError.select(402), HttpError.PaymentRequired);
161
+ assert.equal(HttpError.select(403), HttpError.Forbidden);
162
+ assert.equal(HttpError.select(404), HttpError.NotFound);
163
+ assert.equal(HttpError.select(405), HttpError.MethodNotAllowed);
164
+ assert.equal(HttpError.select(406), HttpError.NotAcceptable);
165
+ assert.equal(HttpError.select(407), HttpError.ProxyAuthenticationRequired);
166
+ assert.equal(HttpError.select(408), HttpError.RequestTimeout);
167
+ assert.equal(HttpError.select(409), HttpError.Conflict);
168
+ assert.equal(HttpError.select(410), HttpError.Gone);
169
+ assert.equal(HttpError.select(411), HttpError.LengthRequired);
170
+ assert.equal(HttpError.select(412), HttpError.PreconditionFailed);
171
+ assert.equal(HttpError.select(413), HttpError.RequestEntityTooLarge);
172
+ assert.equal(HttpError.select(414), HttpError.RequestUriTooLong);
173
+ assert.equal(HttpError.select(415), HttpError.UnsupportedMediaType);
174
+ assert.equal(HttpError.select(416), HttpError.RequestRangeNotSatisfiable);
175
+ assert.equal(HttpError.select(417), HttpError.ExpectationFailed);
176
+ assert.equal(HttpError.select(499), HttpError.BadRequest);
177
+ assert.equal(HttpError.select(500), HttpError.InternalServerError);
178
+ assert.equal(HttpError.select(501), HttpError.NotImplemented);
179
+ assert.equal(HttpError.select(502), HttpError.BadGateway);
180
+ assert.equal(HttpError.select(503), HttpError.ServiceUnavailable);
181
+ assert.equal(HttpError.select(504), HttpError.GatewayTimeout);
182
+ assert.equal(HttpError.select(505), HttpError.HttpVersionNotSupported);
183
+ assert.equal(HttpError.select(599), HttpError.InternalServerError);
184
+ assert.equal(HttpError.select(600), HttpError);
185
+ });
186
+ });
187
+ });
188
+ });
@@ -1,71 +1,71 @@
1
- /*!
2
- * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
- */
4
-
5
- import '@webex/internal-plugin-device';
6
-
7
- import {assert} from '@webex/test-helper-chai';
8
- import sinon from 'sinon';
9
- import WebexCore from '@webex/webex-core';
10
- import testUsers from '@webex/test-helper-test-users';
11
-
12
- describe('http-core', () => {
13
- describe('interceptor', () => {
14
- let webex;
15
-
16
- before('create users', () =>
17
- testUsers
18
- .create({count: 1})
19
- .then(
20
- ([user]) =>
21
- new Promise((resolve) => {
22
- setTimeout(() => resolve(user), 3000);
23
- })
24
- )
25
- .then((user) => {
26
- webex = new WebexCore({credentials: user.token});
27
- })
28
- .then(() => webex.internal.device.register())
29
- .then(() => webex.internal.services.waitForCatalog('postauth', 10))
30
- );
31
-
32
- describe('logOptions', () => {
33
- let flagged;
34
- let toggleVNL;
35
-
36
- before('check for verbose network logging and enable if needed', () => {
37
- // flag used to restore state of verbose network logging env variable
38
- flagged = !process.env.ENABLE_VERBOSE_NETWORK_LOGGING;
39
-
40
- // reused toggle that toggles verbose network logging env variable
41
- toggleVNL = () => {
42
- if (flagged) {
43
- process.env.ENABLE_VERBOSE_NETWORK_LOGGING =
44
- !process.env.ENABLE_VERBOSE_NETWORK_LOGGING;
45
- }
46
- };
47
-
48
- // toggle to enabled if disabled
49
- toggleVNL();
50
- });
51
-
52
- it('calls logger plugin', () => {
53
- const spy = sinon.spy(webex.logger, 'info');
54
-
55
- return webex
56
- .request({
57
- service: 'hydra',
58
- resource: 'people/me',
59
- })
60
- .then(() => {
61
- assert.called(spy);
62
- });
63
- });
64
-
65
- after('disable verbose network logging if needed', () => {
66
- // toggle to disabled if originally disabled
67
- toggleVNL();
68
- });
69
- });
70
- });
71
- });
1
+ /*!
2
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+
5
+ import '@webex/internal-plugin-device';
6
+
7
+ import {assert} from '@webex/test-helper-chai';
8
+ import sinon from 'sinon';
9
+ import WebexCore from '@webex/webex-core';
10
+ import testUsers from '@webex/test-helper-test-users';
11
+
12
+ describe('http-core', () => {
13
+ describe('interceptor', () => {
14
+ let webex;
15
+
16
+ before('create users', () =>
17
+ testUsers
18
+ .create({count: 1})
19
+ .then(
20
+ ([user]) =>
21
+ new Promise((resolve) => {
22
+ setTimeout(() => resolve(user), 3000);
23
+ })
24
+ )
25
+ .then((user) => {
26
+ webex = new WebexCore({credentials: user.token});
27
+ })
28
+ .then(() => webex.internal.device.register())
29
+ .then(() => webex.internal.services.waitForCatalog('postauth', 10))
30
+ );
31
+
32
+ describe('logOptions', () => {
33
+ let flagged;
34
+ let toggleVNL;
35
+
36
+ before('check for verbose network logging and enable if needed', () => {
37
+ // flag used to restore state of verbose network logging env variable
38
+ flagged = !process.env.ENABLE_VERBOSE_NETWORK_LOGGING;
39
+
40
+ // reused toggle that toggles verbose network logging env variable
41
+ toggleVNL = () => {
42
+ if (flagged) {
43
+ process.env.ENABLE_VERBOSE_NETWORK_LOGGING =
44
+ !process.env.ENABLE_VERBOSE_NETWORK_LOGGING;
45
+ }
46
+ };
47
+
48
+ // toggle to enabled if disabled
49
+ toggleVNL();
50
+ });
51
+
52
+ it('calls logger plugin', () => {
53
+ const spy = sinon.spy(webex.logger, 'info');
54
+
55
+ return webex
56
+ .request({
57
+ service: 'hydra',
58
+ resource: 'people/me',
59
+ })
60
+ .then(() => {
61
+ assert.called(spy);
62
+ });
63
+ });
64
+
65
+ after('disable verbose network logging if needed', () => {
66
+ // toggle to disabled if originally disabled
67
+ toggleVNL();
68
+ });
69
+ });
70
+ });
71
+ });