Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies #11

Merged
merged 2 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
extends: seegno
extends: uphold

rules:
no-console: 0
no-sync: 0
prefer-spread: 0

# Disable prettier.
prettier/prettier: 0
50 changes: 50 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Release

on:
workflow_dispatch:
inputs:
VERSION_BUMP:
description: 'The version bump'
type: choice
options:
- major
- minor
- patch
default: minor
required: true

jobs:
release:
runs-on: ubuntu-latest
concurrency: 1
environment: release

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.RELEASE_GITHUB_TOKEN }}

- name: Setup Node.js version
uses: actions/setup-node@v4
with:
node-version: 20

- name: Enable yarn
run: corepack enable

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Configure git
run: |
git config user.name "Uphold"
git config user.email "[email protected]"

- name: Generate release
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.RELEASE_NPM_TOKEN }}
run: |
echo "//registry.npmjs.org/:_authToken=\${NPM_TOKEN}" > .npmrc
npm run release -- --increment "${{ github.event.inputs.VERSION_BUMP }}" -V
19 changes: 19 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Test

on: [push]

jobs:
unit:
runs-on: ubuntu-latest
strategy:
matrix:
node: ['18', '20']

container:
image: node:${{ matrix.node }}-alpine

steps:
- uses: actions/checkout@v4
- run: yarn install --frozen-lockfile
- run: yarn lint
- run: yarn test
22 changes: 22 additions & 0 deletions .release-it.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module.exports = {
git: {
changelog: 'echo "## Changelog\\n\\n$(npx @uphold/github-changelog-generator -f unreleased | tail -n +4 -f)"',
commitMessage: 'Release ${version}',
requireBranch: 'master',
requireCommits: true,
tagName: 'v${version}'
},
github: {
release: true,
releaseName: 'v${version}'
},
hooks: {
'after:bump': `
echo "$(npx @uphold/github-changelog-generator -f v\${version})\n$(tail -n +2 CHANGELOG.md)" > CHANGELOG.md &&
git add CHANGELOG.md --all
`
},
npm: {
publish: true
}
};
26 changes: 0 additions & 26 deletions .travis.yml

This file was deleted.

13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# request-logger

