@webex/http-core 3.0.0-beta.8 → 3.0.0-bnr.0

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 (50) hide show
  1. package/README.md +0 -1
  2. package/dist/http-error-subtypes.js +2 -147
  3. package/dist/http-error-subtypes.js.map +1 -1
  4. package/dist/http-error.js +9 -38
  5. package/dist/http-error.js.map +1 -1
  6. package/dist/index.js +5 -29
  7. package/dist/index.js.map +1 -1
  8. package/dist/interceptors/http-status.js +7 -30
  9. package/dist/interceptors/http-status.js.map +1 -1
  10. package/dist/lib/detect.js +28 -48
  11. package/dist/lib/detect.js.map +1 -1
  12. package/dist/lib/interceptor.js +7 -23
  13. package/dist/lib/interceptor.js.map +1 -1
  14. package/dist/lib/xhr.js +44 -93
  15. package/dist/lib/xhr.js.map +1 -1
  16. package/dist/progress-event.js +0 -7
  17. package/dist/progress-event.js.map +1 -1
  18. package/dist/request/index.js +1 -15
  19. package/dist/request/index.js.map +1 -1
  20. package/dist/request/request.js +5 -23
  21. package/dist/request/request.js.map +1 -1
  22. package/dist/request/request.shim.js +38 -90
  23. package/dist/request/request.shim.js.map +1 -1
  24. package/dist/types/http-error-subtypes.d.ts +8 -0
  25. package/dist/types/http-error.d.ts +41 -0
  26. package/dist/types/index.d.ts +7 -0
  27. package/dist/types/interceptors/http-status.d.ts +17 -0
  28. package/dist/types/lib/detect.d.ts +6 -0
  29. package/dist/types/lib/interceptor.d.ts +51 -0
  30. package/dist/types/lib/xhr.d.ts +6 -0
  31. package/dist/types/progress-event.d.ts +18 -0
  32. package/dist/types/request/index.d.ts +5 -0
  33. package/dist/types/request/request.d.ts +6 -0
  34. package/dist/types/request/request.shim.d.ts +6 -0
  35. package/package.json +10 -10
  36. package/src/http-error-subtypes.js +1 -1
  37. package/src/http-error.js +15 -23
  38. package/src/index.js +4 -9
  39. package/src/interceptors/http-status.js +7 -5
  40. package/src/lib/detect.js +0 -1
  41. package/src/lib/interceptor.js +2 -4
  42. package/src/lib/xhr.js +197 -194
  43. package/src/progress-event.js +10 -5
  44. package/src/request/request.js +16 -14
  45. package/src/request/request.shim.js +47 -38
  46. package/test/integration/spec/http-error.js +11 -11
  47. package/test/integration/spec/interceptor.js +20 -13
  48. package/test/integration/spec/progress-event.js +8 -8
  49. package/test/integration/spec/request.js +135 -127
  50. package/test/unit/spec/interceptors/http-status.js +14 -11
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @class
3
+ */
4
+ export default class HttpStatusInterceptor extends Interceptor {
5
+ /**
6
+ * @param {Object} options
7
+ * @returns {HttpStatusInterceptor}
8
+ */
9
+ static create(options: any): HttpStatusInterceptor;
10
+ /**
11
+ * @param {Object} webex
12
+ * @param {Object} options
13
+ * @returns {HttpStatusInterceptor}
14
+ */
15
+ constructor(webex: any, options: any);
16
+ }
17
+ import Interceptor from "../lib/interceptor";
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Determine mimeType for the specified buffer;
3
+ * @param {Buffer|Uint8Array|ArrayBuffer} buffer
4
+ * @returns {Promise<string>}
5
+ */
6
+ export default function detect(buffer: Buffer | Uint8Array | ArrayBuffer): Promise<string>;
@@ -0,0 +1,51 @@
1
+ /**
2
+ * @class
3
+ */
4
+ export default class Interceptor {
5
+ /**
6
+ * @abstract
7
+ * @returns {Interceptor}
8
+ */
9
+ static create(): Interceptor;
10
+ /**
11
+ * @constructor
12
+ * @param {Object} attrs
13
+ * @returns {UrlInterceptor}
14
+ */
15
+ constructor(attrs: any);
16
+ /**
17
+ * Logs the options of a request. This should be utilized
18
+ * during the intercepting process, but can be used at any
19
+ * time otherwise.
20
+ * @param {object} options
21
+ * @returns {void}
22
+ */
23
+ logOptions(options?: object): void;
24
+ /**
25
+ * Transform request options before sending them
26
+ * @param {Object} options
27
+ * @returns {Promise<Object>}
28
+ */
29
+ onRequest(options: any): Promise<any>;
30
+ /**
31
+ * Handle request failures
32
+ * @param {Object} options
33
+ * @param {Error} reason
34
+ * @returns {RejectedPromise<Error>}
35
+ */
36
+ onRequestError(options: any, reason: Error): RejectedPromise<Error>;
37
+ /**
38
+ * Transform response before returning it
39
+ * @param {Object} options
40
+ * @param {HttpResponse} response
41
+ * @returns {Promise<HttpResponse>}
42
+ */
43
+ onResponse(options: any, response: HttpResponse): Promise<HttpResponse>;
44
+ /**
45
+ * Handle response errors
46
+ * @param {Object} options
47
+ * @param {WebexHttpError} reason
48
+ * @returns {Promise<WebexHttpError>}
49
+ */
50
+ onResponseError(options: any, reason: WebexHttpError): Promise<WebexHttpError>;
51
+ }
@@ -0,0 +1,6 @@
1
+ export default createXHR;
2
+ declare function createXHR(uri: any, options: any, callback: any): any;
3
+ declare namespace createXHR {
4
+ const XMLHttpRequest: any;
5
+ const XDomainRequest: any;
6
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Object of the same shape as web browser ProgressEvents
3
+ * @class ProgressEvent
4
+ * @param {integer} loaded
5
+ * @param {integer} total
6
+ * @returns {ProgressEvent}
7
+ */
8
+ export default function ProgressEvent(loaded: integer, total: integer): ProgressEvent;
9
+ export default class ProgressEvent {
10
+ /**
11
+ * Object of the same shape as web browser ProgressEvents
12
+ * @class ProgressEvent
13
+ * @param {integer} loaded
14
+ * @param {integer} total
15
+ * @returns {ProgressEvent}
16
+ */
17
+ constructor(loaded: integer, total: integer);
18
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @param {Object} options
3
+ * @returns {Promise}
4
+ */
5
+ export default function request(options: any): Promise<any>;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @name request
3
+ * @param {Object} options
4
+ * @returns {Promise}
5
+ */
6
+ export default function _request(options: any): Promise<any>;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @name request
3
+ * @param {Object} options
4
+ * @returns {Promise}
5
+ */
6
+ export default function _request(options: any): Promise<any>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webex/http-core",
3
- "version": "3.0.0-beta.8",
3
+ "version": "3.0.0-bnr.0",
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.8",
28
- "@webex/test-helper-file": "3.0.0-beta.8",
29
- "@webex/test-helper-make-local-url": "3.0.0-beta.8",
30
- "@webex/test-helper-mocha": "3.0.0-beta.8",
27
+ "@webex/test-helper-chai": "3.0.0-bnr.0",
28
+ "@webex/test-helper-file": "3.0.0-bnr.0",
29
+ "@webex/test-helper-make-local-url": "3.0.0-bnr.0",
30
+ "@webex/test-helper-mocha": "3.0.0-bnr.0",
31
31
  "sinon": "^9.2.4"
32
32
  },
33
33
  "dependencies": {
34
- "@webex/common": "3.0.0-beta.8",
35
- "@webex/http-core": "3.0.0-beta.8",
36
- "@webex/internal-plugin-device": "3.0.0-beta.8",
37
- "@webex/test-helper-test-users": "3.0.0-beta.8",
38
- "@webex/webex-core": "3.0.0-beta.8",
34
+ "@webex/common": "3.0.0-bnr.0",
35
+ "@webex/http-core": "3.0.0-bnr.0",
36
+ "@webex/internal-plugin-device": "3.0.0-bnr.0",
37
+ "@webex/test-helper-test-users": "3.0.0-bnr.0",
38
+ "@webex/webex-core": "3.0.0-bnr.0",
39
39
  "file-type": "^16.0.1",
40
40
  "global": "^4.4.0",
41
41
  "is-function": "^1.0.1",
@@ -182,6 +182,6 @@ export default function makeSubTypes(Base) {
182
182
  statusCode = parseInt(statusCode, 10);
183
183
 
184
184
  return Base[statusCode] || Base;
185
- }
185
+ },
186
186
  });
187
187
  }
package/src/http-error.js CHANGED
@@ -23,14 +23,7 @@ export default class HttpError extends Exception {
23
23
  *
24
24
  * @type {Array}
25
25
  */
26
- static errorKeys = [
27
- 'error',
28
- 'errorString',
29
- 'response',
30
- 'errorResponse',
31
- 'message',
32
- 'msg'
33
- ];
26
+ static errorKeys = ['error', 'errorString', 'response', 'errorResponse', 'message', 'msg'];
34
27
 
35
28
  /**
36
29
  * Default error string if no error can be extracted from the http response
@@ -55,8 +48,7 @@ export default class HttpError extends Exception {
55
48
  try {
56
49
  body = JSON.parse(body);
57
50
  message = this.parseObject(body);
58
- }
59
- catch (err) {
51
+ } catch (err) {
60
52
  message = body;
61
53
  }
62
54
  break;
@@ -73,52 +65,52 @@ export default class HttpError extends Exception {
73
65
  Object.defineProperties(this, {
74
66
  body: {
75
67
  enumerable: false,
76
- value: body
68
+ value: body,
77
69
  },
78
70
  httpVersion: {
79
71
  enumerable: false,
80
- value: res.httpVersion
72
+ value: res.httpVersion,
81
73
  },
82
74
  headers: {
83
75
  enumerable: false,
84
- value: res.headers || {}
76
+ value: res.headers || {},
85
77
  },
86
78
  rawHeaders: {
87
79
  enumerable: false,
88
- value: res.rawHeaders || []
80
+ value: res.rawHeaders || [],
89
81
  },
90
82
  trailers: {
91
83
  enumerable: false,
92
- value: res.trailers || {}
84
+ value: res.trailers || {},
93
85
  },
94
86
  rawTrailers: {
95
87
  enumerable: false,
96
- value: res.rawTrailers || []
88
+ value: res.rawTrailers || [],
97
89
  },
98
90
  method: {
99
91
  enumerable: false,
100
- value: res.method
92
+ value: res.method,
101
93
  },
102
94
  url: {
103
95
  enumerable: false,
104
- value: res.url
96
+ value: res.url,
105
97
  },
106
98
  statusCode: {
107
99
  enumerable: false,
108
- value: res.statusCode
100
+ value: res.statusCode,
109
101
  },
110
102
  statusMessage: {
111
103
  enumerable: false,
112
- value: res.statusMessage
104
+ value: res.statusMessage,
113
105
  },
114
106
  socket: {
115
107
  enumerable: false,
116
- value: res.socket
108
+ value: res.socket,
117
109
  },
118
110
  _res: {
119
111
  enumerable: false,
120
- value: res
121
- }
112
+ value: res,
113
+ },
122
114
  });
123
115
 
124
116
  return message;
package/src/index.js CHANGED
@@ -20,17 +20,12 @@ const protorequest = curry(function protorequest(defaultOptions, options) {
20
20
  }
21
21
 
22
22
  // Hide useless elements from logs
23
- [
24
- 'download',
25
- 'interceptors',
26
- 'logger',
27
- 'upload'
28
- ].forEach((prop) => {
23
+ ['download', 'interceptors', 'logger', 'upload'].forEach((prop) => {
29
24
  let descriptor = Reflect.getOwnPropertyDescriptor(options, prop);
30
25
 
31
26
  descriptor = assign({}, descriptor, {
32
27
  enumerable: false,
33
- writable: true
28
+ writable: true,
34
29
  });
35
30
  Reflect.defineProperty(options, prop, descriptor);
36
31
  });
@@ -50,8 +45,8 @@ const defaultOptions = {
50
45
  json: true,
51
46
  interceptors: [
52
47
  // Reminder: this is supposed to be an instantiated interceptor.
53
- HttpStatusInterceptor.create()
54
- ]
48
+ HttpStatusInterceptor.create(),
49
+ ],
55
50
  };
56
51
 
57
52
  export const defaults = protorequest;
@@ -18,12 +18,12 @@ export default class HttpStatusInterceptor extends Interceptor {
18
18
  */
19
19
  constructor(webex, options) {
20
20
  super(webex);
21
- const ErrorConstructor = options && (options.error || options.ErrorConstructor) || HttpError;
21
+ const ErrorConstructor = (options && (options.error || options.ErrorConstructor)) || HttpError;
22
22
 
23
23
  Object.defineProperties(this, {
24
24
  ErrorConstructor: {
25
- value: ErrorConstructor
26
- }
25
+ value: ErrorConstructor,
26
+ },
27
27
  });
28
28
  }
