@vegan-friendly/strapi-plugin-elasticsearch 0.1.0-alpha.1 → 0.1.0-alpha.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.
Files changed (124) hide show
  1. package/dist/admin/src/components/Initializer/index.d.ts +15 -0
  2. package/dist/admin/src/components/Initializer/index.js +25 -0
  3. package/dist/admin/src/components/PluginIcon/index.d.ts +8 -0
  4. package/dist/admin/src/components/PluginIcon/index.js +14 -0
  5. package/dist/admin/src/components/SubNavigation/index.d.ts +4 -0
  6. package/dist/admin/src/components/SubNavigation/index.js +40 -0
  7. package/dist/admin/src/index.d.ts +8 -0
  8. package/dist/admin/src/index.js +92 -0
  9. package/dist/admin/src/pages/App/index.d.ts +9 -0
  10. package/dist/admin/src/pages/App/index.js +29 -0
  11. package/dist/admin/src/pages/ConfigureCollection/index.d.ts +3 -0
  12. package/dist/admin/src/pages/ConfigureCollection/index.js +193 -0
  13. package/dist/admin/src/pages/ConfigureCollectionList/index.d.ts +3 -0
  14. package/dist/admin/src/pages/ConfigureCollectionList/index.js +228 -0
  15. package/dist/admin/src/pages/Homepage/index.d.ts +3 -0
  16. package/dist/admin/src/pages/Homepage/index.js +155 -0
  17. package/dist/admin/src/pages/ViewIndexingRunLog/index.d.ts +3 -0
  18. package/dist/admin/src/pages/ViewIndexingRunLog/index.js +125 -0
  19. package/dist/admin/src/pluginId.d.ts +2 -0
  20. package/dist/admin/src/pluginId.js +8 -0
  21. package/dist/admin/src/utils/apiUrls.d.ts +10 -0
  22. package/dist/admin/src/utils/apiUrls.js +20 -0
  23. package/dist/admin/src/utils/axiosInstance.d.ts +5 -0
  24. package/dist/admin/src/utils/axiosInstance.js +33 -0
  25. package/dist/admin/src/utils/getTrad.d.ts +2 -0
  26. package/dist/admin/src/utils/getTrad.js +8 -0
  27. package/dist/server/bootstrap.js +125 -0
  28. package/dist/server/config/index.d.ts +0 -0
  29. package/dist/server/config/index.js +5 -0
  30. package/dist/server/content-types/index.d.ts +2 -0
  31. package/{server → dist/server}/content-types/index.js +7 -9
  32. package/dist/server/content-types/indexing-logs.d.ts +0 -0
  33. package/dist/server/content-types/indexing-logs.js +35 -0
  34. package/dist/server/content-types/name-prefix.d.ts +0 -0
  35. package/dist/server/content-types/name-prefix.js +1 -0
  36. package/dist/server/content-types/tasks.d.ts +0 -0
  37. package/dist/server/content-types/tasks.js +52 -0
  38. package/dist/server/controllers/configure-indexing.d.ts +0 -0
  39. package/dist/server/controllers/configure-indexing.js +58 -0
  40. package/dist/server/controllers/index.d.ts +5 -0
  41. package/{server → dist/server}/controllers/index.js +13 -15
  42. package/dist/server/controllers/log-indexing.d.ts +0 -0
  43. package/{server → dist/server}/controllers/log-indexing.js +10 -11
  44. package/dist/server/controllers/perform-indexing.d.ts +0 -0
  45. package/{server → dist/server}/controllers/perform-indexing.js +22 -28
  46. package/dist/server/controllers/perform-search.d.ts +1 -0
  47. package/dist/server/controllers/perform-search.js +29 -0
  48. package/dist/server/controllers/setup-info.d.ts +0 -0
  49. package/{server → dist/server}/controllers/setup-info.js +10 -14
  50. package/dist/server/destroy.d.ts +0 -0
  51. package/{server → dist/server}/destroy.js +4 -5
  52. package/dist/server/index.d.ts +10 -0
  53. package/{server → dist/server}/index.js +23 -25
  54. package/dist/server/middlewares/index.d.ts +0 -0
  55. package/{server → dist/server}/middlewares/index.js +2 -3
  56. package/dist/server/policies/index.d.ts +0 -0
  57. package/{server → dist/server}/policies/index.js +2 -3
  58. package/dist/server/register.d.ts +0 -0
  59. package/{server → dist/server}/register.js +4 -5
  60. package/dist/server/routes/configure-indexing.d.ts +0 -0
  61. package/dist/server/routes/configure-indexing.js +43 -0
  62. package/dist/server/routes/index.d.ts +5 -0
  63. package/{server → dist/server}/routes/index.js +13 -13
  64. package/dist/server/routes/perform-indexing.d.ts +0 -0
  65. package/dist/server/routes/perform-indexing.js +25 -0
  66. package/dist/server/routes/perform-search.d.ts +0 -0
  67. package/dist/server/routes/perform-search.js +15 -0
  68. package/dist/server/routes/run-log.d.ts +0 -0
  69. package/dist/server/routes/run-log.js +13 -0
  70. package/dist/server/routes/setup-info.d.ts +0 -0
  71. package/dist/server/routes/setup-info.js +13 -0
  72. package/dist/server/services/configure-indexing.d.ts +24 -0
  73. package/dist/server/services/configure-indexing.js +161 -0
  74. package/dist/server/services/es-interface.d.ts +4 -0
  75. package/dist/server/services/es-interface.js +161 -0
  76. package/dist/server/services/helper.d.ts +34 -0
  77. package/{server → dist/server}/services/helper.js +269 -305
  78. package/dist/server/services/index.d.ts +7 -0
  79. package/{server → dist/server}/services/index.js +17 -21
  80. package/dist/server/services/log-indexing.d.ts +0 -0
  81. package/{server → dist/server}/services/log-indexing.js +27 -26
  82. package/dist/server/services/perform-indexing.d.ts +0 -0
  83. package/{server → dist/server}/services/perform-indexing.js +147 -173
  84. package/dist/server/services/schedule-indexing.d.ts +0 -0
  85. package/{server → dist/server}/services/schedule-indexing.js +61 -65
  86. package/dist/server/services/transform-content.d.ts +2 -0
  87. package/{server → dist/server}/services/transform-content.js +21 -22
  88. package/dist/strapi-admin.d.ts +0 -0
  89. package/{strapi-admin.js → dist/strapi-admin.js} +2 -3
  90. package/dist/strapi-server.d.ts +0 -0
  91. package/{strapi-server.js → dist/strapi-server.js} +2 -3
  92. package/package.json +24 -3
  93. package/.prettierrc +0 -7
  94. package/.vscode/settings.json +0 -24
  95. package/admin/src/components/Initializer/index.js +0 -26
  96. package/admin/src/components/PluginIcon/index.js +0 -12
  97. package/admin/src/components/SubNavigation/index.js +0 -48
  98. package/admin/src/index.js +0 -63
  99. package/admin/src/pages/App/index.js +0 -29
  100. package/admin/src/pages/ConfigureCollection/index.js +0 -225
  101. package/admin/src/pages/ConfigureCollectionList/index.js +0 -266
  102. package/admin/src/pages/Homepage/index.js +0 -168
  103. package/admin/src/pages/ViewIndexingRunLog/index.js +0 -124
  104. package/admin/src/pluginId.js +0 -5
  105. package/admin/src/translations/en.json +0 -1
  106. package/admin/src/translations/fr.json +0 -1
  107. package/admin/src/utils/apiUrls.js +0 -14
  108. package/admin/src/utils/axiosInstance.js +0 -40
  109. package/admin/src/utils/getTrad.js +0 -5
  110. package/server/bootstrap.js +0 -142
  111. package/server/config/index.js +0 -6
  112. package/server/content-types/indexing-logs.js +0 -35
  113. package/server/content-types/tasks.js +0 -52
  114. package/server/controllers/configure-indexing.js +0 -66
  115. package/server/controllers/perform-search.js +0 -31
  116. package/server/routes/configure-indexing.js +0 -42
  117. package/server/routes/perform-indexing.js +0 -24
  118. package/server/routes/perform-search.js +0 -14
  119. package/server/routes/run-log.js +0 -12
  120. package/server/routes/setup-info.js +0 -12
  121. package/server/services/configure-indexing.js +0 -184
  122. package/server/services/es-interface.js +0 -187
  123. package/server/services/virtual-collections-registry.js +0 -346
  124. /package/{server/content-types/name-prefix.js → dist/server/bootstrap.d.ts} +0 -0
