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

feat: dropping support for non-native FormData implementations #199

Merged
merged 6 commits into from
Sep 14, 2023
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
7 changes: 6 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@

"unicorn/prefer-node-protocol": "error",

"vitest/require-hook": "off"
"vitest/require-hook": [
"error",
{
"allowedFunctionCalls": ["runCustomFixtures"]
}
]
},
"overrides": [
{
Expand Down
6 changes: 3 additions & 3 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: "/"
directory: '/'
schedule:
interval: monthly
reviewers:
Expand All @@ -19,7 +19,7 @@ updates:
prefix-development: chore(deps-dev)

- package-ecosystem: npm
directory: "/"
directory: '/'
schedule:
interval: monthly
open-pull-requests-limit: 10
Expand All @@ -40,4 +40,4 @@ updates:
# stringify-objectis now an ESM package and can't be used here without a rewrite.
- dependency-name: stringify-object
versions:
- ">= 4"
- '>= 4'
17 changes: 8 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ on:

jobs:
build:

runs-on: ubuntu-latest

strategy:
Expand All @@ -18,13 +17,13 @@ jobs:
- 20

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- run: npm ci
- run: npm run build
- run: npm test
- run: npm ci
- run: npm run build
- run: npm test
20 changes: 10 additions & 10 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "CodeQL"
name: 'CodeQL'

on:
push:
Expand All @@ -20,16 +20,16 @@ jobs:
strategy:
fail-fast: false
matrix:
language: [ 'javascript' ]
language: ['javascript']

steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Checkout repository
uses: actions/checkout@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
12 changes: 6 additions & 6 deletions .github/workflows/integration-node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4

- name: Run tests
run: docker-compose run integration_node
- name: Run tests
run: docker-compose run integration_node

- name: Cleanup
if: always()
run: docker-compose down
- name: Cleanup
if: always()
run: docker-compose down
12 changes: 6 additions & 6 deletions .github/workflows/integration-php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4

- name: Run tests
run: docker-compose run integration_php
- name: Run tests
run: docker-compose run integration_php

- name: Cleanup
if: always()
run: docker-compose down
- name: Cleanup
if: always()
run: docker-compose down
12 changes: 6 additions & 6 deletions .github/workflows/integration-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4

- name: Run tests
run: docker-compose run integration_python
- name: Run tests
run: docker-compose run integration_python

- name: Cleanup
if: always()
run: docker-compose down
- name: Cleanup
if: always()
run: docker-compose down
12 changes: 6 additions & 6 deletions .github/workflows/integration-shell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4

- name: Run tests
run: docker-compose run integration_shell
- name: Run tests
run: docker-compose run integration_shell

- name: Cleanup
if: always()
run: docker-compose down
- name: Cleanup
if: always()
run: docker-compose down
1 change: 0 additions & 1 deletion .sink.d.ts

This file was deleted.

10 changes: 8 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
{
"files.insertFinalNewline": false, // controlled by the .editorconfig at root since we can't map vscode settings directly to files (see: https://github.com/microsoft/vscode/issues/35350)
"editor.defaultFormatter": "esbenp.prettier-vscode"
"editor.codeActionsOnSave": {
"source.fixAll": true
},
"editor.defaultFormatter": "esbenp.prettier-vscode",

// controlled by the .editorconfig at root since we can't map vscode settings directly to files
// https://github.com/microsoft/vscode/issues/35350
"files.insertFinalNewline": false
}
49 changes: 24 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Type: `object`

Available options:

* `harIsAlreadyEncoded` (`boolean`): In the event of you supplying a `source` HAR that already contains escaped data (query and cookie parameters)strings, this allows you to disable automatic encoding of those parameters to prevent them from being double-escaped.
- `harIsAlreadyEncoded` (`boolean`): In the event of you supplying a `source` HAR that already contains escaped data (query and cookie parameters)strings, this allows you to disable automatic encoding of those parameters to prevent them from being double-escaped.

### convert(target [, options])

Expand All @@ -64,11 +64,11 @@ const snippet = new HTTPSnippet({
});

// generate Node.js: Native output
console.log(snippet.convert('node'));
console.log(await snippet.convert('node'));

// generate Node.js: Native output, indent with tabs
console.log(
snippet.convert('node', {
await snippet.convert('node', {
indent: '\t',
}),
);
Expand Down Expand Up @@ -104,13 +104,13 @@ const snippet = new HTTPSnippet({

// generate Shell: cURL output
console.log(
snippet.convert('shell', 'curl', {
await snippet.convert('shell', 'curl', {
indent: '\t',
}),
);

// generate Node.js: Unirest output
console.log(snippet.convert('node', 'unirest'));
console.log(await snippet.convert('node', 'unirest'));
```

### addTarget(target)
Expand Down Expand Up @@ -155,32 +155,31 @@ For detailed information on each target, please review the [wiki](https://github

There are some major differences between this library and the [httpsnippet](https://github.com/Kong/httpsnippet) upstream:

* Includes a full integration test suite for a handful of clients and targets.
* Does not ship with a CLI component.
* Does not do any HAR schema validation. It's just assumed that the HAR you're supplying to the library is already valid.
* The main `HTTPSnippet` export contains an `options` argument for an `harIsAlreadyEncoded` option for disabling [escaping](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent) of cookies and query strings in URLs.
* We added this because all HARs that we interact with already have this data escaped and this option prevents them from being double encoded, thus corrupting the data.
* Does not support the `insecureSkipVerify` option on `go:native`, `node:native`, `ruby:native`, and `shell:curl` as we don't want snippets generated for our users to bypass SSL certificate verification.
* Node
* `fetch`
* Body payloads are treated as an object literal and wrapped within `JSON.stringify()`. We do this to keep those targets looking nicer with those kinds of payloads. This also applies to the JS `fetch` target as well.
* `request`
* Does not provide query string parameters in a `params` argument due to complexities with query encoding.
* PHP
* `guzzle`
* Snippets have `require_once('vendor/autoload.php');` prefixed at the top.
* Python
* `python3`
* Does not ship this client due to its incompatibility with being able to support file uploads.
* `requests`
* Does not provide query string parameters in a `params` argument due to complexities with query encoding.
- Includes a full integration test suite for a handful of clients and targets.
- Does not ship with a CLI component.
- Does not do any HAR schema validation. It's just assumed that the HAR you're supplying to the library is already valid.
- The main `HTTPSnippet` export contains an `options` argument for an `harIsAlreadyEncoded` option for disabling [escaping](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent) of cookies and query strings in URLs.
- We added this because all HARs that we interact with already have this data escaped and this option prevents them from being double encoded, thus corrupting the data.
- Does not support the `insecureSkipVerify` option on `go:native`, `node:native`, `ruby:native`, and `shell:curl` as we don't want snippets generated for our users to bypass SSL certificate verification.
- Node
- `fetch`
- Body payloads are treated as an object literal and wrapped within `JSON.stringify()`. We do this to keep those targets looking nicer with those kinds of payloads. This also applies to the JS `fetch` target as well.
- `request`
- Does not provide query string parameters in a `params` argument due to complexities with query encoding.
- PHP
- `guzzle`
- Snippets have `require_once('vendor/autoload.php');` prefixed at the top.
- Python
- `python3`
- Does not ship this client due to its incompatibility with being able to support file uploads.
- `requests`
- Does not provide query string parameters in a `params` argument due to complexities with query encoding.

## License

[MIT](LICENSE) © [Kong](https://konghq.com)

[license-url]: https://github.com/Kong/httpsnippet/blob/master/LICENSE

[npm-url]: https://www.npmjs.com/package/@readme/httpsnippet
[npm-license]: https://img.shields.io/npm/l/@readme/httpsnippet.svg?style=flat-square
[npm-version]: https://img.shields.io/npm/v/@readme/httpsnippet.svg?style=flat-square
Loading