From ad038d9761662b8eb54bc349bf14b3435b39acfe Mon Sep 17 00:00:00 2001 From: "K. Adam White" Date: Tue, 22 Jan 2019 23:29:58 -0500 Subject: [PATCH 01/12] Update supported WP version to 5.0 and add v1.2 changelog --- CHANGELOG.md | 13 +++++++++++-- README.md | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b942932..4e92a11e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## v1.2 _Space Is Only Noise_ + +- **BREAKING**: The minimum supported node version is now v8. +- **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 @@ -43,9 +52,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 diff --git a/README.md b/README.md index 349408c3..c7a78f38 100644 --- a/README.md +++ b/README.md @@ -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) From 71b1e2d7fb4f21ec5328c52bf312416412865f3e Mon Sep 17 00:00:00 2001 From: "K. Adam White" Date: Tue, 22 Jan 2019 23:39:05 -0500 Subject: [PATCH 02/12] Release v2.0 "Space Is Only Noise" Changes since v1.1.2: - **BREAKING**: The minimum supported node version is now v8. - **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. Props @computamike. --- CHANGELOG.md | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e92a11e..e8a70031 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## v1.2 _Space Is Only Noise_ +## v1.2.0 _Space Is Only Noise_ - **BREAKING**: The minimum supported node version is now v8. - **BREAKING**: `._paging.total` and `._paging.totalPages` response properties are now returned as integers, not strings. diff --git a/package.json b/package.json index f386de0d..6fae16c3 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "url": "http://www.kadamwhite.com" }, "name": "wpapi", - "version": "1.1.2", + "version": "1.2.0", "description": "An isomorphic JavaScript client for interacting with the WordPress REST API", "main": "wpapi.js", "repository": { From dafddc445d69b6e97442c4b5c53d60c2f5d3ee27 Mon Sep 17 00:00:00 2001 From: Jerome Olvera <11675668+jerolan@users.noreply.github.com> Date: Wed, 23 Jan 2019 09:20:45 -0600 Subject: [PATCH 03/12] Fix missing module `li` (#416) Fix #414 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6fae16c3..eada1fe1 100644 --- a/package.json +++ b/package.json @@ -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" @@ -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", From 1b0650fb274ed78deb3b570b6519a33428c9aad0 Mon Sep 17 00:00:00 2001 From: "K. Adam White" Date: Wed, 23 Jan 2019 10:23:09 -0500 Subject: [PATCH 04/12] Release v1.2.1 "Colomb" - Fix issue where `li` was improperly declared as a dev-only dependency props @el-lsan & @jerolan --- CHANGELOG.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e8a70031..c6d3c72d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 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. diff --git a/package.json b/package.json index eada1fe1..1f684a46 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "url": "http://www.kadamwhite.com" }, "name": "wpapi", - "version": "1.2.0", + "version": "1.2.1", "description": "An isomorphic JavaScript client for interacting with the WordPress REST API", "main": "wpapi.js", "repository": { From b2b61238e44b448679028ad86d990d07f40099a8 Mon Sep 17 00:00:00 2001 From: K Adam White Date: Wed, 23 Jan 2019 12:53:19 -0500 Subject: [PATCH 05/12] Throw error if name argument is not provided to .file() when uploading a buffer (#418) Fixes #344 props @cungminh2710, @mvhirsch --- README.md | 4 ++-- lib/constructors/wp-request.js | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c7a78f38..31fc4709 100644 --- a/README.md +++ b/README.md @@ -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 `` element, _e.g._ `document.getElementById( 'file-input' ).files[0]` The file is passed into the `.file()` method: @@ -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 diff --git a/lib/constructors/wp-request.js b/lib/constructors/wp-request.js index d5d9cd0b..78eaeda4 100644 --- a/lib/constructors/wp-request.js +++ b/lib/constructors/wp-request.js @@ -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 within a browser context * * wp.media() @@ -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 From ac9a4fe0c722867e3613eefcc8cd1ce06c3d640d Mon Sep 17 00:00:00 2001 From: "K. Adam White" Date: Wed, 23 Jan 2019 12:55:00 -0500 Subject: [PATCH 06/12] Add changelog note for .file() argument validation --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c6d3c72d..bad1dcc2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,16 @@ # Changelog + +## v1.2.2 _(future release)_ + +- 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. From f6fe753715e63a3a026dee142ec8f2bcb9f435ef Mon Sep 17 00:00:00 2001 From: "K. Adam White" Date: Thu, 24 Jan 2019 14:21:51 -0500 Subject: [PATCH 07/12] Clarify supported Node versions are >= 8.6 or 8.2.1 --harmony @HoraceShmorace rightly comments that we have not made our conformance to semver (or lack thereof) clear, and the Node support matrix change in 1.2 constitutes an insufficiently-announced breaking change. This commit updates the README and CHANGELOG to clarify that this library will only run correctly on Node versions later than 8.2.1 `--harmony`, not simply any version of Node v8. Closes #419 --- CHANGELOG.md | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bad1dcc2..2f3613b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ ## v1.2.0 _Space Is Only Noise_ -- **BREAKING**: The minimum supported node version is now v8. +- **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)! diff --git a/README.md b/README.md index 31fc4709..9341e491 100644 --- a/README.md +++ b/README.md @@ -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. From e51ec0e303c6d26e8b05f323490cd8e345dd6950 Mon Sep 17 00:00:00 2001 From: Alessandro Manias Date: Tue, 16 Feb 2021 11:49:19 +0100 Subject: [PATCH 08/12] Fixed regexp for named route --- lib/util/named-group-regexp.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/util/named-group-regexp.js b/lib/util/named-group-regexp.js index 0a927dd8..21cb03f1 100644 --- a/lib/util/named-group-regexp.js +++ b/lib/util/named-group-regexp.js @@ -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( '' ); From d6ca2cc67835033245ebe8235007dd62ff0b2490 Mon Sep 17 00:00:00 2001 From: Alessandro Manias Date: Tue, 16 Feb 2021 11:53:00 +0100 Subject: [PATCH 09/12] Fixed some copy an paste mistakes --- lib/util/named-group-regexp.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/util/named-group-regexp.js b/lib/util/named-group-regexp.js index 21cb03f1..3eaeb787 100644 --- a/lib/util/named-group-regexp.js +++ b/lib/util/named-group-regexp.js @@ -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( '' ); From 7195506dbb754a0b5519a1492b49380be9c7a966 Mon Sep 17 00:00:00 2001 From: K Adam White Date: Mon, 10 May 2021 17:43:10 -0400 Subject: [PATCH 10/12] Name v1.2.2 and update changelog for backported #479 --- CHANGELOG.md | 3 ++- package.json | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f3613b1..4b91f5a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,9 @@ # Changelog -## v1.2.2 _(future release)_ +## 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 diff --git a/package.json b/package.json index 1f684a46..55a7043f 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "url": "http://www.kadamwhite.com" }, "name": "wpapi", - "version": "1.2.1", + "version": "1.2.2", "description": "An isomorphic JavaScript client for interacting with the WordPress REST API", "main": "wpapi.js", "repository": { From 216a057f6a7e21ef9aab3ea8014db28c55be9a2f Mon Sep 17 00:00:00 2001 From: K Adam White Date: Mon, 10 May 2021 17:55:03 -0400 Subject: [PATCH 11/12] Add test for WP5.5 path regex and update pattern for proper matching --- lib/util/named-group-regexp.js | 2 +- tests/unit/lib/util/named-group-regexp.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/util/named-group-regexp.js b/lib/util/named-group-regexp.js index 3eaeb787..632757c3 100644 --- a/lib/util/named-group-regexp.js +++ b/lib/util/named-group-regexp.js @@ -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( '' ); diff --git a/tests/unit/lib/util/named-group-regexp.js b/tests/unit/lib/util/named-group-regexp.js index 66a2ed5a..8ea05b1c 100644 --- a/tests/unit/lib/util/named-group-regexp.js +++ b/tests/unit/lib/util/named-group-regexp.js @@ -46,4 +46,12 @@ describe( 'named PCRE group RegExp', () => { expect( result[ 2 ] ).toBe( '' ); } ); + it( 'correctly handles WP 5.5 plugins routes', () => { + const path = '(?P[^.\\/]+(?:\\/[^.\\/]+)?)'; + const result = path.match( namedGroupRE ); + expect( result ).not.toBeNull(); + expect( result[ 1 ] ).toBe( 'plugin' ); + expect( result[ 2 ] ).toBe( '[^.\\/]+(?:\\/[^.\\/]+)?' ); + } ); + } ); From 54d64444212bf24fddb25cae955650b9b8a8e3ad Mon Sep 17 00:00:00 2001 From: K Adam White Date: Mon, 10 May 2021 17:57:32 -0400 Subject: [PATCH 12/12] Release v1.2.2 "Metaphorical Music" - Fix route match error with WordPress 5.5 - Throw an error early when .file() is passed a Buffer without an accompanying name string Props @socrates77, @cungminh2710 & @mvhirsch