Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@rqt/aqt

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rqt/aqt - npm Package Compare versions

Comparing version 1.2.6 to 1.3.0

compile/aqt.js

6

CHANGELOG.md

@@ -0,1 +1,7 @@

## 29 July 2019
### [1.3.0](https://github.com/rqt/aqt/compare/v1.2.6...v1.3.0)
- [package] Compile package with [JavaScript Compiler](https://compiler.page).
## 3 July 2019

@@ -2,0 +8,0 @@

34

package.json
{
"name": "@rqt/aqt",
"version": "1.2.6",
"version": "1.3.0",
"description": "An Advanced Network Request Package That Returns Body (Parsed As JSON If Needed), Headers And Status After Gzip Decompression.",
"main": "build/index.js",
"main": "compile/index.js",
"module": "src/index.js",

@@ -10,16 +10,18 @@ "scripts": {

"test": "yarn t test/spec",
"test-build": "ALAMODE_ENV=test-build yarn test",
"doc": "NODE_DEBUG=doc doc -o README.md",
"d": "typal src/index.js -c -g",
"test-compile": "ALAMODE_ENV=test-compile yarn test",
"compile": "depack-dev src/depack -o compile/aqt.js -c -a -p -s --source_map_include_content",
"doc": "NODE_DEBUG=doc doc -o README.md -n _rqt",
"d": "yarn-s d1 dc",
"d1": "typal types/index.js types/externs.js",
"dc": "typal compile/index.js -c -t types/index.xml",
"lint": "eslint .",
"e": "alanode",
"example/": "yarn e example/example.js",
"b": "alamode src -o build -s",
"build": "yarn-s d b doc"
"example/": "yarn e example/example.js"
},
"files": [
"build",
"types",
"src"
"compile",
"src",
"types"
],
"externs": "types/externs.js",
"repository": {

@@ -49,3 +51,5 @@ "type": "git",

"alamode": "^2.3.4",
"catchment": "^3.3.0",
"documentary": "^1.27.4",
"erotic": "^2.1.1",
"eslint-config-artdeco": "1.0.1",

@@ -56,6 +60,6 @@ "https-context": "^1.0.3",

},
"dependencies": {
"catchment": "^3.3.0",
"erotic": "^2.1.1"
}
"srcDependencies": [
"catchment",
"erotic"
]
}

@@ -5,6 +5,6 @@ # @rqt/aqt

`aqt` is a network request package for Node.js that returns the body (parsed if returned as _JSON_), headers and status after _gzip_ decompression when necessary.
`aqt` is a network request package for Node.JS that returns the body (parsed if returned as _JSON_), headers and status after _gzip_ decompression when necessary.
```sh
yarn add -E @rqt/aqt
```console
yarn add @rqt/aqt
```

@@ -41,16 +41,89 @@

`import('http').OutgoingHttpHeaders` __<a name="type-httpoutgoinghttpheaders">`http.OutgoingHttpHeaders`</a>__
__<a name="type-aqtoptions">`AqtOptions`</a>__: Configuration for requests.
<table>
<thead><tr>
<th>Name</th>
<th>Type &amp; Description</th>
<th>Default</th>
</tr></thead>
<tr>
<td rowSpan="3" align="center">data</td>
<td><em>!Object</em></td>
<td rowSpan="3">-</td>
</tr>
<tr></tr>
<tr>
<td>Optional data to send to the server with the request.</td>
</tr>
<tr>
<td rowSpan="3" align="center">type</td>
<td><em>string</em></td>
<td rowSpan="3"><code>json</code></td>
</tr>
<tr></tr>
<tr>
<td>How to send data: <code>json</code> to serialise JSON data and add <em>Content-Type: application/json</em> header, and <code>form</code> for url-encoded transmission with <em>Content-Type: application/x-www-form-urlencoded</em>. <em>Multipart/form-data</em> must be implemented manually.</td>
</tr>
<tr>
<td rowSpan="3" align="center">headers</td>
<td><em><a href="https://nodejs.org/api/http.html#http_class_http_outgoinghttpheaders" title="The headers hash map for making requests, including such properties as Content-Encoding, Content-Type, etc.">!http.OutgoingHttpHeaders</a></em></td>
<td rowSpan="3">-</td>
</tr>
<tr></tr>
<tr>
<td>Headers to use for the request. By default, a single User-Agent header with <em>Mozilla/5.0 (Node.JS) aqt/{version}</em> value is set.</td>
</tr>
<tr>
<td rowSpan="3" align="center">compress</td>
<td><em>boolean</em></td>
<td rowSpan="3"><code>true</code></td>
</tr>
<tr></tr>
<tr>
<td>Add the <code>Accept-Encoding: gzip, deflate</code> header to indicate to the server that it can send a compressed response.</td>
</tr>
<tr>
<td rowSpan="3" align="center">timeout</td>
<td><em>number</em></td>
<td rowSpan="3">-</td>
</tr>
<tr></tr>
<tr>
<td>The timeout after which the request should fail.</td>
</tr>
<tr>
<td rowSpan="3" align="center">method</td>
<td><em>string</em></td>
<td rowSpan="3">-</td>
</tr>
<tr></tr>
<tr>
<td>What HTTP method to use in making of the request. When no method is given and <code>data</code> is present, defaults to <code>POST</code>.</td>
</tr>
<tr>
<td rowSpan="3" align="center">binary</td>
<td><em>boolean</em></td>
<td rowSpan="3"><code>false</code></td>
</tr>
<tr></tr>
<tr>
<td>Whether to return a buffer instead of a string.</td>
</tr>
<tr>
<td rowSpan="3" align="center">justHeaders</td>
<td><em>boolean</em></td>
<td rowSpan="3"><code>false</code></td>
</tr>
<tr></tr>
<tr>
<td>Whether to stop the request after response headers were received, without waiting for the data.</td>
</tr>
</table>
| Name | Type | Description | Default |
| ----------- | ------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------- | -------- |
| data | <em>Object</em> | Optional data to send to the server with the request. | - |
| type | <em>('form' \| 'json')</em> | How to send data: `json` to serialise JSON data and `form` for url-encoded transmission with `json` mode by default. | `'json'` |
| headers | <em>[http.OutgoingHttpHeaders](#type-httpoutgoinghttpheaders)</em> | Headers to use for the request. | - |
| compress | <em>boolean</em> | Add the `Accept-Encoding: gzip, deflate` header to indicate to the server that it can send a compressed response. | `true` |
| timeout | <em>number</em> | The timeout after which the request should fail. | - |
| method | <em>string</em> | What HTTP method to use in making of the request. When no method is given and `data` is present, defaults to `POST`. | - |
| binary | <em>boolean</em> | Whether to return a buffer instead of a string. | `false` |
| justHeaders | <em>boolean</em> | Whether to stop the request after response headers were received, without waiting for the data. | `false` |
_In the example below, a function is created to query data from a server._
<table>
<tr><th><a href="example/index.js">Source</a></th><th>Output</th></tr>
<tr><td>
```js

@@ -65,2 +138,5 @@ import aqt from '@rqt/aqt'

```
</td>
<td>
```json5

@@ -71,3 +147,3 @@ {

"content-type": "text/plain",
"date": "Wed, 03 Jul 2019 15:34:47 GMT",
"date": "Mon, 29 Jul 2019 16:34:16 GMT",
"connection": "close",

@@ -80,2 +156,4 @@ "transfer-encoding": "chunked"

```
</td></tr>
</table>

@@ -166,3 +244,4 @@ <p align="center"><a href="#table-of-contents"><img src="/.documentary/section-breaks/2.svg?sanitize=true"></a></p>

<a href="https://artd.eco">
<img src="https://raw.githubusercontent.com/wrote/wrote/master/images/artdeco.png" alt="Art Deco">
<img width="100" src="https://raw.githubusercontent.com/wrote/wrote/master/images/artdeco.png"
alt="Art Deco">
</a>

@@ -173,3 +252,3 @@ </th>

<a href="https://www.technation.sucks" title="Tech Nation Visa">
<img src="https://raw.githubusercontent.com/artdecoweb/www.technation.sucks/master/anim.gif"
<img width="100" src="https://raw.githubusercontent.com/idiocc/cookies/master/wiki/arch4.jpg"
alt="Tech Nation Visa">

@@ -176,0 +255,0 @@ </a>

@@ -6,5 +6,13 @@ import { request as https } from 'https'

import { parse } from 'url'
import { version } from '../package.json'
import { getData, exec } from './lib'
let ua
try {
// require in index won't lead to --process_common_js_modules
const { 'version': version, 'name': name } = require('../package.json')
ua = name == '@rqt/aqt' ? `@rqt/aqt/${version}` : `@rqt/aqt via ${name}/${version}`
} catch (err) {
ua = '@aqt/rqt'
}
const LOG = debuglog('aqt')

@@ -15,12 +23,3 @@

* @param {string} address The URL such as http://example.com/api.
* @param {AqtOptions} [options] Configuration for requests.
* @param {Object} [options.data] Optional data to send to the server with the request.
* @param {'form'|'json'} [options.type="'json'"] How to send data: `json` to serialise JSON data and `form` for url-encoded transmission with `json` mode by default. Default `'json'`.
* @param {http.OutgoingHttpHeaders} [options.headers] Headers to use for the request.
* @param {boolean} [options.compress=true] Add the `Accept-Encoding: gzip, deflate` header to indicate to the server that it can send a compressed response. Default `true`.
* @param {number} [options.timeout] The timeout after which the request should fail.
* @param {string} [options.method] What HTTP method to use in making of the request. When no method is given and `data` is present, defaults to `POST`.
* @param {boolean} [options.binary=false] Whether to return a buffer instead of a string. Default `false`.
* @param {boolean} [options.justHeaders=false] Whether to stop the request after response headers were received, without waiting for the data. Default `false`.
* @returns {Promise.<AqtReturn>} The body, headers and status.
* @param {_rqt.AqtOptions} [options] Configuration for requests.
*/

@@ -32,3 +31,3 @@ const aqt = async (address, options = {}) => {

headers: outgoingHeaders = {
'User-Agent': `Mozilla/5.0 (Node.js) aqt/${version}`,
'User-Agent': `Mozilla/5.0 (Node.JS) ${ua}`,
},

@@ -88,3 +87,4 @@ compress = true,

return {
/** @type {!_rqt.AqtReturn} */
const res = {
body: parsedBody ? parsedBody : body,

@@ -95,2 +95,3 @@ headers,

}
return res
}

@@ -100,33 +101,9 @@

/* documentary types/index.xml */
/**
* @suppress {nonStandardJsDocs}
* @typedef {Object} AqtOptions Configuration for requests.
* @prop {Object} [data] Optional data to send to the server with the request.
* @prop {'form'|'json'} [type="'json'"] How to send data: `json` to serialise JSON data and `form` for url-encoded transmission with `json` mode by default. Default `'json'`.
* @prop {http.OutgoingHttpHeaders} [headers] Headers to use for the request.
* @prop {boolean} [compress=true] Add the `Accept-Encoding: gzip, deflate` header to indicate to the server that it can send a compressed response. Default `true`.
* @prop {number} [timeout] The timeout after which the request should fail.
* @prop {string} [method] What HTTP method to use in making of the request. When no method is given and `data` is present, defaults to `POST`.
* @prop {boolean} [binary=false] Whether to return a buffer instead of a string. Default `false`.
* @prop {boolean} [justHeaders=false] Whether to stop the request after response headers were received, without waiting for the data. Default `false`.
* @typedef {import('../types').AqtOptions} _rqt.AqtOptions
*/
/**
* @suppress {nonStandardJsDocs}
* @typedef {import('http').OutgoingHttpHeaders} http.OutgoingHttpHeaders
*/
/* documentary types/return.xml */
/**
* @suppress {nonStandardJsDocs}
* @typedef {Object} AqtReturn
* @prop {string|Object|Buffer} body The return from the server. In case the `json` content-type was set by the server, the response will be parsed into an object. If `binary` option was used for the request, a `Buffer` will be returned. Otherwise, a string response is returned.
* @prop {http.IncomingHttpHeaders} headers Incoming headers returned by the server.
* @prop {number} statusCode The status code returned by the server.
* @prop {string} statusMessage The status message set by the server.
*/
/**
* @suppress {nonStandardJsDocs}
* @typedef {import('http').IncomingHttpHeaders} http.IncomingHttpHeaders
*/
* @typedef {import('../types').AqtReturn} _rqt.AqtReturn
*/

@@ -59,7 +59,16 @@ import erotic from 'erotic'

/**
* @param {IncomingMessage.headers} headers
* Check if the returned content-type starts with application/json.
* @param {!http.IncomingHttpHeaders} headers
*/
const isHeadersJson = (headers) => {
/**
* @suppress {checkTypes}
*/
const { 'content-type': contentType = '' } = headers
return contentType.startsWith('application/json')
}
}
/**
* @suppress {nonStandardJsDocs}
* @typedef {import('http').IncomingHttpHeaders} http.IncomingHttpHeaders
*/
import erotic from 'erotic'
import { collect } from 'catchment'
import { createGunzip } from 'zlib'
import { request as Request } from 'http' // eslint-disable-line
/**
* @param {import('http').IncomingMessage} req
* @param {!http.IncomingMessage} res
*/
export const isMessageGzip = (res) => {
return res.headers['content-encoding'] == 'gzip'
/**
* @suppress {checkTypes}
*/
const { 'content-encoding': contentEncoding } = res.headers
return contentEncoding == 'gzip'
}
/**
* @param {typeof import('http').request} request The actual http or https request function.
* @param {import('http').RequestOptions} requestOptions
* @param {object} config Config object.
* @param {typeof Request} request The actual http or https request function.
* @param {!http.RequestOptions} requestOptions
* @param {!Object} [config] Config object.
* @param {boolean} [config.justHeaders] only return headers as soon as available. false

@@ -22,14 +27,12 @@ * @param {boolean} [config.binary] return binary

const { justHeaders, binary, er = erotic(true) } = config
/** @type {import('http').ClientRequest} */
/** @type {!http.ClientRequest} */
let req
/** @type {import('http').IncomingHttpHeaders} */
/** @type {!http.IncomingHttpHeaders} */
let headers
/** @type {{statusMessage: string, statusCode: number}} */
let m
/** @type {string|Buffer} */
/** @type {string|!Buffer} */
let body
/** @type {number} */
let rawLength = 0
/** @type {number} */
let byteLength = 0

@@ -81,2 +84,19 @@

export default makeRequest
export default makeRequest
/**
* @suppress {nonStandardJsDocs}
* @typedef {import('http').IncomingMessage} http.IncomingMessage
*/
/**
* @suppress {nonStandardJsDocs}
* @typedef {import('http').ClientRequest} http.ClientRequest
*/
/**
* @suppress {nonStandardJsDocs}
* @typedef {import('http').IncomingHttpHeaders} http.IncomingHttpHeaders
*/
/**
* @suppress {nonStandardJsDocs}
* @typedef {import('http').RequestOptions} http.RequestOptions
*/

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc