Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
3659b80e1e | |||
770e7d46ea | |||
2a46f2a306 | |||
eae4d09664 | |||
23a2f597fc | |||
c278249c32 | |||
a32c372374 | |||
f98972d9fe | |||
acebe6a381 | |||
7031504852 | |||
3010a1da9a |
@ -3,14 +3,14 @@ image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
|||||||
|
|
||||||
cache:
|
cache:
|
||||||
paths:
|
paths:
|
||||||
- .npmci_cache/
|
- .npmci_cache/
|
||||||
key: "$CI_BUILD_STAGE"
|
key: '$CI_BUILD_STAGE'
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- security
|
- security
|
||||||
- test
|
- test
|
||||||
- release
|
- release
|
||||||
- metadata
|
- metadata
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# security stage
|
# security stage
|
||||||
@ -18,21 +18,23 @@ stages:
|
|||||||
mirror:
|
mirror:
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci git mirror
|
- npmci git mirror
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
snyk:
|
snyk:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:snyk
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci command npm install -g snyk
|
|
||||||
- npmci command npm install --ignore-scripts
|
- npmci command npm install --ignore-scripts
|
||||||
- npmci command snyk test
|
- npmci command snyk test
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# test stage
|
# test stage
|
||||||
@ -41,37 +43,40 @@ snyk:
|
|||||||
testStable:
|
testStable:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci node install stable
|
- npmci node install stable
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci npm test
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- priv
|
- docker
|
||||||
|
- priv
|
||||||
|
|
||||||
testBuild:
|
testBuild:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci node install stable
|
- npmci node install stable
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command npm run build
|
- npmci command npm run build
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
script:
|
script:
|
||||||
- npmci node install stable
|
- npmci node install stable
|
||||||
- npmci npm publish
|
- npmci npm publish
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# metadata stage
|
# metadata stage
|
||||||
@ -85,30 +90,31 @@ codequality:
|
|||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- priv
|
- docker
|
||||||
|
- priv
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci trigger
|
- npmci trigger
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
pages:
|
pages:
|
||||||
image: hosttoday/ht-docker-dbase:npmci
|
|
||||||
services:
|
|
||||||
- docker:stable-dind
|
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
|
- npmci node install lts
|
||||||
- npmci command npm install -g @gitzone/tsdoc
|
- npmci command npm install -g @gitzone/tsdoc
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command tsdoc
|
- npmci command tsdoc
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
only:
|
only:
|
||||||
@ -116,5 +122,5 @@ pages:
|
|||||||
artifacts:
|
artifacts:
|
||||||
expire_in: 1 week
|
expire_in: 1 week
|
||||||
paths:
|
paths:
|
||||||
- public
|
- public
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartrequest",
|
"name": "@pushrocks/smartrequest",
|
||||||
"version": "1.1.40",
|
"version": "1.1.46",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
14
package.json
14
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartrequest",
|
"name": "@pushrocks/smartrequest",
|
||||||
"version": "1.1.40",
|
"version": "1.1.46",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "dropin replacement for request",
|
"description": "dropin replacement for request",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
@ -38,12 +38,12 @@
|
|||||||
"tslint-config-prettier": "^1.18.0"
|
"tslint-config-prettier": "^1.18.0"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/*",
|
"ts/**/*",
|
||||||
"ts_web/*",
|
"ts_web/**/*",
|
||||||
"dist/*",
|
"dist/**/*",
|
||||||
"dist_web/*",
|
"dist_web/**/*",
|
||||||
"dist_ts_web/*",
|
"dist_ts_web/**/*",
|
||||||
"assets/*",
|
"assets/**/*",
|
||||||
"cli.js",
|
"cli.js",
|
||||||
"npmextra.json",
|
"npmextra.json",
|
||||||
"readme.md"
|
"readme.md"
|
||||||
|
@ -22,18 +22,18 @@ Use TypeScript for best in class instellisense.
|
|||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|
||||||
* supports http
|
- supports http
|
||||||
* supports https
|
- supports https
|
||||||
* supports unix socks
|
- supports unix socks
|
||||||
* supports formData
|
- supports formData
|
||||||
* supports file uploads
|
- supports file uploads
|
||||||
* supports best practice keepAlive
|
- supports best practice keepAlive
|
||||||
* dedicated functions for working with JSON request/response cycles
|
- dedicated functions for working with JSON request/response cycles
|
||||||
* written in TypeScript
|
- written in TypeScript
|
||||||
* continuously updated
|
- continuously updated
|
||||||
* uses node native http and https modules
|
- uses node native http and https modules
|
||||||
* used in modules like @pushrocks/smartproxy and @apiglobal/typedrequest
|
- used in modules like @pushrocks/smartproxy and @apiglobal/typedrequest
|
||||||
* commercial support available at [https://lossless.support](https://lossless.support)
|
- commercial support available at [https://lossless.support](https://lossless.support)
|
||||||
|
|
||||||
> note: smartrequest uses the **native** node http/https modules under the hood (not the bloated one from npm)
|
> note: smartrequest uses the **native** node http/https modules under the hood (not the bloated one from npm)
|
||||||
|
|
||||||
@ -46,23 +46,24 @@ let options: smartrequest.ISmartRequestOptions = { // typed options
|
|||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
"Authorization": "Bearer token"
|
"Authorization": "Bearer token"
|
||||||
},
|
},
|
||||||
requestBody: {
|
requestBody: JSON.stringify({
|
||||||
key1: 'value1',
|
key1: 'value1',
|
||||||
key2: 3
|
key2: 3
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
smartrequest.post('https://example.com', options).then(res => {
|
smartrequest.request('https://example.com', options).then(res => {
|
||||||
console.log(res.status)
|
console.log(res.status)
|
||||||
console.log(res.body) // if json, body will be parsed automatically
|
console.log(res.body) // if json, body will be parsed automatically
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
console.log(err)
|
console.log(err)
|
||||||
})
|
})
|
||||||
|
|
||||||
// also available
|
// dedicated JSON metods are available:
|
||||||
smartrequest.get(...)
|
smartrequest.getJson(...)
|
||||||
smartrequest.put(...)
|
smartrequest.postJson(...)
|
||||||
smartrequest.del(...)
|
smartrequest.putJson(...)
|
||||||
|
smartrequest.delJson(...)
|
||||||
|
|
||||||
// streaming
|
// streaming
|
||||||
smartrequest.get('https://example.com/bigfile.mp4', optionsArg, true).then(res => { // third arg = true signals streaming
|
smartrequest.get('https://example.com/bigfile.mp4', optionsArg, true).then(res => { // third arg = true signals streaming
|
||||||
@ -76,6 +77,10 @@ smartrequest.get('https://example.com/bigfile.mp4', optionsArg, true).then(res =
|
|||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Contribution
|
||||||
|
|
||||||
|
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
||||||
|
|
||||||
For further information read the linked docs at the top of this readme.
|
For further information read the linked docs at the top of this readme.
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
@ -21,7 +21,7 @@ export const getBinary = async (
|
|||||||
//so Buffer.concat() can make us a new Buffer
|
//so Buffer.concat() can make us a new Buffer
|
||||||
//of all of them together
|
//of all of them together
|
||||||
const buffer = Buffer.concat(data);
|
const buffer = Buffer.concat(data);
|
||||||
response.body = buffer.toString('binary');
|
response.body = buffer;
|
||||||
done.resolve();
|
done.resolve();
|
||||||
});
|
});
|
||||||
await done.promise;
|
await done.promise;
|
||||||
|
@ -10,6 +10,7 @@ export interface IFormField {
|
|||||||
type: 'string' | 'filePath' | 'Buffer';
|
type: 'string' | 'filePath' | 'Buffer';
|
||||||
payload: string | Buffer;
|
payload: string | Buffer;
|
||||||
fileName?: string;
|
fileName?: string;
|
||||||
|
contentType?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const appendFormField = async (formDataArg: plugins.formData, formDataField: IFormField) => {
|
const appendFormField = async (formDataArg: plugins.formData, formDataField: IFormField) => {
|
||||||
@ -19,7 +20,11 @@ const appendFormField = async (formDataArg: plugins.formData, formDataField: IFo
|
|||||||
break;
|
break;
|
||||||
case 'filePath':
|
case 'filePath':
|
||||||
if (typeof formDataField.payload !== 'string') {
|
if (typeof formDataField.payload !== 'string') {
|
||||||
throw new Error(`Payload for key ${formDataField.name} must be of type string. Got ${typeof formDataField.payload} instead.`);
|
throw new Error(
|
||||||
|
`Payload for key ${
|
||||||
|
formDataField.name
|
||||||
|
} must be of type string. Got ${typeof formDataField.payload} instead.`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
const fileData = plugins.fs.readFileSync(
|
const fileData = plugins.fs.readFileSync(
|
||||||
plugins.path.join(process.cwd(), formDataField.payload)
|
plugins.path.join(process.cwd(), formDataField.payload)
|
||||||
@ -30,9 +35,9 @@ const appendFormField = async (formDataArg: plugins.formData, formDataField: IFo
|
|||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case 'Buffer':
|
case 'Buffer':
|
||||||
formDataArg.append('file', formDataField.payload, {
|
formDataArg.append(formDataField.name, formDataField.payload, {
|
||||||
filename: formDataField.fileName ? formDataField.fileName : 'upload.pdf',
|
filename: formDataField.fileName ? formDataField.fileName : 'upload.pdf',
|
||||||
contentType: 'application/pdf'
|
contentType: formDataField.contentType ? formDataField.contentType : 'application/pdf'
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user