Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: cusyio/plone-js-sdk
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.0.0
Choose a base ref
...
head repository: cusyio/plone-js-sdk
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
  • 20 commits
  • 7 files changed
  • 1 contributor

Commits on Oct 18, 2021

  1. chore:

    thomasmassmann committed Oct 18, 2021
    Copy the full SHA
    2bb2731 View commit details
  2. Copy the full SHA
    120e64c View commit details

Commits on Oct 19, 2021

  1. Copy the full SHA
    ca4c20e View commit details
  2. feat: ✨ add querystringSearch method

    Uses post request to get results from @querystring-search endpoint.
    thomasmassmann committed Oct 19, 2021
    Copy the full SHA
    78c6aec View commit details
  3. Copy the full SHA
    5018f6e View commit details
  4. v1.1.0

    thomasmassmann committed Oct 19, 2021
    Copy the full SHA
    2ae310b View commit details
  5. Copy the full SHA
    a4a368c View commit details

Commits on Oct 25, 2021

  1. Copy the full SHA
    6ca86ad View commit details
  2. Copy the full SHA
    c32f6e6 View commit details
  3. v1.2.0

    thomasmassmann committed Oct 25, 2021
    Copy the full SHA
    0462298 View commit details

Commits on Nov 2, 2021

  1. Copy the full SHA
    37847d2 View commit details
  2. Copy the full SHA
    8ced008 View commit details
  3. chore(release): 1.3.0

    thomasmassmann committed Nov 2, 2021
    Copy the full SHA
    af70d64 View commit details

Commits on Nov 8, 2021

  1. chore: 👷 run compile after version change and before publishing to npm

    This ensures that correct version number is included in the release.
    thomasmassmann committed Nov 8, 2021
    Copy the full SHA
    1caf477 View commit details
  2. Copy the full SHA
    87d68d6 View commit details
  3. chore(release): 1.3.1

    thomasmassmann committed Nov 8, 2021
    Copy the full SHA
    15c968d View commit details
  4. Copy the full SHA
    8ece465 View commit details

Commits on Nov 9, 2021

  1. revert: 🐛 don’t add user-agent string for all requests

    This should only happen for server requests, but not client initiated requests (otherwise CORS errors might occur).
    thomasmassmann committed Nov 9, 2021
    Copy the full SHA
    e21c2c3 View commit details
  2. Copy the full SHA
    845a12a View commit details
  3. chore(release): 1.4.0

    thomasmassmann committed Nov 9, 2021
    Copy the full SHA
    df9103a View commit details
Showing with 1,015 additions and 24 deletions.
  1. +3 −1 .github/workflows/docs.yml
  2. +27 −1 CHANGELOG.md
  3. +44 −2 docs/content/en/api.md
  4. +7 −0 docs/nuxt.config.js
  5. +9 −5 package.json
  6. +25 −4 src/index.js
  7. +900 −11 yarn.lock
4 changes: 3 additions & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: docs

on: [push, pull_request]
on:
release:
types: [released]

jobs:
cd:
28 changes: 27 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
# Changelog

