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 +1 -1
- package/admin/src/Hooks/useCollection.js +3 -3
- package/package.json +1 -1
- package/server/__tests__/meilisearch.test.js +59 -0
- package/server/services/meilisearch/client.js +1 -1
- package/server/services/meilisearch/config.js +9 -3
- package/server/services/meilisearch/connector.js +5 -2
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
|
|
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
|
|
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
|
|
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
|
|
122
|
+
message: 'Request to update content-type is successful',
|
|
123
123
|
blockTransition: false,
|
|
124
124
|
})
|
|
125
125
|
}
|
package/package.json
CHANGED
|
@@ -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
|
})
|
|
@@ -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
|
|
194
|
-
|
|
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
|
|
41
|
-
entries = await config.removeSensitiveFields({
|
|
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({
|