strapi-plugin-meilisearch 0.9.1 → 0.9.2

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/README.md CHANGED
@@ -530,7 +530,7 @@ If you are using [Strapi v3](https://github.com/strapi/strapi/tree/v3.6.9), plea
530
530
 
531
531
  **Supported Meilisearch versions**:
532
532
 
533
- This package only guarantees the compatibility with the [version v0.30.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.30.0).
533
+ This package guarantees compatibility with [version v1.x of Meilisearch](https://github.com/meilisearch/meilisearch/releases/latest), but some features may not be present. Please check the [issues](https://github.com/meilisearch/strapi-plugin-meilisearch/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22+label%3Aenhancement) for more info.
534
534
 
535
535
  **Node / NPM versions**:
536
536
 
@@ -73,7 +73,7 @@ export function useCollection() {
73
73
  refetchCollection()
74
74
  handleNotification({
75
75
  type: 'success',
76
- message: 'Request to delete content-type is succesfull',
76
+ message: 'Request to delete content-type is successful',
77
77
  blockTransition: false,
78
78
  })
79
79
  }
@@ -96,7 +96,7 @@ export function useCollection() {
96
96
  refetchCollection()
97
97
  handleNotification({
98
98
  type: 'success',
99
- message: 'Request to add a content-type is succesfull',
99
+ message: 'Request to add a content-type is successful',
100
100
  blockTransition: false,
101
101
  })
102
102
  }
@@ -119,7 +119,7 @@ export function useCollection() {
119
119
  refetchCollection()
120
120
  handleNotification({
121
121
  type: 'success',
122
- message: 'Request to update content-type is succesfull',
122
+ message: 'Request to update content-type is successful',
123
123
  blockTransition: false,
124
124
  })
125
125
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "strapi-plugin-meilisearch",
3
- "version": "0.9.1",
3
+ "version": "0.9.2",
4
4
  "description": "Synchronise and search in your Strapi content-types with Meilisearch",
5
5
  "scripts": {
6
6
  "playground:dev": "yarn --cwd ./playground && yarn --cwd ./playground dev",
@@ -109,4 +109,63 @@ describe('Tests content types', () => {
109
109
  },
110
110
  })
111
111
  })
112
+
113
+ test('sanitizes the private fields from the entries', async () => {
114
+ const pluginMock = jest.fn(() => ({
115
+ // This rewrites only the needed methods to reach the system under test (removeSensitiveFields)
116
+ service: jest.fn().mockImplementation(() => {
117
+ return {
118
+ async actionInBatches({ contentType = 'restaurant', callback }) {
119
+ await callback({
120
+ entries: [
121
+ { id: 1, title: 'title', secret: '123' },
122
+ { id: 2, title: 'abc', secret: '234' },
123
+ ],
124
+ contentType,
125
+ })
126
+ },
127
+ getCollectionName: ({ contentType }) => contentType,
128
+ addIndexedContentType: jest.fn(),
129
+ subscribeContentType: jest.fn(),
130
+ getCredentials: () => ({}),
131
+ }
132
+ }),
133
+ }))
134
+
135
+ const service = createMeilisearchService({
136
+ strapi: {
137
+ plugin: pluginMock,
138
+ contentTypes: {
139
+ restaurant: {
140
+ attributes: {
141
+ id: { private: false },
142
+ title: { private: false },
143
+ secret: { private: true },
144
+ },
145
+ },
146
+ },
147
+ config: { get: jest.fn(() => ({ restaurant: jest.fn() })) },
148
+ },
149
+ })
150
+
151
+ await service.addContentTypeInMeiliSearch({ contentType: 'restaurant' })
152
+
153
+ expect(Meilisearch().index).toHaveBeenCalledWith('restaurant')
154
+ expect(Meilisearch().index().addDocuments).toHaveBeenNthCalledWith(
155
+ 1,
156
+ [
157
+ {
158
+ _meilisearch_id: 'restaurant-1',
159
+ id: 1,
160
+ title: 'title',
161
+ },
162
+ {
163
+ _meilisearch_id: 'restaurant-2',
164
+ id: 2,
165
+ title: 'abc',
166
+ },
167
+ ],
168
+ { primaryKey: '_meilisearch_id' }
169
+ )
170
+ })
112
171
  })
@@ -12,5 +12,5 @@ const packageJson = require('../../../package.json')
12
12
  module.exports = config =>
13
13
  new Meilisearch({
14
14
  ...config,
15
- clientAgents: [`Meilisearch Strapi ${packageJson.version}`],
15
+ clientAgents: [`Meilisearch Strapi (v${packageJson.version})`],
16
16
  })
@@ -188,10 +188,16 @@ module.exports = ({ strapi }) => {
188
188
  *
189
189
  * @return {Array<Object>} - Entries
190
190
  */
191
- removeSensitiveFields: function ({ entries }) {
191
+ removeSensitiveFields: function ({ contentType, entries }) {
192
+ // TODO: should be persisted somewhere to make it more performant
193
+ const attrs = strapi.contentTypes[contentType].attributes
194
+ const privateFields = Object.entries(attrs).map(([field, schema]) =>
195
+ schema.private ? field : false
196
+ )
197
+
192
198
  return entries.map(entry => {
193
- delete entry.createdBy
194
- delete entry.updatedBy
199
+ privateFields.forEach(attr => delete entry[attr])
200
+
195
201
  return entry
196
202
  })
197
203
  },
@@ -37,8 +37,11 @@ const sanitizeEntries = async function ({
37
37
  entries,
38
38
  })
39
39
 
40
- // Remove nested
41
- entries = await config.removeSensitiveFields({ entries })
40
+ // Remove sensitive fields (private = true)
41
+ entries = await config.removeSensitiveFields({
42
+ contentType,
43
+ entries,
44
+ })
42
45
 
43
46
  // Apply transformEntry plugin config.
44
47
  entries = await config.transformEntries({