@plone/volto 14.0.0 → 14.0.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Change Log
2
2
 
3
+ ## 14.0.1 (2021-12-21)
4
+
5
+ ### Bugfix
6
+
7
+ - Construct request with list parameters as separate querystring key value pairs according Zope convention @ksuess
8
+
3
9
  ## 14.0.0 (2021-12-20)
4
10
 
5
11
  ### Breaking
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  }
10
10
  ],
11
11
  "license": "MIT",
12
- "version": "14.0.0",
12
+ "version": "14.0.1",
13
13
  "repository": {
14
14
  "type": "git",
15
15
  "url": "git@github.com:plone/volto.git"
@@ -14,7 +14,7 @@ describe('api middleware helpers', () => {
14
14
  const result = addExpandersToPath('/de/mypage', GET_CONTENT);
15
15
  expect(result).toEqual('/de/mypage?expand=mycustomexpander');
16
16
  });
17
- it('addExpandersToPath with expanders already present (multilingual)', () => {
17
+ it('addExpandersToPath - Custom expander from settings, with expander (translation) already present (multilingual) in query', () => {
18
18
  config.settings.apiExpanders = [
19
19
  {
20
20
  match: '/',
@@ -28,7 +28,7 @@ describe('api middleware helpers', () => {
28
28
  );
29
29
  expect(result).toEqual('/de/mypage?expand=translations,mycustomexpander');
30
30
  });
31
- it('addExpandersToPath not matching', () => {
31
+ it('addExpandersToPath - Path not matching', () => {
32
32
  config.settings.apiExpanders = [
33
33
  {
34
34
  match: '/de/otherpath',
@@ -39,7 +39,7 @@ describe('api middleware helpers', () => {
39
39
  const result = addExpandersToPath('/de/mypage', GET_CONTENT);
40
40
  expect(result).toEqual('/de/mypage');
41
41
  });
42
- it('addExpandersToPath not matching, preserve query', () => {
42
+ it('addExpandersToPath - Path not matching, preserve query', () => {
43
43
  config.settings.apiExpanders = [
44
44
  {
45
45
  match: '/de/otherpath',
@@ -53,7 +53,7 @@ describe('api middleware helpers', () => {
53
53
  );
54
54
  expect(result).toEqual('/de/mypage/@navigation?expand.navigation.depth=3');
55
55
  });
56
- it('addExpandersToPath should work as expected, several', () => {
56
+ it('addExpandersToPath - Two custom expanders from settings', () => {
57
57
  config.settings.apiExpanders = [
58
58
  {
59
59
  match: '/',
@@ -67,7 +67,7 @@ describe('api middleware helpers', () => {
67
67
  '/de/mypage?expand=mycustomexpander,mycustomexpander2',
68
68
  );
69
69
  });
70
- it('addExpandersToPath should work as expected, already query present', () => {
70
+ it('addExpandersToPath - Two custom expanders from settings, expansion nested (with dots notation) present', () => {
71
71
  config.settings.apiExpanders = [
72
72
  {
73
73
  match: '/',
@@ -84,7 +84,7 @@ describe('api middleware helpers', () => {
84
84
  '/de/mypage/@navigation?expand=mycustomexpander,mycustomexpander2&expand.navigation.depth=3',
85
85
  );
86
86
  });
87
- it('addExpandersToPath should work as expected, already query present', () => {
87
+ it('addExpandersToPath - Two custom expanders from settings, query present ', () => {
88
88
  config.settings.apiExpanders = [
89
89
  {
90
90
  match: '/',
@@ -101,4 +101,55 @@ describe('api middleware helpers', () => {
101
101
  '/de/mypage/@navigation?expand=mycustomexpander,mycustomexpander2&expand.navigation.depth=3&someotherquery=1',
102
102
  );
103
103
  });
104
+ it('addExpandersToPath - Two custom expanders from settings, a list parameter present', () => {
105
+ config.settings.apiExpanders = [
106
+ {
107
+ match: '/',
108
+ GET_CONTENT: ['mycustomexpander', 'mycustomexpander2'],
109
+ },
110
+ ];
111
+
112
+ const result = addExpandersToPath(
113
+ '/de/mypage/@navigation?expand.navigation.depth=3&someotherquery=1&someotherquery=2',
114
+ GET_CONTENT,
115
+ );
116
+ // No need to stringify
117
+ expect(result).toEqual(
118
+ '/de/mypage/@navigation?expand=mycustomexpander,mycustomexpander2&expand.navigation.depth=3&someotherquery=1&someotherquery=2',
119
+ );
120
+ });
121
+ it('addExpandersToPath - Two custom expanders from settings, a list parameter present, and a translation expand already in query', () => {
122
+ config.settings.apiExpanders = [
123
+ {
124
+ match: '/',
125
+ GET_CONTENT: ['mycustomexpander', 'mycustomexpander2'],
126
+ },
127
+ ];
128
+
129
+ const result = addExpandersToPath(
130
+ '/de/mypage/@navigation?expand=translations&expand.navigation.depth=3&someotherquery=1&someotherquery=2',
131
+ GET_CONTENT,
132
+ );
133
+ // No need to stringify
134
+ expect(result).toEqual(
135
+ '/de/mypage/@navigation?expand=translations,mycustomexpander,mycustomexpander2&expand.navigation.depth=3&someotherquery=1&someotherquery=2',
136
+ );
137
+ });
138
+ it('addExpandersToPath - Two custom expanders from settings, a list parameter present, and a two expand present already in query', () => {
139
+ config.settings.apiExpanders = [
140
+ {
141
+ match: '/',
142
+ GET_CONTENT: ['mycustomexpander', 'mycustomexpander2'],
143
+ },
144
+ ];
145
+
146
+ const result = addExpandersToPath(
147
+ '/de/mypage/@navigation?expand=translations,secondexpand&expand.navigation.depth=3&someotherquery=1&someotherquery=2',
148
+ GET_CONTENT,
149
+ );
150
+ // No need to stringify
151
+ expect(result).toEqual(
152
+ '/de/mypage/@navigation?expand=translations,secondexpand,mycustomexpander,mycustomexpander2&expand.navigation.depth=3&someotherquery=1&someotherquery=2',
153
+ );
154
+ });
104
155
  });
@@ -22,6 +22,13 @@ let socket = null;
22
22
  /**
23
23
  *
24
24
  * Add configured expanders to an api call for an action
25
+ * Requirements:
26
+ *
27
+ * - It should add the expanders set in the config settings
28
+ * - It should preserve any query if present
29
+ * - It should preserve (and add) any expand parameter (if present) e.g. translations
30
+ * - It should take use the correct codification for arrays in querystring (repeated parameter for each member of the array)
31
+ *
25
32
  * @function addExpandersToPath
26
33
  * @param {string} path The url/path including the querystring
27
34
  * @param {*} type The action type
@@ -31,24 +38,38 @@ export function addExpandersToPath(path, type) {
31
38
  const { settings } = config;
32
39
  const { apiExpanders = [] } = settings;
33
40
 
34
- const pathPart = path.split('?')[0] || '';
35
- const expanders = apiExpanders
36
- .filter((expand) => matchPath(pathPart, expand.match) && expand[type])
41
+ const {
42
+ url,
43
+ query: { expand, ...query },
44
+ } = qs.parseUrl(path);
45
+
46
+ const expandersFromConfig = apiExpanders
47
+ .filter((expand) => matchPath(url, expand.match) && expand[type])
37
48
  .map((expand) => expand[type]);
38
- const query = qs.parse(qs.extract(path));
39
- const expand = compact(union([query.expand, ...flatten(expanders)]));
40
- if (expand) {
41
- query.expand = expand;
42
- }
49
+
50
+ const expandMerge = compact(union([expand, ...flatten(expandersFromConfig)]));
51
+
52
+ const stringifiedExpand = qs.stringify(
53
+ { expand: expandMerge },
54
+ {
55
+ arrayFormat: 'comma',
56
+ encode: false,
57
+ },
58
+ );
59
+
43
60
  const stringifiedQuery = qs.stringify(query, {
44
- arrayFormat: 'comma',
45
61
  encode: false,
46
62
  });
47
- if (!stringifiedQuery) {
48
- return pathPart;
49
- }
50
63
 
51
- return `${pathPart}?${stringifiedQuery}`;
64
+ if (stringifiedQuery && stringifiedExpand) {
65
+ return `${url}?${stringifiedExpand}&${stringifiedQuery}`;
66
+ } else if (!stringifiedQuery && stringifiedExpand) {
67
+ return `${url}?${stringifiedExpand}`;
68
+ } else if (stringifiedQuery && !stringifiedExpand) {
69
+ return `${url}?${stringifiedQuery}`;
70
+ } else {
71
+ return url;
72
+ }
52
73
  }
53
74
 
54
75
  /**