@automattic/request-promise-native 2.5.3 → 2.5.4
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/AGENTS.md +77 -0
- package/package.json +10 -4
package/AGENTS.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# AGENTS.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) and other agents when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This is `request-promise-native`, a Promise-enabled wrapper for the HTTP request library. It uses native ES6+ promises (not Bluebird) and is a fork maintained by Automattic that uses `@cypress/request` instead of the deprecated original `request` package.
|
|
8
|
+
|
|
9
|
+
## Development Commands
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
# Run linting
|
|
13
|
+
npm run lint
|
|
14
|
+
|
|
15
|
+
# Auto-fix linting issues
|
|
16
|
+
npm run lint:fix
|
|
17
|
+
|
|
18
|
+
# Run all tests (both main tests and promise-core tests)
|
|
19
|
+
npm test
|
|
20
|
+
|
|
21
|
+
# Check for unused dependencies
|
|
22
|
+
npm run check-dependencies
|
|
23
|
+
|
|
24
|
+
# Verify TypeScript definitions
|
|
25
|
+
npm run check-dts
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Test Structure
|
|
29
|
+
|
|
30
|
+
Tests are run with Mocha in two separate test suites:
|
|
31
|
+
- Main package tests: `test/spec/request-test.js`
|
|
32
|
+
- Promise core tests: `deps/promise-core/test/spec/`
|
|
33
|
+
|
|
34
|
+
Both test suites run sequentially with the `npm test` command.
|
|
35
|
+
|
|
36
|
+
## Architecture
|
|
37
|
+
|
|
38
|
+
### Core Structure
|
|
39
|
+
|
|
40
|
+
The package has a unique architecture that wraps the `request` library with promise functionality:
|
|
41
|
+
|
|
42
|
+
1. **Entry point** (`lib/rp.js`):
|
|
43
|
+
- Uses `stealthy-require` to load a fresh instance of `request` to avoid polluting user's require cache
|
|
44
|
+
- Configures promise plumbing with native `Promise` implementation
|
|
45
|
+
- Exposes `then`, `catch`, and `promise` methods on request objects
|
|
46
|
+
|
|
47
|
+
2. **Promise Core** (`deps/promise-core/`):
|
|
48
|
+
- Contains the core promise wrapping logic embedded in this repository
|
|
49
|
+
- `configure/request2.js`: Intercepts the `request.Request.prototype.init` method to inject promise functionality
|
|
50
|
+
- `lib/plumbing.js`: Core promise integration logic that wraps request callbacks with promise resolve/reject
|
|
51
|
+
- `lib/errors.js`: Custom error classes (`RequestError`, `StatusCodeError`, `TransformError`)
|
|
52
|
+
|
|
53
|
+
3. **Error Handling**:
|
|
54
|
+
- `RequestError`: Network/request-level errors
|
|
55
|
+
- `StatusCodeError`: Non-2xx status codes when `simple: true` (default)
|
|
56
|
+
- `TransformError`: Errors thrown during response transformation
|
|
57
|
+
|
|
58
|
+
### Key Concepts
|
|
59
|
+
|
|
60
|
+
- **Promise interception**: The package modifies `request`'s prototype to inject promise handling before the original init method runs
|
|
61
|
+
- **Transform functions**: Optional response transformers can be applied, with special handling for `transform2xxOnly` option
|
|
62
|
+
- **Options**:
|
|
63
|
+
- `simple` (default: true): Reject on non-2xx status codes
|
|
64
|
+
- `resolveWithFullResponse` (default: false): Resolve with full response object instead of just body
|
|
65
|
+
- `transform2xxOnly` (default: true): Only transform 2xx responses
|
|
66
|
+
|
|
67
|
+
### Dependencies
|
|
68
|
+
|
|
69
|
+
- Uses `@cypress/request` (aliased as `request`) because the original `request` is deprecated
|
|
70
|
+
- `qs` is pinned to v6.14.2 via package.json overrides
|
|
71
|
+
- Requires Node.js >=20.x
|
|
72
|
+
|
|
73
|
+
## Important Notes
|
|
74
|
+
|
|
75
|
+
- This package maintains API compatibility with `request-promise` but uses native promises instead of Bluebird
|
|
76
|
+
- The `stealthy-require` pattern ensures users can still require an unaltered `request` instance if needed
|
|
77
|
+
- The promise-core dependency is embedded in `deps/` rather than being an external npm package
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@automattic/request-promise-native",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.4",
|
|
4
4
|
"description": "The simplified HTTP request client 'request' with Promise support. Powered by native ES6 promises.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"xhr",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"scripts": {
|
|
18
18
|
"lint": "eslint .",
|
|
19
19
|
"lint:fix": "eslint --fix .",
|
|
20
|
-
"test": "
|
|
20
|
+
"test": "jest",
|
|
21
21
|
"check-dependencies": "npx depcheck@1.4.7",
|
|
22
22
|
"check-dts": "npx check-dts lib/*.d.ts"
|
|
23
23
|
},
|
|
@@ -40,17 +40,23 @@
|
|
|
40
40
|
"stealthy-require": "^1.1.1"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
+
"@jest/globals": "^30.2.0",
|
|
43
44
|
"@types/caseless": "^0.12.5",
|
|
44
45
|
"@types/node": "^25.0.2",
|
|
45
46
|
"bluebird": "^3.7.2",
|
|
46
47
|
"body-parser": "~2.2.0",
|
|
47
|
-
"chai": "^6.0.1",
|
|
48
48
|
"eslint": "^10.0.0",
|
|
49
49
|
"globals": "^17.0.0",
|
|
50
|
-
"
|
|
50
|
+
"jest": "^30.2.0",
|
|
51
51
|
"tough-cookie": "^6.0.0"
|
|
52
52
|
},
|
|
53
53
|
"overrides": {
|
|
54
54
|
"qs": "6.14.2"
|
|
55
|
+
},
|
|
56
|
+
"jest": {
|
|
57
|
+
"injectGlobals": false,
|
|
58
|
+
"testMatch": [
|
|
59
|
+
"**/test/spec/*.js"
|
|
60
|
+
]
|
|
55
61
|
}
|
|
56
62
|
}
|