caccl-send-request 2.0.0-beta.0 → 2.0.0-beta.10

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 CHANGED
@@ -8,12 +8,6 @@ The default request sender used throughout the CACCL project.
8
8
  **C**onnection
9
9
  **L**ibrary
10
10
 
11
- ## Overriding caccl-send-request
12
-
13
- Throughout the `caccl` project, the default sendRequest function is this `caccl-send-request` module.
14
-
15
- However, if you want to override the sendRequest function, just create your own function that follows the description below. Your function should follow our description _exactly_, including sending of cross-origin credentials.
16
-
17
11
  ## Description
18
12
 
19
13
  Sends an http request, handles paging, retries failed requests, and processes the response.
@@ -28,7 +22,7 @@ headers | object | headers to include in the request | {}
28
22
  numRetries | number | number of times to retry the request if it fails | 0
29
23
  ignoreSSLIssues | boolean | if true, ignores self-signed certificate issues | false usually, true if host is `localhost:8088`
30
24
 
31
- Returns:
25
+ Returns:
32
26
  `Promise.<CACCLError|object>` Returns promise that resolves with `{ body, status, headers }` on success, rejects with CACCLError (see `caccl-error` on npm) on failure.
33
27
 
34
- **Note:** This function sends cross-origin credentials if `process.env.DEV` is true or if `process.env.NODE_ENV` equals `development`.
28
+ **Note:** This function sends cross-origin credentials if `process.env.NODE_ENV` equals `development`.
package/lib/index.d.ts CHANGED
@@ -2,20 +2,20 @@
2
2
  * Sends and retries an http request
3
3
  * @author Gabriel Abrams
4
4
  * @param opts object containing all arguments
5
- * @param opts.host host to send request to
6
5
  * @param opts.path path to send request to
6
+ * @param [opts.host] host to send request to
7
7
  * @param [opts.method=GET] http method to use
8
8
  * @param [opts.params] body/data to include in the request
9
9
  * @param [opts.headers] headers to include in the request
10
10
  * @param [opts.numRetries=0] number of times to retry the request if it
11
11
  * fails
12
- * @param [opts.ignoreSSLIssues=false] if true, ignores SSL certificate
12
+ * @param [opts.ignoreSSLIssues] if true, ignores SSL certificate
13
13
  * issues. If host is localhost:8088, this will default to true
14
- * @returns Returns { body, status, headers } on success
14
+ * @returns { body, status, headers } on success
15
15
  */