## 1.0.0 (unreleased)
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [1.4.0](https://github.com/cusyio/plone-js-sdk/compare/v1.3.1...v1.4.0) (2021-11-09)


### Features

* :sparkles: allow custom headers to be set when initializing the client ([845a12a](https://github.com/cusyio/plone-js-sdk/commit/845a12ae1007846c1cb8eeae081f4ac82325bbfd))

## [1.3.1](https://github.com/cusyio/plone-js-sdk/compare/v1.3.0...v1.3.1) (2021-11-08)

## [1.3.0](https://github.com/cusyio/plone-js-sdk/compare/v1.2.0...v1.3.0) (2021-11-02)

### Features

- set custom user agent header for the axios http client ([37847d2](https://github.com/cusyio/plone-js-sdk/commit/37847d23137051a1a6f00f1bffaf798ef4777c7c))

## 1.2.0 (2021-10-25)

- Bugfix: Include initial items when fetching collection.
- Increase initial timeout to 60 seconds.

## 1.1.0 (2021-10-19)

- Add `querystringSearch` to get results from @querystring-search endpoint.

## 1.0.0 (2021-10-18)

- Initial release.
- Support for Plone REST-API 7.x and newer.
46 changes: 44 additions & 2 deletions docs/content/en/api.md
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ Query the Plone REST-API.
- `path` (type: `string`) The relative path to search within.
- `query` (type: `object`) API query options.
- `options` (type: `object`) Additional axios options for the request.
- **Returns**: `string` The raw API response in JSON format.
- **Returns**: `object` A search result object.

This is the base for all requests to the Plone REST-API.
We do some URL normalization and then call the api.
@@ -55,7 +55,7 @@ Search for content using the built-in `search` endpoint.
- `path` (type: `string`) The relative path to search within.
- `query` (type: `object`) API query options.
- `options` (type: `object`) Additional axios options for the request.
- **Returns**: `string` The raw API response in JSON format.
- **Returns**: `object` A search result object with items.

<alert type="info">

@@ -88,6 +88,48 @@ const results = await client.search('/', query);
const newsItems = result.items;
```

## `async querystringSearch()`

Search for content using the built-in `querystring-search` endpoint.

- **Arguments**:
- `path` (type: `string`) The relative path to search within.
- `query` (type: `object`) API query options.
- `options` (type: `object`) Additional axios options for the request.
- **Returns**: `object` A search result object with items.

<alert type="info">

More information about the `querystring-search` endpoint is available at the [plone.restapi querystring-search documentation](https://plonerestapi.readthedocs.io/en/latest/querystringsearch.html).

</alert>

### Example: Get the next 5 upcoming events

```js
import PloneClient from '@cusy/plone-js';
const client = new PloneClient('http://localhost:8080/Plone');
const query = {
limit: 5,
query: [
{
i: 'portal_type',
o: 'plone.app.querystring.operation.selection.any',
v: ['Event'],
},
{
i: 'end',
o: 'plone.app.querystring.operation.date.afterToday',
v: '',
},
],
sort_on: 'start',
};

const results = await client.querystringSearch('/', query);
const events = result.items;
```

## `async fetchItems()`

Get all available Plone content.
7 changes: 7 additions & 0 deletions docs/nuxt.config.js
Original file line number Diff line number Diff line change
@@ -4,6 +4,13 @@ export default theme({
docs: {
primaryColor: '#0095D3',
},
hooks: {
render: {
route(url, result) {
result.html = result.html.replace(/<base [^>]*>/, '');
},
},
},
loading: { color: '#0095D3' },
pwa: {
manifest: {
14 changes: 9 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cusy/plone-js",
"version": "1.0.0",
"version": "1.4.0",
"private": false,
"description": "JavaScript client for Plone CMS",
"main": "dist/index.js",
@@ -12,11 +12,14 @@
"scripts": {
"compile": "rm -rf dist && mkdir dist && node build.js",
"lint": "eslint --ext .js src test",
"test": "jest",
"precommit": "lint-staged",
"prepublish": "yarn compile",
"preversion": "yarn test",
"postversion": "git push --tags && yarn publish . --tag $npm_package_version && git push && echo \"Successfully released version $npm_package_version!\""
"release": "yarn test && standard-version -a && git push --follow-tags && yarn publish",
"test": "jest"
},
"standard-version": {
"scripts": {
"postchangelog": "yarn compile"
}
},
"lint-staged": {
"*.js": [
@@ -37,6 +40,7 @@
"axios": "^0.21.1",
"axios-extensions": "^3.1.3",
"axios-retry": "^3.2.0",
"standard-version": "^9.3.2",
"ufo": "^0.7.5"
},
"devDependencies": {
29 changes: 25 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -66,6 +66,7 @@ const defaultOptions = {
enableRetry: true,
// Additional axios instance options.
axiosOptions: {},
headers: {},
};

/**
@@ -92,8 +93,10 @@ class PloneClient {
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
...clientOptions.headers,
},
timeout: 20000,
// 1 minute timeout might be necessary with Plone.
timeout: 60000,
// The adapters will always be available.
// You can configure if the caching adapter is enabled by default
// using the `enableCaching` option.
@@ -136,7 +139,7 @@ class PloneClient {
* @param {string} path The relative path to search within.
* @param {object} query API query options.
* @param {object} options Additional axios options for the request.
* @returns {string} The raw API response in JSON format.
* @returns {object} A search result object.
*/
async query(path, query = {}, options = {}) {
path = normalizeURL(path);
@@ -153,7 +156,7 @@ class PloneClient {
* @param {string} path The relative path to search within.
* @param {object} query API query options.
* @param {object} options Additional axios options for the request.
* @returns {array} A list of search results
* @returns {object} A search result object with items.
*/
async search(path = '', query = {}, options = {}) {
let url = path;
@@ -164,6 +167,24 @@ class PloneClient {
return await this.query(url, query, options);
}

/**
* Search for content using the built-in `querystring-search` endpoint.
*
* @param {string} path The relative path to search within.
* @param {object} query API query options.
* @param {object} options Additional axios options for the request.
* @returns {object} A search result object with items.
*/
async querystringSearch(path = '', query = {}, options = {}) {
let url = path;
if (!url.endsWith('@querystring-search')) {
// Ensure the @querystring-search endpoint is used.
url = joinURL(path, '@querystring-search');
}
const result = await this.$http.post(url, query, options);
return result?.data;
}

/**
* Get all available Plone content.
*
@@ -210,7 +231,7 @@ class PloneClient {
*/
async fetchCollection(path = '', query = {}, options = {}) {
const response = await this.query(path, query, options);
let items;
let items = response?.items;
if (response?.batching) {
items = await this.fetchItems(
path,
Loading