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

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,18 @@
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
13
- * issues. If host is localhost:8088, this will default to true
14
- * @returns Returns { body, status, headers } on success
12
+ * @returns { body, status, headers } on success
15
13
  */
16
14
  declare const sendRequest: (opts: {
17
- host: string;
18
15
  path: string;
16
+ host?: string;
19
17
  method?: ('GET' | 'POST' | 'PUT' | 'DELETE');
20
18
  params?: {
21
19
  [x: string]: any;
@@ -24,7 +22,6 @@ declare const sendRequest: (opts: {
24
22
  [x: string]: any;
25
23
  };
26
24
  numRetries?: number;
27
- ignoreSSLIssues?: boolean;
28
25
  }) => Promise<{
29
26
  body: any;
30
27
  status: number;
package/lib/index.js CHANGED
@@ -53,32 +53,27 @@ 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
77
- * issues. If host is localhost:8088, this will default to true
78
- * @returns Returns { body, status, headers } on success
73
+ * @returns { body, status, headers } on success
79
74
  */
80
75
  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;
76
+ var numRetries, method, stringifiedParams, query, url, headers, data, response, err_1;
82
77
  return __generator(this, function (_a) {
83
78
  switch (_a.label) {
84
79
  case 0:
@@ -96,12 +91,6 @@ var sendRequest = function (opts) { return __awaiter(void 0, void 0, void 0, fun
96
91
  else {
97
92
  url = "https://".concat(opts.host).concat(opts.path).concat(query);
98
93
  }
99
- ignoreSSLIssues = (opts.ignoreSSLIssues !== undefined
100
- ? opts.ignoreSSLIssues
101
- : opts.host === 'localhost:8088');
102
- httpsAgent = (ignoreSSLIssues
103
- ? ignoreSSLIssuesAgent
104
- : undefined);
105
94
  headers = opts.headers || {};
106
95
  data = null;
107
96
  if (!headers['Content-Type']) {
@@ -121,7 +110,6 @@ var sendRequest = function (opts) { return __awaiter(void 0, void 0, void 0, fun
121
110
  method: method,
122
111
  url: url,
123
112
  data: data,
124
- httpsAgent: httpsAgent,
125
113
  headers: headers,
126
114
  withCredentials: sendCrossDomainCredentials,
127
115
  })];
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,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,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.16",
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",
@@ -19,13 +19,14 @@
19
19
  "request",
20
20
  "CACCL"
21
21
  ],
22
- "author": "Gabriel Abrams <gabeabrams@gmail.com>",
22
+ "author": "Gabe Abrams <gabeabrams@gmail.com>",
23
23
  "license": "MIT",
24
24
  "bugs": {
25
25
  "url": "https://github.com/harvard-edtech/caccl-send-request/issues"
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
+ "caccl-error": "^2.0.0-beta.15",
41
+ "axios": "^0.21.4",
42
42
  "qs": "^6.9.6"
43
43
  }
44
44
  }
package/src/index.ts CHANGED
@@ -1,45 +1,37 @@
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
31
- * issues. If host is localhost:8088, this will default to true
32
- * @returns Returns { body, status, headers } on success
25
+ * @returns { body, status, headers } on success
33
26
  */
34
27
  const sendRequest = async (
35
28
  opts: {
36
- host: string,
37
29
  path: string,
30
+ host?: string,
38
31
  method?: ('GET' | 'POST' | 'PUT' | 'DELETE'),
39
32
  params?: { [k in string]: any },
40
33
  headers?: { [k in string]: any },
41
34
  numRetries?: number,
42
- ignoreSSLIssues?: boolean,
43
35
  },
44
36
  ): Promise<{
45
37
  body: any,
@@ -68,20 +60,6 @@ const sendRequest = async (
68
60
  url = `https://${opts.host}${opts.path}${query}`;
69
61
  }
70
62
 
71
- // Default ignoreSSLIssues
72
- const ignoreSSLIssues = (
73
- opts.ignoreSSLIssues !== undefined
74
- ? opts.ignoreSSLIssues
75
- : opts.host === 'localhost:8088'
76
- );
77
-
78
- // Prep to ignore ssl issues
79
- const httpsAgent = (
80
- ignoreSSLIssues
81
- ? ignoreSSLIssuesAgent
82
- : undefined
83
- );
84
-
85
63
  // Update headers
86
64
  const headers = opts.headers || {};
87
65
  let data = null;
@@ -101,7 +79,6 @@ const sendRequest = async (
101
79
  method,
102
80
  url,
103
81
  data,
104
- httpsAgent,
105
82
  headers,
106
83
  withCredentials: sendCrossDomainCredentials,
107
84
  });