16
16
  declare const sendRequest: (opts: {
17
- host: string;
18
17
  path: string;
18
+ host?: string;
19
19
  method?: ('GET' | 'POST' | 'PUT' | 'DELETE');
20
20
  params?: {
21
21
  [x: string]: any;
package/lib/index.js CHANGED
@@ -53,32 +53,29 @@ Object.defineProperty(exports, "__esModule", { value: true });
53
53
  // Import libs
54
54
  var axios_1 = __importDefault(require("axios"));
55
55
  var qs_1 = __importDefault(require("qs"));
56
+ // Import other CACCL libs
56
57
  var caccl_error_1 = __importDefault(require("caccl-error"));
57
- var https_1 = __importDefault(require("https"));
58
58
  // Import shared types
59
59
  var ErrorCode_1 = __importDefault(require("./ErrorCode"));
60
- // Create an agent to ignore unauthorize ssl issues
61
- var ignoreSSLIssuesAgent = new https_1.default.Agent({ rejectUnauthorized: false });
62
60
  // Check if we should send cross-domain credentials
63
- var sendCrossDomainCredentials = !!(process.env.DEV
64
- || process.env.NODE_ENV === 'development');
61
+ var sendCrossDomainCredentials = (process.env.NODE_ENV === 'development');
65
62
  /**
66
63
  * Sends and retries an http request
67
64
  * @author Gabriel Abrams
68
65
  * @param opts object containing all arguments
69
- * @param opts.host host to send request to
70
66
  * @param opts.path path to send request to
67
+ * @param [opts.host] host to send request to
71
68
  * @param [opts.method=GET] http method to use
72
69
  * @param [opts.params] body/data to include in the request
73
70
  * @param [opts.headers] headers to include in the request
74
71
  * @param [opts.numRetries=0] number of times to retry the request if it
75
72
  * fails
76
- * @param [opts.ignoreSSLIssues=false] if true, ignores SSL certificate
73
+ * @param [opts.ignoreSSLIssues] if true, ignores SSL certificate
77
74
  * issues. If host is localhost:8088, this will default to true
78
- * @returns Returns { body, status, headers } on success
75
+ * @returns { body, status, headers } on success
79
76
  */
80
77
  var sendRequest = function (opts) { return __awaiter(void 0, void 0, void 0, function () {
81
- var numRetries, method, stringifiedParams, query, url, ignoreSSLIssues, httpsAgent, headers, data, response, err_1;
78
+ var numRetries, method, stringifiedParams, query, url, ignoreSSLIssues, headers, data, response, err_1;
82
79
  return __generator(this, function (_a) {
83
80
  switch (_a.label) {
84
81
  case 0:
@@ -99,9 +96,6 @@ var sendRequest = function (opts) { return __awaiter(void 0, void 0, void 0, fun
99
96
  ignoreSSLIssues = (opts.ignoreSSLIssues !== undefined
100
97
  ? opts.ignoreSSLIssues
101
98
  : opts.host === 'localhost:8088');
102
- httpsAgent = (ignoreSSLIssues
103
- ? ignoreSSLIssuesAgent
104
- : undefined);
105
99
  headers = opts.headers || {};
106
100
  data = null;
107
101
  if (!headers['Content-Type']) {
@@ -121,7 +115,6 @@ var sendRequest = function (opts) { return __awaiter(void 0, void 0, void 0, fun
121
115
  method: method,
122
116
  url: url,
123
117
  data: data,
124
- httpsAgent: httpsAgent,
125
118
  headers: headers,
126
119
  withCredentials: sendCrossDomainCredentials,
127
120
  })];
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,cAAc;AACd,gDAA0B;AAC1B,0CAAoB;AACpB,4DAAqC;AACrC,gDAA0B;AAE1B,sBAAsB;AACtB,0DAAoC;AAEpC,mDAAmD;AACnD,IAAM,oBAAoB,GAAG,IAAI,eAAK,CAAC,KAAK,CAAC,EAAE,kBAAkB,EAAE,KAAK,EAAE,CAAC,CAAC;AAE5E,mDAAmD;AACnD,IAAM,0BAA0B,GAAG,CAAC,CAAC,CACnC,OAAO,CAAC,GAAG,CAAC,GAAG;OACZ,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa,CAC1C,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,IAAM,WAAW,GAAG,UAClB,IAQC;;;;;gBAOK,UAAU,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBAGrD,MAAM,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C,OAAO,CAAC,QAAQ,CAAC,yBAAyB,CAAC,EAAE;oBACnD,MAAM,IAAI,qBAAU,CAAC;wBACnB,OAAO,EAAE,iFAAiF;wBAC1F,IAAI,EAAE,mBAAS,CAAC,UAAU;qBAC3B,CAAC,CAAC;iBACJ;gBAED,gBAAgB;gBAChB,MAAM,IAAI,qBAAU,CAAC;oBACnB,OAAO,EAAE,0GAA0G;oBACnH,IAAI,EAAE,mBAAS,CAAC,YAAY;iBAC7B,CAAC,CAAC;;;;KAEN,CAAC;AAEF,kBAAe,WAAW,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "caccl-send-request",
3
- "version": "2.0.0-beta.0",
3
+ "version": "2.0.0-beta.10",
4
4
  "description": "The default request sender used throughout the CACCL project.",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -26,6 +26,7 @@
26
26
  },
27
27
  "homepage": "https://github.com/harvard-edtech/caccl-send-request#readme",
28
28
  "devDependencies": {
29
+ "@types/browserify": "^12.0.37",
29
30
  "@types/node": "^17.0.17",
30
31
  "@types/qs": "^6.9.7",
31
32
  "eslint": "^8.9.0",
@@ -36,9 +37,8 @@
36
37
  "typescript": "^4.5.5"
37
38
  },
38
39
  "dependencies": {
39
- "axios": "^0.21.1",
40
- "caccl-error": "^2.0.0-beta.0",
41
- "https": "^1.0.0",
40
+ "axios": "^0.21.4",
41
+ "caccl-error": "^2.0.0-beta.10",
42
42
  "qs": "^6.9.6"
43
43
  }
44
44
  }
package/src/index.ts CHANGED
@@ -1,40 +1,35 @@
1
1
  // Import libs
2
2
  import axios from 'axios';
3
3
  import qs from 'qs';
4
+
5
+ // Import other CACCL libs
4
6
  import CACCLError from 'caccl-error';
5
- import https from 'https';
6
7
 
7
8
  // Import shared types
8
9
  import ErrorCode from './ErrorCode';
9
10
 
10
- // Create an agent to ignore unauthorize ssl issues
11
- const ignoreSSLIssuesAgent = new https.Agent({ rejectUnauthorized: false });
12
-
13
11
  // Check if we should send cross-domain credentials
14
- const sendCrossDomainCredentials = !!(
15
- process.env.DEV
16
- || process.env.NODE_ENV === 'development'
17
- );
12
+ const sendCrossDomainCredentials = (process.env.NODE_ENV === 'development');
18
13
 
19
14
  /**
20
15
  * Sends and retries an http request
21
16
  * @author Gabriel Abrams
22
17
  * @param opts object containing all arguments
23
- * @param opts.host host to send request to
24
18
  * @param opts.path path to send request to
19
+ * @param [opts.host] host to send request to
25
20
  * @param [opts.method=GET] http method to use
26
21
  * @param [opts.params] body/data to include in the request
27
22
  * @param [opts.headers] headers to include in the request
28
23
  * @param [opts.numRetries=0] number of times to retry the request if it
29
24
  * fails
30
- * @param [opts.ignoreSSLIssues=false] if true, ignores SSL certificate
25
+ * @param [opts.ignoreSSLIssues] if true, ignores SSL certificate
31
26
  * issues. If host is localhost:8088, this will default to true
32
- * @returns Returns { body, status, headers } on success
27
+ * @returns { body, status, headers } on success
33
28
  */
34
29
  const sendRequest = async (
35
30
  opts: {
36
- host: string,
37
31
  path: string,
32
+ host?: string,
38
33
  method?: ('GET' | 'POST' | 'PUT' | 'DELETE'),
39
34
  params?: { [k in string]: any },
40
35
  headers?: { [k in string]: any },
@@ -75,13 +70,6 @@ const sendRequest = async (
75
70
  : opts.host === 'localhost:8088'
76
71
  );
77
72
 
78
- // Prep to ignore ssl issues
79
- const httpsAgent = (
80
- ignoreSSLIssues
81
- ? ignoreSSLIssuesAgent
82
- : undefined
83
- );
84
-
85
73
  // Update headers
86
74
  const headers = opts.headers || {};
87
75
  let data = null;
@@ -101,7 +89,6 @@ const sendRequest = async (
101
89
  method,
102
90
  url,
103
91
  data,
104
- httpsAgent,
105
92
  headers,
106
93
  withCredentials: sendCrossDomainCredentials,
107
94
  });