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

Sync v1.2.2 changes to main branch #487

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
25 changes: 23 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
# Changelog


## v1.2.2 _Metaphorical Music_

- Fix route match error with WordPress 5.5, props socrates77
- Throw an error early when `.file()` is passed a Buffer object without an accompanying name string, props @cungminh2710 & @mvhirsch


## v1.2.1 _Colomb_

- Fix issue where `li` was improperly declared as a dev-only dependency, props @el-lsan & @jerolan.


## v1.2.0 _Space Is Only Noise_

- **BREAKING**: The minimum supported node version is now v8.6, or v8.2.1 with the `--harmony` flag.
- **BREAKING**: `._paging.total` and `._paging.totalPages` response properties are now returned as integers, not strings.
- Bundled route handlers are now available for new first-party endpoints in WordPress 5.0.
- The project now uses Jest and ESLint in place of Mocha, Chai, JSCS and JSHint. Thank you for your years of service, ["nyan" reporter](https://mochajs.org/#nyan)!
- Browser bundle size has been reduced.


## v1.1.2 _If I Survive_

- Resolves an issue where authentication credentials where not maintained properly when iterating through pages of a connection with `._paging.next` or `._paging.prev`, props @motleydev for the reproducible bug report
Expand Down Expand Up @@ -43,9 +64,9 @@ v1.0 namesake album _Emotional Technology_ by BT.

- Add CHANGELOG.md
- Reduce complexity of, and rename, default routes JSON file
- BREAKING: Remove third "merge" argument from `.param()` method signature
- **BREAKING**: Remove third "merge" argument from `.param()` method signature
- Document `.settings()` top-level route handler
- BREAKING: Return API error objects directly from HTTP transport: only return a transport-level error object in the event of a non-API error
- **BREAKING**: Return API error objects directly from HTTP transport: only return a transport-level error object in the event of a non-API error
- Add `.status()` parameter method mixin
- Properly register `.password()` and `.sticky()` parameter mixins
- Utilize the HTTP transport methods during auto-discovery process
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
A WordPress REST API client for JavaScript
==========================================

This library is an isomorphic client for the [WordPress REST API](http://developer.wordpress.org/rest-api), designed to work with WordPress 4.7 or later. If you are using the older [WP REST API plugin](https://github.com/WP-API/WP-API), some commands will not work.
This library is an isomorphic client for the [WordPress REST API](http://developer.wordpress.org/rest-api), designed to work with WordPress 5.0 or later. If you are using the older [WP REST API plugin](https://github.com/WP-API/WP-API) or WordPress 4.9, some commands will not work.

[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/wp-api/node-wpapi?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

Expand Down Expand Up @@ -41,7 +41,7 @@ To get started, `npm install wpapi` or [download the browser build](https://wp-a

## Installation

`node-wpapi` works both on the server or in the browser. Node.js version 8 or higher is required, and the latest LTS release is recommended.
`node-wpapi` works both on the server or in the browser. Node.js version 8.6 or higher (or version 8.2.1 with the `--harmony` flag) is required, and the latest LTS release is recommended.

In the browser `node-wpapi` officially supports the latest two versions of all evergreen browsers, and Internet Explorer 11.

Expand Down Expand Up @@ -524,7 +524,7 @@ Files may be uploaded to the WordPress media library by creating a media record
The file to upload can be specified as

- a `String` describing an image file path, _e.g._ `'/path/to/the/image.jpg'`
- a `Buffer` with file content, _e.g._ `new Buffer()`
- a `Buffer` with file content, _e.g._ `Buffer.from()` (or the result of a `readFile` call)
- a file object from a `<input>` element, _e.g._ `document.getElementById( 'file-input' ).files[0]`

The file is passed into the `.file()` method:
Expand All @@ -533,7 +533,7 @@ The file is passed into the `.file()` method:
wp.media().file(content [, name])...
```

The optional second string argument specifies the file name to use for the uploaded media. If the name argument is omitted `file()` will try to infer a filename from the provided content.
The optional second string argument specifies the file name to use for the uploaded media. If the name argument is omitted `file()` will try to infer a filename from the provided file path. Note that when uploading a Buffer object `name` is a required argument, because no name can be automatically inferred from the buffer.

#### Adding Media to a Post

Expand Down
11 changes: 10 additions & 1 deletion lib/constructors/wp-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,11 @@ WPRequest.prototype.auth = function( credentials ) {
* .file( '/path/to/file.jpg' )
* .create({})...
*
* wp.media()
* // Pass .file() an image as a Buffer object, and a filename string
* .file( imgBuffer, 'desired-title.jpg' )
* .create({})...
*
* @example <caption>within a browser context</caption>
*
* wp.media()
Expand All @@ -644,10 +649,14 @@ WPRequest.prototype.auth = function( credentials ) {
* @chainable
* @param {string|object} file A path to a file (in Node) or an file object
* (Node or Browser) to attach to the request
* @param {string} [name] An (optional) filename to use for the file
* @param {string} [name] A filename to use for the file, required when
* providing file data as a Buffer object
* @returns {WPRequest} The WPRequest instance (for chaining)
*/
WPRequest.prototype.file = function( file, name ) {
if ( global.Buffer && file instanceof global.Buffer && ! name ) {
throw new Error( '.file(): File name is a required argument when uploading a Buffer' );
}
this._attachment = file;
// Explicitly set to undefined if not provided, to override any previously-
// set attachment name property that might exist from a prior `.file()` call
Expand Down
2 changes: 1 addition & 1 deletion lib/util/named-group-regexp.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const pattern = [
'[>\']',
// Get everything up to the end of the capture group: this is the RegExp used
// when matching URLs to this route, which we can use for validation purposes.
'([^\\)]*)',
'([^\\)]*(\\))?\\??)',
// Capture group end
'\\)',
].join( '' );
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"url": "http://www.kadamwhite.com"
},
"name": "wpapi",
"version": "1.1.2",
"version": "1.2.2",
"description": "An isomorphic JavaScript client for interacting with the WordPress REST API",
"main": "wpapi.js",
"repository": {
Expand Down Expand Up @@ -59,6 +59,7 @@
"test": "jest --coverage"
},
"dependencies": {
"li": "^1.3.0",
"parse-link-header": "^1.0.1",
"qs": "^6.6.0",
"superagent": "^4.0.0"
Expand All @@ -78,7 +79,6 @@
"jest": "^23.6.0",
"jsdoc": "^3.4.3",
"kramed": "^0.5.6",
"li": "^1.3.0",
"load-grunt-tasks": "^3.5.0",
"lodash.reduce": "^4.6.0",
"minami": "^1.2.3",
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/lib/util/named-group-regexp.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,12 @@ describe( 'named PCRE group RegExp', () => {
expect( result[ 2 ] ).toBe( '' );
} );

it( 'correctly handles WP 5.5 plugins routes', () => {
const path = '(?P<plugin>[^.\\/]+(?:\\/[^.\\/]+)?)';
const result = path.match( namedGroupRE );
expect( result ).not.toBeNull();
expect( result[ 1 ] ).toBe( 'plugin' );
expect( result[ 2 ] ).toBe( '[^.\\/]+(?:\\/[^.\\/]+)?' );
} );

} );