@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,142 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports = async ({ strapi }) => {
4
- const pluginConfig = await strapi.config.get('plugin.elasticsearch');
5
- const configureIndexingService = strapi.plugins['elasticsearch'].services.configureIndexing;
6
- const scheduleIndexingService = strapi.plugins['elasticsearch'].services.scheduleIndexing;
7
- const esInterface = strapi.plugins['elasticsearch'].services.esInterface;
8
- const indexer = strapi.plugins['elasticsearch'].services.indexer;
9
- const helper = strapi.plugins['elasticsearch'].services.helper;
10
- try
11
- {
12
- await configureIndexingService.initializeStrapiElasticsearch();
13
-
14
- if (!Object.keys(pluginConfig).includes('indexingCronSchedule'))
15
- console.warn("The plugin strapi-plugin-elasticsearch is enabled but the indexingCronSchedule is not configured.");
16
- else if (!Object.keys(pluginConfig).includes('searchConnector'))
17
- console.warn("The plugin strapi-plugin-elasticsearch is enabled but the searchConnector is not configured.");
18
- else
19
- {
20
- const connector = pluginConfig['searchConnector'];
21
- await esInterface.initializeSearchEngine({host : connector.host, uname: connector.username,
22
- password: connector.password, cert: connector.certificate});
23
- strapi.cron.add({
24
- elasticsearchIndexing: {
25
- task: async ({ strapi }) => {
26
- await indexer.indexPendingData();
27
- },
28
- options: {
29
- rule: pluginConfig['indexingCronSchedule'],
30
- },
31
- },
32
- });
33
-
34
- if (await esInterface.checkESConnection())
35
- {
36
- //Attach the alias to the current index:
37
- const idxName = await helper.getCurrentIndexName();
38
- await esInterface.attachAliasToIndex(idxName);
39
- }
40
-
41
- }
42
-
43
- strapi.db.lifecycles.subscribe(async (event) => {
44
- if (event.action === 'afterCreate' || event.action === 'afterUpdate') {
45
- if (strapi.elasticsearch.collections.includes(event.model.uid))
46
- {
47
- //collection without draft-publish
48
- if (typeof event.model.attributes.publishedAt === "undefined")
49
- {
50
- await scheduleIndexingService.addItemToIndex({
51
- collectionUid: event.model.uid,
52
- recordId: event.result.id
53
- });
54
- }
55
- else if (event.model.attributes.publishedAt)
56
- {
57
- if (event.result.publishedAt)
58
- {
59
- await scheduleIndexingService.addItemToIndex({
60
- collectionUid: event.model.uid,
61
- recordId: event.result.id
62
- });
63
- }
64
- else
65
- {
66
- //unpublish
67
- await scheduleIndexingService.removeItemFromIndex({
68
- collectionUid: event.model.uid,
69
- recordId: event.result.id
70
- });
71
- }
72
- }
73
- }
74
- }
75
- //bulk publish-unpublish from list view
76
- if (event.action === 'afterCreateMany' || event.action === 'afterUpdateMany') {
77
- if (strapi.elasticsearch.collections.includes(event.model.uid))
78
- {
79
- if (Object.keys(event.params.where.id).includes('$in'))
80
- {
81
- const updatedItemIds = event.params.where.id['$in']
82
- //bulk unpublish
83
- if (typeof event.params.data.publishedAt === "undefined" ||
84
- event.params.data.publishedAt === null)
85
- {
86
- for (let k = 0; k< updatedItemIds.length; k++)
87
- {
88
- await scheduleIndexingService.removeItemFromIndex({
89
- collectionUid: event.model.uid,
90
- recordId: updatedItemIds[k]
91
- });
92
- }
93
- }
94
- else
95
- {
96
- for (let k = 0; k< updatedItemIds.length; k++)
97
- {
98
- await scheduleIndexingService.addItemToIndex({
99
- collectionUid: event.model.uid,
100
- recordId: updatedItemIds[k]
101
- });
102
- }
103
- }
104
- }
105
- }
106
- }
107
- if (event.action === 'afterDelete') {
108
- if (strapi.elasticsearch.collections.includes(event.model.uid))
109
- {
110
- await scheduleIndexingService.removeItemFromIndex({
111
- collectionUid: event.model.uid,
112
- recordId: event.result.id
113
- });
114
- }
115
- }
116
- if (event.action === 'afterDeleteMany') {
117
- if (strapi.elasticsearch.collections.includes(event.model.uid))
118
- {
119
- if (Object.keys(event.params.where).includes('$and') &&
120
- Array.isArray(event.params.where['$and']) &&
121
- Object.keys(event.params.where['$and'][0]).includes('id') &&
122
- Object.keys(event.params.where['$and'][0]['id']).includes('$in'))
123
- {
124
- const deletedItemIds = event.params.where['$and'][0]['id']['$in']
125
- for (let k = 0; k< deletedItemIds.length; k++)
126
- {
127
- await scheduleIndexingService.removeItemFromIndex({
128
- collectionUid: event.model.uid,
129
- recordId: deletedItemIds[k]
130
- });
131
- }
132
- }
133
- }
134
- }
135
- });
136
- configureIndexingService.markInitialized();
137
- }
138
- catch(err) {
139
- console.error('An error was encountered while initializing the strapi-plugin-elasticsearch plugin.')
140
- console.error(err);
141
- }
142
- };
@@ -1,6 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports = {
4
- default: {},
5
- validator() {},
6
- };
@@ -1,35 +0,0 @@
1
- module.exports = {
2
- "kind": "collectionType",
3
- "collectionName": "indexing-log",
4
- "info": {
5
- "singularName": "indexing-log",
6
- "pluralName": "indexing-logs",
7
- "displayName": "Indexing Logs",
8
- "description": "Logged runs of the indexing cron job"
9
- },
10
- "options": {
11
- "draftAndPublish": false
12
- },
13
- "pluginOptions": {
14
- 'content-manager': {
15
- visible: false,
16
- },
17
- 'content-type-builder': {
18
- visible: false,
19
- }
20
- },
21
- "attributes": {
22
- "status": {
23
- "type": "enumeration",
24
- "enum": [
25
- "pass",
26
- "fail"
27
- ],
28
- "required": true
29
- },
30
- "details": {
31
- "type": "text"
32
- }
33
- }
34
- }
35
-
@@ -1,52 +0,0 @@
1
- module.exports = {
2
- "kind": "collectionType",
3
- "collectionName": "task",
4
- "info": {
5
- "singularName": "task",
6
- "pluralName": "tasks",
7
- "displayName": "Task",
8
- "description": "Search indexing tasks"
9
- },
10
- "options": {
11
- "draftAndPublish": false
12
- },
13
- "pluginOptions": {
14
- 'content-manager': {
15
- visible: false,
16
- },
17
- 'content-type-builder': {
18
- visible: false,
19
- }
20
- },
21
- "attributes": {
22
- "collection_name": {
23
- "type": "string",
24
- "required": true
25
- },
26
- "item_id": {
27
- "type": "integer"
28
- },
29
- "indexing_status": {
30
- "type": "enumeration",
31
- "enum": [
32
- "to-be-done",
33
- "done"
34
- ],
35
- "required": true,
36
- "default": "to-be-done"
37
- },
38
- "full_site_indexing": {
39
- "type": "boolean"
40
- },
41
- "indexing_type": {
42
- "type": "enumeration",
43
- "enum": [
44
- "add-to-index",
45
- "remove-from-index"
46
- ],
47
- "default": "add-to-index",
48
- "required": true
49
- }
50
- }
51
- }
52
-
@@ -1,66 +0,0 @@
1
- 'use strict';
2
-
3
-
4
-
5
- module.exports = ({ strapi }) => {
6
- const configureIndexingService = strapi.plugins['elasticsearch'].services.configureIndexing;
7
-
8
- const getContentConfig = async (ctx) => {
9
- return configureIndexingService.getContentConfig();
10
- };
11
-
12
- const saveCollectionConfig = async (ctx) => {
13
- const { body } = ctx.request;
14
- try {
15
- const updatedConfig = await configureIndexingService.setContentConfig({collection: ctx.params.collectionname, config : body.data});
16
- return updatedConfig;
17
- } catch (err) {
18
- ctx.throw(500, err);
19
- }
20
- };
21
-
22
- const importContentConfig = async (ctx) => {
23
- const { body } = ctx.request;
24
- try {
25
- if (body['data'])
26
- {
27
- const updatedConfig = await configureIndexingService.importContentConfig({config : body['data']});
28
- return updatedConfig;
29
- }
30
- else
31
- ctx.throw(400, 'Invalid parameters')
32
- } catch (err) {
33
- ctx.throw(500, err);
34
- }
35
- }
36
-
37
- const exportContentConfig = async (ctx) => {
38
- return configureIndexingService.getContentConfig();
39
- }
40
-
41
- const setContentConfig = async (ctx) => {
42
- const { body } = ctx.request;
43
- try {
44
- const updatedConfig = await configureIndexingService.setContentConfig({config : body});
45
- return updatedConfig;
46
- } catch (err) {
47
- ctx.throw(500, err);
48
- }
49
- }
50
-
51
- const getCollectionConfig = async (ctx) => {
52
- if (ctx.params.collectionname)
53
- return configureIndexingService.getCollectionConfig({collectionName: ctx.params.collectionname})
54
- else
55
- return null;
56
- }
57
-
58
- return {
59
- getContentConfig,
60
- setContentConfig,
61
- getCollectionConfig,
62
- saveCollectionConfig,
63
- exportContentConfig,
64
- importContentConfig
65
- };
66
- };
@@ -1,31 +0,0 @@
1
- 'use strict';
2
-
3
- const qs = require('qs');
4
-
5
- module.exports = {
6
- search : async (ctx) => {
7
- try {
8
- const esInterface = strapi.plugins['elasticsearch'].services.esInterface;
9
- if (ctx.query.query)
10
- {
11
- const query = qs.parse(ctx.query.query);
12
- const resp = await esInterface.searchData(query);
13
- if (resp?.hits?.hits)
14
- {
15
- const filteredData = resp.hits.hits.filter(dt => dt._source !== null);
16
- const filteredMatches = filteredData.map((dt) => dt['_source']);
17
- ctx.body = filteredMatches;
18
- }
19
- else
20
- ctx.body = {}
21
- }
22
- else
23
- ctx.body = {}
24
- } catch (err) {
25
- ctx.response.status = 500;
26
- ctx.body = "An error was encountered while processing the search request."
27
- console.log('An error was encountered while processing the search request.')
28
- console.log(err);
29
- }
30
- }
31
- };
@@ -1,42 +0,0 @@
1
- module.exports = {
2
- // accessible only from admin UI
3
- type: 'admin',
4
- routes: [
5
- {
6
- method: 'GET',
7
- path: '/content-config',
8
- handler: 'configureIndexing.getContentConfig',
9
- config: { policies: [] },
10
- },
11
- {
12
- method: 'GET',
13
- path: '/collection-config/:collectionname',
14
- handler: 'configureIndexing.getCollectionConfig',
15
- config: { policies: [] },
16
- },
17
- {
18
- method: 'POST',
19
- path: '/collection-config/:collectionname',
20
- handler: 'configureIndexing.saveCollectionConfig',
21
- config: { policies: [] },
22
- },
23
- {
24
- method: 'POST',
25
- path: '/content-config',
26
- handler: 'configureIndexing.setContentConfig',
27
- config: { policies: [] },
28
- },
29
- {
30
- method: 'GET',
31
- path: '/export-content-config',
32
- handler: 'configureIndexing.exportContentConfig',
33
- config: { policies: [] },
34
- },
35
- {
36
- method: 'POST',
37
- path: '/import-content-config',
38
- handler: 'configureIndexing.importContentConfig',
39
- config: { policies: [] },
40
- },
41
- ],
42
- };
@@ -1,24 +0,0 @@
1
- module.exports = {
2
- // accessible only from admin UI
3
- type: 'admin',
4
- routes: [
5
- {
6
- method: 'GET',
7
- path: '/reindex',
8
- handler: 'performIndexing.rebuildIndex',
9
- config: { policies: [] },
10
- },
11
- {
12
- method: 'GET',
13
- path: '/collection-reindex/:collectionname',
14
- handler: 'performIndexing.indexCollection',
15
- config: { policies: [] },
16
- },
17
- {
18
- method: 'GET',
19
- path: '/trigger-indexing/',
20
- handler: 'performIndexing.triggerIndexingTask',
21
- config: { policies: [] },
22
- },
23
- ],
24
- };
@@ -1,14 +0,0 @@
1
- module.exports = {
2
- // accessible only from admin UI
3
- type: 'content-api',
4
- routes: [
5
- {
6
- method: 'GET',
7
- path: '/search',
8
- handler: 'performSearch.search',
9
- config: {
10
- policies: []
11
- },
12
- }
13
- ],
14
- };
@@ -1,12 +0,0 @@
1
- module.exports = {
2
- // accessible only from admin UI
3
- type: 'admin',
4
- routes: [
5
- {
6
- method: 'GET',
7
- path: '/indexing-run-log',
8
- handler: 'logIndexing.fetchRecentRunsLog',
9
- config: { policies: [] },
10
- }
11
- ],
12
- };
@@ -1,12 +0,0 @@
1
- module.exports = {
2
- // accessible only from admin UI
3
- type: 'admin',
4
- routes: [
5
- {
6
- method: 'GET',
7
- path: '/setup-info',
8
- handler: 'setupInfo.getElasticsearchInfo',
9
- config: { policies: [] },
10
- }
11
- ],
12
- };
@@ -1,184 +0,0 @@
1
- 'use strict';
2
-
3
- const getPluginStore = () => {
4
- return strapi.store({
5
- environment: '',
6
- type: 'plugin',
7
- name: 'elasticsearch',
8
- });
9
- }
10
-
11
- module.exports = ({ strapi }) => ({
12
- async initializeStrapiElasticsearch() {
13
- await this.cacheConfig();
14
- },
15
- async markInitialized() {
16
- if (!strapi.elasticsearch)
17
- strapi.elasticsearch = {}
18
- strapi.elasticsearch.initialized = true;
19
- },
20
- isInitialized() {
21
- return strapi.elasticsearch?.initialized || false
22
- },
23
- async cacheConfig() {
24
- if (!strapi.elasticsearch)
25
- strapi.elasticsearch = {}
26
- strapi.elasticsearch.collectionsconfig = await this.getCollectionsConfiguredForIndexing();
27
- strapi.elasticsearch.collections = await this.getCollectionsConfiguredForIndexing();
28
- },
29
- async getCollectionConfig({collectionName}) {
30
- const contentConfig = await this.getContentConfig();
31
- if (Object.keys(contentConfig).includes(collectionName))
32
- {
33
- const ob = {}
34
- ob[collectionName] = contentConfig[collectionName];
35
- return ob;
36
- }
37
- else
38
- return null;
39
- },
40
- async getCollectionsConfiguredForIndexing() {
41
- const contentConfig = await this.getContentConfig();
42
- if (contentConfig)
43
- return Object.keys(contentConfig).filter((i) => {
44
- let hasAtleastOneIndexableAttribute = false;
45
- const attribs = Object.keys(contentConfig[i])
46
- for (let k=0; k<attribs.length; k++)
47
- {
48
- if (contentConfig[i][attribs[k]]['index'] === true)
49
- {
50
- hasAtleastOneIndexableAttribute = true;
51
- break;
52
- }
53
- }
54
- return hasAtleastOneIndexableAttribute;
55
- })
56
- else
57
- return [];
58
- },
59
- async isCollectionConfiguredToBeIndexed({collectionName}) {
60
- const collectionsToIndex = await this.getCollectionsConfiguredForIndexing();
61
- return collectionsToIndex.includes(collectionName);
62
- },
63
- async getContentConfig() {
64
- const fieldsToExclude = ['createdAt', 'createdBy', 'publishedAt', 'publishedBy', 'updatedAt', 'updatedBy']
65
- const pluginStore = getPluginStore();
66
- const settings = await pluginStore.get({ key: 'configsettings' });
67
- const contentTypes = strapi.contentTypes;
68
- const apiContentTypes = Object.keys(contentTypes).filter((c) => c.includes('api::'));
69
- const apiContentConfig = {};
70
- for (let r = 0; r < apiContentTypes.length; r++)
71
- {
72
- apiContentConfig[apiContentTypes[r]] = {};
73
- const collectionAttributes = contentTypes[apiContentTypes[r]].attributes
74
- const listOfAttributes = Object.keys(collectionAttributes).filter(
75
- (i) => fieldsToExclude.includes(i) === false
76
- );
77
-
78
- for (let k = 0; k < listOfAttributes.length; k++)
79
- {
80
- const currentAttribute = listOfAttributes[k];
81
- let attributeType = "regular";
82
- if (typeof collectionAttributes[currentAttribute]["type"] !== "undefined"
83
- && collectionAttributes[currentAttribute]["type"] !== null)
84
- {
85
- if (collectionAttributes[currentAttribute]["type"] === "component")
86
- attributeType = "component"
87
- else if (collectionAttributes[currentAttribute]["type"] === "dynamiczone")
88
- attributeType = "dynamiczone"
89
- }
90
- apiContentConfig[apiContentTypes[r]][listOfAttributes[k]] = {index: false,
91
- type: attributeType}
92
- }
93
-
94
- }
95
- if (settings)
96
- {
97
- const objSettings = JSON.parse(settings);
98
- if (Object.keys(objSettings).includes('contentConfig'))
99
- {
100
- const collections = Object.keys(apiContentConfig);
101
- for (let r=0; r< collections.length; r++)
102
- {
103
- if (Object.keys(objSettings['contentConfig']).includes(collections[r]))
104
- {
105
- const attribsForCollection = Object.keys(apiContentConfig[collections[r]])
106
- for (let s = 0; s < attribsForCollection.length; s++)
107
- {
108
- if (!Object.keys(objSettings['contentConfig'][collections[r]]).includes(attribsForCollection[s]))
109
- {
110
- objSettings['contentConfig'][collections[r]][attribsForCollection[s]] = {index: false,
111
- type: apiContentConfig[collections[r]][attribsForCollection[s]].type}
112
- }
113
- else
114
- {
115
- if (!Object.keys(objSettings['contentConfig'][collections[r]][attribsForCollection[s]]).includes('type'))
116
- objSettings['contentConfig'][collections[r]][attribsForCollection[s]]['type'] = apiContentConfig[collections[r]][attribsForCollection[s]].type
117
- }
118
- }
119
- }
120
- else
121
- objSettings['contentConfig'][collections[r]] = apiContentConfig[collections[r]]
122
- }
123
- return objSettings['contentConfig'];
124
- }
125
- else
126
- return apiContentConfig
127
- }
128
- else
129
- return apiContentConfig;
130
- },
131
- async importContentConfig({config}){
132
- const pluginStore = getPluginStore();
133
- const settings = await pluginStore.get({ key: 'configsettings' });
134
- if (settings)
135
- {
136
- const objSettings = JSON.parse(settings);
137
- objSettings['contentConfig'] = JSON.parse(config)
138
- const stringifySettings = JSON.stringify(objSettings);
139
- await pluginStore.set({ key: 'configsettings', value : stringifySettings });
140
- }
141
- else
142
- {
143
- const newSettings = JSON.stringify({'contentConfig' : config})
144
- await pluginStore.set({ key: 'configsettings', value : newSettings});
145
- }
146
- const updatedSettings = await pluginStore.get({ key: 'configsettings' });
147
- await this.cacheConfig();
148
- if (updatedSettings && Object.keys(updatedSettings).includes('contentConfig'))
149
- return updatedSettings['contentConfig']
150
- else
151
- return {};
152
- },
153
- async setContentConfig({collection, config}){
154
- const pluginStore = getPluginStore();
155
- const settings = await pluginStore.get({ key: 'configsettings' });
156
- if (settings)
157
- {
158
- const objSettings = JSON.parse(settings);
159
- if (Object.keys(objSettings).includes('contentConfig'))
160
- {
161
- const prevConfig = objSettings['contentConfig'];
162
- const changedConfigKey = Object.keys(config)[0];
163
- const newConfig = prevConfig;
164
- newConfig[changedConfigKey] = config[changedConfigKey]
165
- objSettings['contentConfig'] = newConfig
166
- }
167
- else
168
- objSettings['contentConfig'] = config;
169
- const stringifySettings = JSON.stringify(objSettings);
170
- await pluginStore.set({ key: 'configsettings', value : stringifySettings });
171
- }
172
- else
173
- {
174
- const newSettings = JSON.stringify({'contentConfig' : config})
175
- await pluginStore.set({ key: 'configsettings', value : newSettings});
176
- }
177
- const updatedSettings = await pluginStore.get({ key: 'configsettings' });
178
- await this.cacheConfig();
179
- if (updatedSettings && Object.keys(updatedSettings).includes('contentConfig'))
180
- return updatedSettings['contentConfig']
181
- else
182
- return {};
183
- },
184
- });