@@ -1,305 +1,269 @@
1
-
2
- ///START : via https://raw.githubusercontent.com/Barelydead/strapi-plugin-populate-deep/main/server/helpers/index.js
3
-
4
- const { isEmpty, merge } = require("lodash/fp");
5
- const transformServiceProvider = require('./transform-content');
6
-
7
- const getPluginStore = () => {
8
- return strapi.store({
9
- environment: '',
10
- type: 'plugin',
11
- name: 'elasticsearch',
12
- });
13
- }
14
-
15
-
16
- const getModelPopulationAttributes = (model) => {
17
- if (model.uid === "plugin::upload.file") {
18
- const { related, ...attributes } = model.attributes;
19
- return attributes;
20
- }
21
-
22
- return model.attributes;
23
- };
24
-
25
- const getFullPopulateObject = (modelUid, maxDepth = 20, ignore) => {
26
- const skipCreatorFields = true;
27
-
28
- if (maxDepth <= 1) {
29
- return true;
30
- }
31
- if (modelUid === "admin::user" && skipCreatorFields) {
32
- return undefined;
33
- }
34
-
35
- const populate = {};
36
- const model = strapi.getModel(modelUid);
37
- if (ignore && !ignore.includes(model.collectionName)) ignore.push(model.collectionName)
38
- for (const [key, value] of Object.entries(
39
- getModelPopulationAttributes(model)
40
- )) {
41
- if (ignore?.includes(key)) continue
42
- if (value) {
43
- if (value.type === "component") {
44
- populate[key] = getFullPopulateObject(value.component, maxDepth - 1);
45
- } else if (value.type === "dynamiczone") {
46
- const dynamicPopulate = value.components.reduce((prev, cur) => {
47
- const curPopulate = getFullPopulateObject(cur, maxDepth - 1);
48
- return curPopulate === true ? prev : merge(prev, curPopulate);
49
- }, {});
50
- populate[key] = isEmpty(dynamicPopulate) ? true : dynamicPopulate;
51
- } else if (value.type === "relation") {
52
- const relationPopulate = getFullPopulateObject(
53
- value.target,
54
- (key === 'localizations') && maxDepth > 2 ? 1 : maxDepth - 1,
55
- ignore
56
- );
57
- if (relationPopulate) {
58
- populate[key] = relationPopulate;
59
- }
60
- } else if (value.type === "media") {
61
- populate[key] = true;
62
- }
63
- }
64
- }
65
- return isEmpty(populate) ? true : { populate };
66
- };
67
-
68
- ///END : via https://raw.githubusercontent.com/Barelydead/strapi-plugin-populate-deep/main/server/helpers/index.js
69
-
70
-
71
- /*
72
- //Example config to cover extraction cases
73
- collectionConfig[collectionName] = {
74
- 'major' : {index: true},
75
- 'sections' : { index: true, searchFieldName: 'information',
76
- 'subfields' : [
77
- { 'component' : 'try.paragraph',
78
- 'field' : 'Text'},
79
- { 'component' : 'try.paragraph',
80
- 'field' : 'Heading'},
81
- { 'component' : 'try.footer',
82
- 'field' : 'footer_link',
83
- 'subfields' :[ {
84
- 'component' : 'try.link',
85
- 'field' : 'display_text'
86
- }]
87
- }] },
88
- 'seo_details' : {
89
- index: true, searchFieldName: 'seo',
90
- 'subfields' : [
91
- {
92
- 'component' : 'try.seo',
93
- 'field' : 'meta_description'
94
- }
95
- ]
96
- },
97
- 'changelog' : {
98
- index: true, searchFieldName: 'breakdown',
99
- 'subfields' : [
100
- {
101
- 'component' : 'try.revision',
102
- 'field' : 'summary'
103
- }
104
- ]
105
- }
106
- }
107
- */
108
- function extractSubfieldData({config, data }) {
109
- let returnData = '';
110
- if (Array.isArray(data))
111
- {
112
- const dynDataItems = data;
113
- for (let r=0; r< dynDataItems.length; r++)
114
- {
115
- const extractItem = dynDataItems[r];
116
- for (let s=0; s<config.length; s++)
117
- {
118
- const conf = config[s];
119
- if (Object.keys(extractItem).includes('__component'))
120
- {
121
- if (conf.component === extractItem.__component &&
122
- !Object.keys(conf).includes('subfields') &&
123
- typeof extractItem[conf['field']] !== "undefined" &&
124
- extractItem[conf['field']])
125
- {
126
- let val = extractItem[conf['field']]
127
- if (Object.keys(conf).includes('transform')
128
- && conf['transform'] === 'markdown')
129
- val = transformServiceProvider.transform({content: val, from: 'markdown'});
130
- returnData = returnData + '\n' + val;
131
- }
132
- else if (conf.component === extractItem.__component &&
133
- Object.keys(conf).includes('subfields'))
134
- {
135
- returnData = returnData + '\n' + extractSubfieldData({
136
- config: conf['subfields'], data: extractItem[conf['field']]});
137
- }
138
- }
139
- else
140
- {
141
- if (!Object.keys(conf).includes('subfields') &&
142
- typeof extractItem[conf['field']] !== "undefined" &&
143
- extractItem[conf['field']])
144
- {
145
- let val = extractItem[conf['field']]
146
- if (Object.keys(conf).includes('transform')
147
- && conf['transform'] === 'markdown')
148
- val = transformServiceProvider.transform({content: val, from: 'markdown'});
149
- returnData = returnData + '\n' + val;
150
- }
151
- else if (Object.keys(conf).includes('subfields'))
152
- {
153
- returnData = returnData + '\n' + extractSubfieldData({
154
- config: conf['subfields'], data: extractItem[conf['field']]});
155
- }
156
- }
157
- }
158
- }
159
- }
160
- else //for single component as a field
161
- {
162
- for (let s=0; s<config.length; s++)
163
- {
164
- const conf = config[s];
165
- if (!Object.keys(conf).includes('subfields') &&
166
- typeof data[conf['field']] !== "undefined" &&
167
- data[conf['field']])
168
- returnData = returnData + '\n' + data[conf['field']]
169
- else if (Object.keys(conf).includes('subfields'))
170
- {
171
- returnData = returnData + '\n' + extractSubfieldData({
172
- config: conf['subfields'], data: data[conf['field']]});
173
- }
174
- }
175
- }
176
- return returnData;
177
- }
178
-
179
- module.exports = ({ strapi }) => ({
180
- async getElasticsearchInfo() {
181
- const configureService = strapi.plugins['elasticsearch'].services.configureIndexing;
182
- const esInterface = strapi.plugins['elasticsearch'].services.esInterface;
183
- const pluginConfig = await strapi.config.get('plugin.elasticsearch');
184
-
185
- const connected = pluginConfig.searchConnector && pluginConfig.searchConnector.host
186
- ? await esInterface.checkESConnection() : false;
187
-
188
- return {
189
- indexingCronSchedule : pluginConfig.indexingCronSchedule || "Not configured",
190
- elasticHost : pluginConfig.searchConnector ?
191
- pluginConfig.searchConnector.host || "Not configured" : "Not configured",
192
- elasticUserName : pluginConfig.searchConnector ?
193
- pluginConfig.searchConnector.username || "Not configured" : "Not configured",
194
- elasticCertificate : pluginConfig.searchConnector ?
195
- pluginConfig.searchConnector.certificate || "Not configured" : "Not configured",
196
- elasticIndexAlias : pluginConfig.indexAliasName || "Not configured",
197
- connected : connected,
198
- initialized : configureService.isInitialized()
199
- }
200
- },
201
- isCollectionDraftPublish({collectionName}) {
202
- const model = strapi.getModel(collectionName);
203
- return model.attributes.publishedAt ? true : false
204
- },
205
- getPopulateAttribute({collectionName}) {
206
- //TODO : We currently have set populate to upto 4 levels, should
207
- //this be configurable or a different default value?
208
- return getFullPopulateObject(collectionName, 4, []);
209
- },
210
- getIndexItemId ({collectionName, itemId}) {
211
- return collectionName+'::' + itemId;
212
- },
213
- async getCurrentIndexName () {
214
- const pluginStore = getPluginStore();
215
- const settings = await pluginStore.get({ key: 'configsettings' });
216
- let indexName = 'strapi-plugin-elasticsearch-index_000001';
217
- if (settings)
218
- {
219
- const objSettings = JSON.parse(settings);
220
- if (Object.keys(objSettings).includes('indexConfig'))
221
- {
222
- const idxConfig = objSettings['indexConfig'];
223
- indexName = idxConfig['name'];
224
- }
225
- }
226
- return indexName;
227
- },
228
- async getIncrementedIndexName () {
229
- const currentIndexName = await this.getCurrentIndexName();
230
- const number = parseInt(currentIndexName.split('index_')[1]);
231
- return 'strapi-plugin-elasticsearch-index_' + String(number+1).padStart(6,'0');
232
- },
233
- async storeCurrentIndexName (indexName) {
234
- const pluginStore = getPluginStore();
235
- const settings = await pluginStore.get({ key: 'configsettings' });
236
- if (settings)
237
- {
238
- const objSettings = JSON.parse(settings);
239
- objSettings['indexConfig'] = {'name' : indexName};
240
- await pluginStore.set({ key: 'configsettings', value : JSON.stringify(objSettings)});
241
- }
242
- else
243
- {
244
- const newSettings = JSON.stringify({'indexConfig' : {'name' : indexName}})
245
- await pluginStore.set({ key: 'configsettings', value : newSettings});
246
- }
247
- },
248
- modifySubfieldsConfigForExtractor(collectionConfig) {
249
- const collectionName = Object.keys(collectionConfig)[0];
250
- const attributes = Object.keys(collectionConfig[collectionName]);
251
- for (let r=0; r< attributes.length; r++)
252
- {
253
- const attr = attributes[r];
254
- const attribFields = Object.keys(collectionConfig[collectionName][attr]);
255
- if (attribFields.includes('subfields'))
256
- {
257
- const subfielddata = collectionConfig[collectionName][attr]['subfields'];
258
- if (subfielddata.length > 0)
259
- {
260
- try {
261
- const subfieldjson = JSON.parse(subfielddata)
262
- if (Object.keys(subfieldjson).includes('subfields'))
263
- collectionConfig[collectionName][attr]['subfields'] = subfieldjson['subfields']
264
- }
265
- catch(err)
266
- {
267
- continue;
268
- }
269
- }
270
- }
271
- }
272
- return collectionConfig;
273
- },
274
- extractDataToIndex({collectionName, data, collectionConfig}) {
275
- collectionConfig = this.modifySubfieldsConfigForExtractor(collectionConfig);
276
- const fti = Object.keys(collectionConfig[collectionName]);
277
- const document = {}
278
- for (let k = 0; k < fti.length; k++)
279
- {
280
- const fieldConfig = collectionConfig[collectionName][fti[k]];
281
- if (fieldConfig.index)
282
- {
283
- let val = null;
284
- if (Object.keys(fieldConfig).includes('subfields'))
285
- {
286
- val = extractSubfieldData({config: fieldConfig['subfields'], data: data[fti[k]]})
287
- val = val ? val.trim() : val
288
- }
289
- else
290
- {
291
- val = data[fti[k]];
292
- if (Object.keys(fieldConfig).includes('transform') &&
293
- fieldConfig['transform'] === 'markdown')
294
- val = transformServiceProvider.transform({content: val, from: 'markdown'});
295
- }
296
-
297
- if (Object.keys(fieldConfig).includes('searchFieldName'))
298
- document[fieldConfig['searchFieldName']] = val;
299
- else
300
- document[fti[k]] = val;
301
- }
302
- }
303
- return document;
304
- }
305
- });
1
+ "use strict";
2
+ ///START : via https://raw.githubusercontent.com/Barelydead/strapi-plugin-populate-deep/main/server/helpers/index.js
3
+ const { isEmpty, merge } = require("lodash/fp");
4
+ const transformServiceProvider = require('./transform-content');
5
+ const getPluginStore = () => {
6
+ return strapi.store({
7
+ environment: '',
8
+ type: 'plugin',
9
+ name: 'elasticsearch',
10
+ });
11
+ };
12
+ const getModelPopulationAttributes = (model) => {
13
+ if (model.uid === "plugin::upload.file") {
14
+ const { related, ...attributes } = model.attributes;
15
+ return attributes;
16
+ }
17
+ return model.attributes;
18
+ };
19
+ const getFullPopulateObject = (modelUid, maxDepth = 20, ignore) => {
20
+ const skipCreatorFields = true;
21
+ if (maxDepth <= 1) {
22
+ return true;
23
+ }
24
+ if (modelUid === "admin::user" && skipCreatorFields) {
25
+ return undefined;
26
+ }
27
+ const populate = {};
28
+ const model = strapi.getModel(modelUid);
29
+ if (ignore && !ignore.includes(model.collectionName))
30
+ ignore.push(model.collectionName);
31
+ for (const [key, value] of Object.entries(getModelPopulationAttributes(model))) {
32
+ if (ignore === null || ignore === void 0 ? void 0 : ignore.includes(key))
33
+ continue;
34
+ if (value) {
35
+ if (value.type === "component") {
36
+ populate[key] = getFullPopulateObject(value.component, maxDepth - 1);
37
+ }
38
+ else if (value.type === "dynamiczone") {
39
+ const dynamicPopulate = value.components.reduce((prev, cur) => {
40
+ const curPopulate = getFullPopulateObject(cur, maxDepth - 1);
41
+ return curPopulate === true ? prev : merge(prev, curPopulate);
42
+ }, {});
43
+ populate[key] = isEmpty(dynamicPopulate) ? true : dynamicPopulate;
44
+ }
45
+ else if (value.type === "relation") {
46
+ const relationPopulate = getFullPopulateObject(value.target, (key === 'localizations') && maxDepth > 2 ? 1 : maxDepth - 1, ignore);
47
+ if (relationPopulate) {
48
+ populate[key] = relationPopulate;
49
+ }
50
+ }
51
+ else if (value.type === "media") {
52
+ populate[key] = true;
53
+ }
54
+ }
55
+ }
56
+ return isEmpty(populate) ? true : { populate };
57
+ };
58
+ ///END : via https://raw.githubusercontent.com/Barelydead/strapi-plugin-populate-deep/main/server/helpers/index.js
59
+ /*
60
+ //Example config to cover extraction cases
61
+ collectionConfig[collectionName] = {
62
+ 'major' : {index: true},
63
+ 'sections' : { index: true, searchFieldName: 'information',
64
+ 'subfields' : [
65
+ { 'component' : 'try.paragraph',
66
+ 'field' : 'Text'},
67
+ { 'component' : 'try.paragraph',
68
+ 'field' : 'Heading'},
69
+ { 'component' : 'try.footer',
70
+ 'field' : 'footer_link',
71
+ 'subfields' :[ {
72
+ 'component' : 'try.link',
73
+ 'field' : 'display_text'
74
+ }]
75
+ }] },
76
+ 'seo_details' : {
77
+ index: true, searchFieldName: 'seo',
78
+ 'subfields' : [
79
+ {
80
+ 'component' : 'try.seo',
81
+ 'field' : 'meta_description'
82
+ }
83
+ ]
84
+ },
85
+ 'changelog' : {
86
+ index: true, searchFieldName: 'breakdown',
87
+ 'subfields' : [
88
+ {
89
+ 'component' : 'try.revision',
90
+ 'field' : 'summary'
91
+ }
92
+ ]
93
+ }
94
+ }
95
+ */
96
+ function extractSubfieldData({ config, data }) {
97
+ let returnData = '';
98
+ if (Array.isArray(data)) {
99
+ const dynDataItems = data;
100
+ for (let r = 0; r < dynDataItems.length; r++) {
101
+ const extractItem = dynDataItems[r];
102
+ for (let s = 0; s < config.length; s++) {
103
+ const conf = config[s];
104
+ if (Object.keys(extractItem).includes('__component')) {
105
+ if (conf.component === extractItem.__component &&
106
+ !Object.keys(conf).includes('subfields') &&
107
+ typeof extractItem[conf['field']] !== "undefined" &&
108
+ extractItem[conf['field']]) {
109
+ let val = extractItem[conf['field']];
110
+ if (Object.keys(conf).includes('transform')
111
+ && conf['transform'] === 'markdown')
112
+ val = transformServiceProvider.transform({ content: val, from: 'markdown' });
113
+ returnData = returnData + '\n' + val;
114
+ }
115
+ else if (conf.component === extractItem.__component &&
116
+ Object.keys(conf).includes('subfields')) {
117
+ returnData = returnData + '\n' + extractSubfieldData({
118
+ config: conf['subfields'], data: extractItem[conf['field']]
119
+ });
120
+ }
121
+ }
122
+ else {
123
+ if (!Object.keys(conf).includes('subfields') &&
124
+ typeof extractItem[conf['field']] !== "undefined" &&
125
+ extractItem[conf['field']]) {
126
+ let val = extractItem[conf['field']];
127
+ if (Object.keys(conf).includes('transform')
128
+ && conf['transform'] === 'markdown')
129
+ val = transformServiceProvider.transform({ content: val, from: 'markdown' });
130
+ returnData = returnData + '\n' + val;
131
+ }
132
+ else if (Object.keys(conf).includes('subfields')) {
133
+ returnData = returnData + '\n' + extractSubfieldData({
134
+ config: conf['subfields'], data: extractItem[conf['field']]
135
+ });
136
+ }
137
+ }
138
+ }
139
+ }
140
+ }
141
+ else //for single component as a field
142
+ {
143
+ for (let s = 0; s < config.length; s++) {
144
+ const conf = config[s];
145
+ if (!Object.keys(conf).includes('subfields') &&
146
+ typeof data[conf['field']] !== "undefined" &&
147
+ data[conf['field']])
148
+ returnData = returnData + '\n' + data[conf['field']];
149
+ else if (Object.keys(conf).includes('subfields')) {
150
+ returnData = returnData + '\n' + extractSubfieldData({
151
+ config: conf['subfields'], data: data[conf['field']]
152
+ });
153
+ }
154
+ }
155
+ }
156
+ return returnData;
157
+ }
158
+ module.exports = ({ strapi }) => ({
159
+ async getElasticsearchInfo() {
160
+ const configureService = strapi.plugins['elasticsearch'].services.configureIndexing;
161
+ const esInterface = strapi.plugins['elasticsearch'].services.esInterface;
162
+ const pluginConfig = await strapi.config.get('plugin.elasticsearch');
163
+ const connected = pluginConfig.searchConnector && pluginConfig.searchConnector.host
164
+ ? await esInterface.checkESConnection() : false;
165
+ return {
166
+ indexingCronSchedule: pluginConfig.indexingCronSchedule || "Not configured",
167
+ elasticHost: pluginConfig.searchConnector ?
168
+ pluginConfig.searchConnector.host || "Not configured" : "Not configured",
169
+ elasticUserName: pluginConfig.searchConnector ?
170
+ pluginConfig.searchConnector.username || "Not configured" : "Not configured",
171
+ elasticCertificate: pluginConfig.searchConnector ?
172
+ pluginConfig.searchConnector.certificate || "Not configured" : "Not configured",
173
+ elasticIndexAlias: pluginConfig.indexAliasName || "Not configured",
174
+ connected: connected,
175
+ initialized: configureService.isInitialized()
176
+ };
177
+ },
178
+ isCollectionDraftPublish({ collectionName }) {
179
+ const model = strapi.getModel(collectionName);
180
+ return model.attributes.publishedAt ? true : false;
181
+ },
182
+ getPopulateAttribute({ collectionName }) {
183
+ //TODO : We currently have set populate to upto 4 levels, should
184
+ //this be configurable or a different default value?
185
+ return getFullPopulateObject(collectionName, 4, []);
186
+ },
187
+ getIndexItemId({ collectionName, itemId }) {
188
+ return collectionName + '::' + itemId;
189
+ },
190
+ async getCurrentIndexName() {
191
+ const pluginStore = getPluginStore();
192
+ const settings = await pluginStore.get({ key: 'configsettings' });
193
+ let indexName = 'strapi-plugin-elasticsearch-index_000001';
194
+ if (settings) {
195
+ const objSettings = JSON.parse(settings);
196
+ if (Object.keys(objSettings).includes('indexConfig')) {
197
+ const idxConfig = objSettings['indexConfig'];
198
+ indexName = idxConfig['name'];
199
+ }
200
+ }
201
+ return indexName;
202
+ },
203
+ async getIncrementedIndexName() {
204
+ const currentIndexName = await this.getCurrentIndexName();
205
+ const number = parseInt(currentIndexName.split('index_')[1]);
206
+ return 'strapi-plugin-elasticsearch-index_' + String(number + 1).padStart(6, '0');
207
+ },
208
+ async storeCurrentIndexName(indexName) {
209
+ const pluginStore = getPluginStore();
210
+ const settings = await pluginStore.get({ key: 'configsettings' });
211
+ if (settings) {
212
+ const objSettings = JSON.parse(settings);
213
+ objSettings['indexConfig'] = { 'name': indexName };
214
+ await pluginStore.set({ key: 'configsettings', value: JSON.stringify(objSettings) });
215
+ }
216
+ else {
217
+ const newSettings = JSON.stringify({ 'indexConfig': { 'name': indexName } });
218
+ await pluginStore.set({ key: 'configsettings', value: newSettings });
219
+ }
220
+ },
221
+ modifySubfieldsConfigForExtractor(collectionConfig) {
222
+ const collectionName = Object.keys(collectionConfig)[0];
223
+ const attributes = Object.keys(collectionConfig[collectionName]);
224
+ for (let r = 0; r < attributes.length; r++) {
225
+ const attr = attributes[r];
226
+ const attribFields = Object.keys(collectionConfig[collectionName][attr]);
227
+ if (attribFields.includes('subfields')) {
228
+ const subfielddata = collectionConfig[collectionName][attr]['subfields'];
229
+ if (subfielddata.length > 0) {
230
+ try {
231
+ const subfieldjson = JSON.parse(subfielddata);
232
+ if (Object.keys(subfieldjson).includes('subfields'))
233
+ collectionConfig[collectionName][attr]['subfields'] = subfieldjson['subfields'];
234
+ }
235
+ catch (err) {
236
+ continue;
237
+ }
238
+ }
239
+ }
240
+ }
241
+ return collectionConfig;
242
+ },
243
+ extractDataToIndex({ collectionName, data, collectionConfig }) {
244
+ collectionConfig = this.modifySubfieldsConfigForExtractor(collectionConfig);
245
+ const fti = Object.keys(collectionConfig[collectionName]);
246
+ const document = {};
247
+ for (let k = 0; k < fti.length; k++) {
248
+ const fieldConfig = collectionConfig[collectionName][fti[k]];
249
+ if (fieldConfig.index) {
250
+ let val = null;
251
+ if (Object.keys(fieldConfig).includes('subfields')) {
252
+ val = extractSubfieldData({ config: fieldConfig['subfields'], data: data[fti[k]] });
253
+ val = val ? val.trim() : val;
254
+ }
255
+ else {
256
+ val = data[fti[k]];
257
+ if (Object.keys(fieldConfig).includes('transform') &&
258
+ fieldConfig['transform'] === 'markdown')
259
+ val = transformServiceProvider.transform({ content: val, from: 'markdown' });
260
+ }
261
+ if (Object.keys(fieldConfig).includes('searchFieldName'))
262
+ document[fieldConfig['searchFieldName']] = val;
263
+ else
264
+ document[fti[k]] = val;
265
+ }
266
+ }
267
+ return document;
268
+ }
269
+ });
@@ -0,0 +1,7 @@
1
+ declare const configureIndexing: any;
2
+ declare const scheduleIndexing: any;
3
+ declare const esInterface: any;
4
+ declare const indexer: any;
5
+ declare const logIndexing: any;
6
+ declare const helper: any;
7
+ declare const transformContent: any;
@@ -1,21 +1,17 @@
1
- 'use strict';
2
-
3
- const configureIndexing = require('./configure-indexing');
4
- const scheduleIndexing = require('./schedule-indexing');
5
- const esInterface = require('./es-interface');
6
- const indexer = require('./perform-indexing');
7
- const logIndexing = require('./log-indexing');
8
- const helper = require('./helper');
9
- const transformContent = require('./transform-content');
10
- const virtualCollectionsRegistry = require('./virtual-collections-registry');
11
-
12
- module.exports = {
13
- configureIndexing,
14
- scheduleIndexing,
15
- esInterface,
16
- indexer,
17
- logIndexing,
18
- helper,
19
- transformContent,
20
- virtualCollectionsRegistry,
21
- };
1
+ 'use strict';
2
+ const configureIndexing = require('./configure-indexing');
3
+ const scheduleIndexing = require('./schedule-indexing');
4
+ const esInterface = require('./es-interface');
5
+ const indexer = require('./perform-indexing');
6
+ const logIndexing = require('./log-indexing');
7
+ const helper = require('./helper');
8
+ const transformContent = require('./transform-content');
9
+ module.exports = {
10
+ configureIndexing,
11
+ scheduleIndexing,
12
+ esInterface,
13
+ indexer,
14
+ logIndexing,
15
+ helper,
16
+ transformContent
17
+ };