A wrapper for the [request](https://github.com/request/request) module that logs all request events.
A wrapper for the [request](https://github.com/cypress-io/request) module that logs all request events.

## Status

Expand All @@ -26,7 +26,7 @@ Wrap the `request` module using `@uphold/request-logger`. By default, all events

```javascript
const logger = require('@uphold/request-logger');
const request = logger(require('request'));
const request = logger(require('@cypress/request'));

request.get('https://www.github.com');

Expand Down Expand Up @@ -56,7 +56,7 @@ You can optionally define a custom logging function which receives the request o

```javascript
const logger = require('@uphold/request-logger');
const request = logger(require('request'), data => console.log(`${data.id} ${data.type}: ${data.uri}${data.statusCode ? ` (${data.statusCode})` : ''} ${(data.body ? `${data.body}` : '').length} bytes`));
const request = logger(require('@cypress/request'), data => console.log(`${data.id} ${data.type}: ${data.uri}${data.statusCode ? ` (${data.statusCode})` : ''} ${(data.body ? `${data.body}` : '').length} bytes`));

request.get('https://www.github.com', () => {});

Expand Down Expand Up @@ -86,11 +86,10 @@ The recommended node.js version is `>= 6` as it ships with native [ES2015 Proxy]

The minimum required `request` version is `2.27.0`, although `2.54.0` is a particularly troubled version which is best avoided.

## Release
## Release process

```shell
❯ npm version [<newversion> | major | minor | patch] -m "Release %s"`
```
The release of a version is automated via the [release](https://github.com/uphold/request-logger/.github/workflows/release.yaml) GitHub workflow.
Run it by clicking the "Run workflow" button.

## License

Expand Down
25 changes: 12 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,29 @@
"main": "src",
"repository": "https://github.com/uphold/request-logger.git",
"scripts": {
"changelog": "github_changelog_generator --no-issues --header-label='# Changelog' --future-release=v$npm_config_future_release && sed -i '' -e :a -e '$d;N;2,4ba' -e 'P;D' CHANGELOG.md",
"lint": "eslint src test",
"test": "jest --coverage --verbose",
"version": "npm run changelog --future-release=$npm_package_version && git add -A CHANGELOG.md"
},
"dependencies": {
"uuid": "^3.0.1"
"release": "release-it",
"test": "jest --coverage --verbose"
},
"dependencies": {},
"devDependencies": {
"eslint": "^3.12.2",
"eslint-config-seegno": "^8.0.1",
"jest": "^18.1.0",
"nock": "^9.0.2",
"request": "^2.79.0"
"@cypress/request": "^3.0.1",
"eslint": "^8.57.0",
"eslint-config-uphold": "^6.0.0",
"jest": "^29.7.0",
"nock": "^13.5.4",
"release-it": "^17.1.1"
},
"peerDependencies": {
"request": ">=2.27.0"
"@cypress/request": ">=3.0.1"
},
"engines": {
"node": ">=4"
},
"jest": {
"coveragePathIgnorePatterns": [
"/src/proxy.js"
]
],
"restoreMocks": true
}
}
101 changes: 59 additions & 42 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* Module dependencies.
*/

const { randomUUID } = require('node:crypto');
const Proxy = require('./proxy');
const uuid = require('uuid/v4');

/**
* Exports
Expand All @@ -21,44 +21,57 @@ module.exports = function logger(request, log) {
}

function apply(target, caller, args) {
const id = uuid();
const id = randomUUID();
const startTime = Date.now();

return target.apply(undefined, args)
.on('complete', function(response) {
return target
.apply(undefined, args)
.on('complete', function (response) {
if (!this.callback) {
return;
}

log({
body: response.body,
duration: Date.now() - startTime,
headers: response.headers,
id,
statusCode: response.statusCode,
type: 'response',
uri: this.uri.href
}, this);
}).on('error', function(error) {
log({
duration: Date.now() - startTime,
error,
headers: this.headers,
id,
method: this.method.toUpperCase(),
type: 'error',
uri: this.uri.href
}, this);
}).on('redirect', function() {
log({
duration: Date.now() - startTime,
headers: this.response.headers,
id,
statusCode: this.response.statusCode,
type: 'redirect',
uri: this.uri.href
}, this);
}).on('request', function() {
log(
{
body: response.body,
duration: Date.now() - startTime,
headers: response.headers,
id,
statusCode: response.statusCode,
type: 'response',
uri: this.uri.href
},
this
);
})
.on('error', function (error) {
log(
{
duration: Date.now() - startTime,
error,
headers: this.headers,
id,
method: this.method.toUpperCase(),
type: 'error',
uri: this.uri.href
},
this
);
})
.on('redirect', function () {
log(
{
duration: Date.now() - startTime,
headers: this.response.headers,
id,
statusCode: this.response.statusCode,
type: 'redirect',
uri: this.uri.href
},
this
);
})
.on('request', function () {
const data = {
headers: this.headers,
id,
Expand All @@ -72,19 +85,23 @@ module.exports = function logger(request, log) {
}

log(data, this);
}).on('response', function(response) {
})
.on('response', function (response) {
if (this.callback) {
return;
}

log({
duration: Date.now() - startTime,
headers: response.headers,
id,
statusCode: response.statusCode,
type: 'response',
uri: this.uri.href
}, this);
log(
{
duration: Date.now() - startTime,
headers: response.headers,
id,
statusCode: response.statusCode,
type: 'response',
uri: this.uri.href
},
this
);
});
}

Expand Down
6 changes: 3 additions & 3 deletions src/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
* Module dependencies.
*/

const fs = require('fs');
const vm = require('vm');
const fs = require('node:fs');
const vm = require('node:vm');

/**
* Proxy reference.
*/

let Proxy = global.Proxy;
let { Proxy } = global;

/**
* Workaround to avoid mutating `global.Proxy`.
Expand Down
1 change: 0 additions & 1 deletion test/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
env:
jest: true
jasmine: true
Loading