29
29
 
@@ -46,9 +46,11 @@ export default class HttpStatusInterceptor extends Interceptor {
46
46
  return Promise.resolve(response);
47
47
  }
48
48
  // to handle locus redirects
49
- if (response.statusCode === 404 &&
49
+ if (
50
+ response.statusCode === 404 &&
50
51
  response.body &&
51
- response.body.errorCode === LOCUS_REDIRECT_ERROR) {
52
+ response.body.errorCode === LOCUS_REDIRECT_ERROR
53
+ ) {
52
54
  return Promise.resolve(response);
53
55
  }
54
56
  }
package/src/lib/detect.js CHANGED
@@ -10,7 +10,6 @@ import {fromBuffer} from 'file-type';
10
10
  * @returns {Promise<string>}
11
11
  */
12
12
  export default async function detect(buffer) {
13
- /* global Blob */
14
13
  if (
15
14
  !(buffer instanceof Blob) &&
16
15
  !(buffer instanceof ArrayBuffer) &&
@@ -20,7 +20,7 @@ export default class Interceptor {
20
20
 
21
21
  Reflect.defineProperty(this, key, {
22
22
  enumerable: true,
23
- value
23
+ value,
24
24
  });
25
25
  });
26
26
  }
@@ -43,9 +43,7 @@ export default class Interceptor {
43
43
  // prepend a header for the interceptor
44
44
  logger.info('/***** Interceptor ****************************************************\\');
45
45
 
46
- logger.info(
47
- `${this.constructor.name} - ${JSON.stringify(options, null, 2)}`
48
- );
46
+ logger.info(`${this.constructor.name} - ${JSON.stringify(options, null, 2)}`);
49
47
  }
50
48
 
51
49
  /**