@localazy/strapi-plugin 0.1.15 → 0.1.16

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.
@@ -0,0 +1,4 @@
1
+ {
2
+ "latest": "3.6.11",
3
+ "lastUpdateCheck": 1694088415931
4
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@localazy/strapi-plugin",
3
- "version": "0.1.15",
3
+ "version": "0.1.16",
4
4
  "description": "The official Strapi Plugin by Localazy.",
5
5
  "strapi": {
6
6
  "name": "localazy",
@@ -54,7 +54,7 @@
54
54
  "@strapi-community/eslint-config": "^0.4.3",
55
55
  "eslint": "^8.32.0",
56
56
  "eslint-plugin-jest": "^27.2.1",
57
- "jest": "^29.3.1"
57
+ "jest": "^29.6.4"
58
58
  },
59
59
  "maintainers": [
60
60
  {
@@ -310,35 +310,39 @@ module.exports = {
310
310
  let languagesCodes = projectLanguagesWithoutSourceLanguage.map(
311
311
  (language) => language.code
312
312
  );
313
- // process filtered languages only / keep all of empty!
313
+ // process filtered languages only / keep all if empty!
314
314
  languagesCodes = await getFilteredLanguagesCodesForDownload(languagesCodes);
315
315
 
316
316
  /**
317
317
  * Iterate over languages and create the ones that are not present in Strapi
318
318
  */
319
319
  const strapiUnsupportedLanguages = []; // do not iterate over these languages later
320
+ const strapiLocales = await StrapiI18nService.getLocales(ctx);
320
321
  for (const isoLocalazy of languagesCodes) {
321
322
  try {
323
+ const isoStrapi = isoLocalazyToStrapi(isoLocalazy);
324
+ const strapiLocale = strapiLocales.find(
325
+ (locale) => locale.code === isoStrapi
326
+ );
327
+ // skip creating locale if it already exists
328
+ if (strapiLocale) {
329
+ strapi.log.info(`The Localazy locale ${isoLocalazy} already exists.`);
330
+ continue;
331
+ }
332
+
322
333
  const newLocaleCode = await StrapiI18nService.createStrapiLocale(
323
334
  ctx,
324
335
  isoLocalazy
325
336
  );
326
337
  messageReport.push(`Created locale ${newLocaleCode}`);
327
338
  } catch (e) {
328
- if (
329
- e.name === "ApplicationError" &&
330
- e.message === "This locale already exists"
331
- ) {
332
- strapi.log.info(`The Localazy locale ${isoLocalazy} already exists.`);
333
- } else {
334
- strapi.log.error(e.message);
335
- }
339
+ strapi.log.error(e.message);
336
340
  if (e.name === "ValidationError") {
337
341
  // store unsupported language code
338
342
  strapiUnsupportedLanguages.push(isoLocalazy);
339
- messageReport.push(
340
- `Language ${isoLocalazy} is not supported by Strapi`
341
- );
343
+ messageReport.push(`Language ${isoLocalazy} is not supported by Strapi`);
344
+ } else {
345
+ messageReport.push(e.message);
342
346
  }
343
347
  }
344
348
  }
@@ -391,16 +395,7 @@ module.exports = {
391
395
  );
392
396
 
393
397
  if (typeof modelContentTransferSetup !== "undefined" && shouldSetDownloadedProperty(modelContentTransferSetup, parsedKey.rest)) {
394
- const parsedKeyRestWithoutComponents = parsedKey.rest.map((segment) => {
395
- const semicolonIndex = segment.indexOf(";");
396
-
397
- if (semicolonIndex === -1) {
398
- return segment;
399
- }
400
-
401
- return segment.substring(0, semicolonIndex);
402
- });
403
-
398
+ const parsedKeyRestWithoutComponents = parsedKey.rest;
404
399
  const setKey = [
405
400
  isoStrapi,
406
401
  parsedKey.uid,
@@ -482,6 +477,7 @@ module.exports = {
482
477
  } catch (e) {
483
478
  success = false;
484
479
  strapi.log.error(e.message);
480
+ strapi.log.error(JSON.stringify(e.details?.errors || {}));
485
481
  messageReport.push(
486
482
  `Cannot create an entry in ${isoStrapi} for ${uid}[${baseEntry.id}]: ${e.message}`
487
483
  );
@@ -508,6 +504,7 @@ module.exports = {
508
504
  } catch (e) {
509
505
  success = false;
510
506
  strapi.log.error(e.message);
507
+ strapi.log.error(JSON.stringify(e.details?.errors || {}));
511
508
  messageReport.push(
512
509
  `Cannot update an ${uid}[${baseEntryCurrentLanguageLocalizationInfo.id}] (${isoStrapi}): ${e.message}`
513
510
  );
@@ -2,9 +2,8 @@
2
2
 
3
3
  const { isoLocalazyToStrapi } = require("../utils/iso-locales-utils.js");
4
4
  const intlDisplayName = require("../utils/intl-display-name.js");
5
- const merge = require("lodash/merge");
6
- const cloneDeep = require("lodash/cloneDeep");
7
5
  const omitDeep = require("../utils/omit-deep.js");
6
+ const { forEach, find } = require("lodash")
8
7
 
9
8
  module.exports = ({ strapi }) => ({
10
9
  async getLocales(ctx = {}) {
@@ -86,14 +85,12 @@ module.exports = ({ strapi }) => ({
86
85
  const newEntryLocale = newEntry.locale;
87
86
  const filteredNewEntry = omitDeep(newEntry, [
88
87
  "locale",
89
- "id",
90
88
  "createdAt",
91
- // "publishedAt",
92
89
  "updatedAt",
93
90
  ]);
94
91
  filteredNewEntry.locale = newEntryLocale;
95
92
  // * sets as draft (no timestamp)
96
- // ! do not completely omit as it won't process the required fields
93
+ // do not completely omit as it won't process the required fields
97
94
  filteredNewEntry.publishedAt = null;
98
95
 
99
96
  newLocalizationCtx.request.body = filteredNewEntry;
@@ -105,9 +102,8 @@ module.exports = ({ strapi }) => ({
105
102
  baseEntry.id,
106
103
  newEntryLocale
107
104
  );
108
- const mergedEntry = merge(cloneDeep(baseEntry), insertedEntry);
109
105
 
110
- return mergedEntry;
106
+ return insertedEntry
111
107
  } catch (e) {
112
108
  strapi.log.error(e);
113
109
  throw e;
@@ -115,9 +111,28 @@ module.exports = ({ strapi }) => ({
115
111
  },
116
112
  async updateLocalizationForAnExistingEntry(uid, updateEntryId, data) {
117
113
  try {
114
+
118
115
  const StrapiService = strapi.plugin("localazy").service("strapiService");
116
+ const strapiContentTypesModels = await StrapiService.getModels();
119
117
  const populate = await StrapiService.getPopulateObject(uid);
120
118
 
119
+ // Bugfix by <emanuele.c@dacoco.io>:
120
+ // Prevents IDs to be appended when updating a localized entry. When IDs are present
121
+ // Strapi attempts to update a not yet existent ID into the DB
122
+ if (strapiContentTypesModels) {
123
+ const filtered = find(strapiContentTypesModels, (model) => model.uid === uid)
124
+ if (filtered?.attributes) {
125
+ for (let attribute in filtered.attributes) {
126
+ if (filtered.attributes[attribute]?.type === 'dynamiczone') {
127
+ if (!populate[attribute] || populate[attribute] !== 'deep') {
128
+ populate[attribute] = 'deep'
129
+ }
130
+ forEach(data[attribute], (prop) => { if (prop?.id) delete prop.id })
131
+ }
132
+ }
133
+ }
134
+ }
135
+
121
136
  const updatedEntry = await strapi.entityService.update(
122
137
  uid,
123
138
  updateEntryId,
@@ -2,6 +2,8 @@
2
2
 
3
3
  const parsedLocalazyEntryToCreateEntry = require("../utils/parsed-localazy-entry-to-create-entry");
4
4
  const parsedLocalazyEntryToUpdateEntry = require("../utils/parsed-localazy-entry-to-update-entry");
5
+ const omitDeep = require("../utils/omit-deep");
6
+ const { merge } = require("lodash");
5
7
 
6
8
  module.exports = ({ strapi }) => ({
7
9
  async createEntry(
@@ -13,7 +15,8 @@ module.exports = ({ strapi }) => ({
13
15
  isoStrapi,
14
16
  ) {
15
17
  // * The entry will be created and then updated as the structures differ
16
- // * It's one extra database call, but the complexity of recursive code to maintain does worth it
18
+ // * It's one extra database call, but the amount of recursive code's complexity is reduced
19
+
17
20
 
18
21
  // Strapi i18n Service
19
22
  const StrapiI18nService = strapi
@@ -28,12 +31,35 @@ module.exports = ({ strapi }) => ({
28
31
  isoStrapi,
29
32
  );
30
33
 
34
+ const filteredBaseEntry = omitDeep(baseEntry, [
35
+ "locale",
36
+ "localizations",
37
+ "createdAt",
38
+ "createdBy",
39
+ "updatedAt",
40
+ "updatedBy",
41
+ "publishedAt",
42
+ ]);
43
+
44
+ let mergedCreateEntry = {};
45
+ merge(mergedCreateEntry, filteredBaseEntry, createEntry);
46
+ mergedCreateEntry = omitDeep(mergedCreateEntry, [
47
+ "locale",
48
+ "localizations",
49
+ "createdAt",
50
+ "createdBy",
51
+ "updatedAt",
52
+ "updatedBy",
53
+ "publishedAt",
54
+ ]);
55
+
56
+ mergedCreateEntry.locale = isoStrapi;
31
57
  const createdEntry =
32
58
  await StrapiI18nService.createLocalizationForAnExistingEntry(
33
59
  ctx,
34
60
  uid,
35
61
  baseEntry,
36
- createEntry,
62
+ mergedCreateEntry,
37
63
  );
38
64
 
39
65
  await this.updateEntry(
@@ -1,10 +1,9 @@
1
1
  const parsedLocalazyEntry = {
2
- title: "Test: Sčítání",
2
+ title: "Test: Přidání",
3
3
  description: "Otestujte si své dovednosti, které jsme se naučili v předchozí lekci.",
4
- lesson_type: [
5
- null,
6
- {
7
- title: "Vyberte správnou odpověď",
4
+ lesson_type: {
5
+ "1;lesson.quiz": {
6
+ title: "Zvolte správnou odpověď",
8
7
  questions: [
9
8
  null,
10
9
  {
@@ -14,7 +13,7 @@ const parsedLocalazyEntry = {
14
13
  question: "5 + 15 = ",
15
14
  },
16
15
  {
17
- question: "Kolik pohárů je na fotce?",
16
+ question: "Kolik šálků je na fotografii?",
18
17
  },
19
18
  ],
20
19
  answers: [
@@ -30,7 +29,7 @@ const parsedLocalazyEntry = {
30
29
  },
31
30
  ],
32
31
  },
33
- ],
32
+ },
34
33
  };
35
34
 
36
35
  const baseEntry = {
@@ -40,7 +39,7 @@ const baseEntry = {
40
39
  duration: "02:00:00.000",
41
40
  description: "Test your skills we've learnt in the previous lesson.",
42
41
  createdAt: "2022-10-19T09:56:10.979Z",
43
- updatedAt: "2022-10-19T12:13:58.102Z",
42
+ updatedAt: "2023-09-07T10:33:16.442Z",
44
43
  publishedAt: null,
45
44
  locale: "en",
46
45
  lesson_type: [
@@ -52,7 +51,7 @@ const baseEntry = {
52
51
  {
53
52
  id: 1,
54
53
  question: "1 + 1 = ",
55
- is_active: true,
54
+ is_active: null,
56
55
  question_number: 1,
57
56
  assets: null,
58
57
  },
@@ -66,7 +65,7 @@ const baseEntry = {
66
65
  {
67
66
  id: 3,
68
67
  question: "How many cups are on the photo?",
69
- is_active: false,
68
+ is_active: true,
70
69
  question_number: 3,
71
70
  assets: [
72
71
  {
@@ -132,6 +131,7 @@ const baseEntry = {
132
131
  provider_metadata: null,
133
132
  createdAt: "2022-10-19T09:57:52.620Z",
134
133
  updatedAt: "2022-10-19T09:57:52.620Z",
134
+ folderPath: null,
135
135
  },
136
136
  ],
137
137
  },
@@ -141,18 +141,21 @@ const baseEntry = {
141
141
  id: 1,
142
142
  question_number: 1,
143
143
  correct_answer: "2",
144
+ pick_answer: "C",
144
145
  answer_asset: null,
145
146
  },
146
147
  {
147
148
  id: 2,
148
149
  question_number: 2,
149
150
  correct_answer: "20",
151
+ pick_answer: null,
150
152
  answer_asset: null,
151
153
  },
152
154
  {
153
155
  id: 3,
154
156
  question_number: 3,
155
157
  correct_answer: "15",
158
+ pick_answer: "A",
156
159
  answer_asset: null,
157
160
  },
158
161
  ],
@@ -160,39 +163,39 @@ const baseEntry = {
160
163
  ],
161
164
  localizations: [
162
165
  {
163
- id: 4,
164
- title: "Test: Sčítání",
166
+ id: 56,
167
+ title: "Test: Přidání",
165
168
  start_time: "2022-10-01T13:00:00.000Z",
166
169
  duration: "02:00:00.000",
167
170
  description: "Otestujte si své dovednosti, které jsme se naučili v předchozí lekci.",
168
- createdAt: "2022-10-19T12:13:58.101Z",
169
- updatedAt: "2022-10-20T07:58:33.627Z",
171
+ createdAt: "2023-09-07T10:33:16.436Z",
172
+ updatedAt: "2023-09-07T10:53:54.311Z",
170
173
  publishedAt: null,
171
174
  locale: "cs",
172
175
  lesson_type: [
173
176
  {
174
177
  __component: "lesson.quiz",
175
- id: 2,
176
- title: "Vyberte správnou odpověď",
178
+ id: 34,
179
+ title: "Zvolte správnou odpověď",
177
180
  questions: [
178
181
  {
179
- id: 4,
182
+ id: 100,
180
183
  question: "1 + 1 = ",
181
- is_active: true,
184
+ is_active: null,
182
185
  question_number: 1,
183
186
  assets: null,
184
187
  },
185
188
  {
186
- id: 5,
189
+ id: 101,
187
190
  question: "5 + 15 = ",
188
191
  is_active: false,
189
192
  question_number: 2,
190
193
  assets: null,
191
194
  },
192
195
  {
193
- id: 6,
194
- question: "Kolik pohárů je na fotce?",
195
- is_active: false,
196
+ id: 102,
197
+ question: "Kolik šálků je na fotografii?",
198
+ is_active: true,
196
199
  question_number: 3,
197
200
  assets: [
198
201
  {
@@ -258,27 +261,31 @@ const baseEntry = {
258
261
  provider_metadata: null,
259
262
  createdAt: "2022-10-19T09:57:52.620Z",
260
263
  updatedAt: "2022-10-19T09:57:52.620Z",
264
+ folderPath: null,
261
265
  },
262
266
  ],
263
267
  },
264
268
  ],
265
269
  answers: [
266
270
  {
267
- id: 4,
271
+ id: 100,
268
272
  question_number: 1,
269
273
  correct_answer: "2",
274
+ pick_answer: "C",
270
275
  answer_asset: null,
271
276
  },
272
277
  {
273
- id: 5,
278
+ id: 101,
274
279
  question_number: 2,
275
280
  correct_answer: "20",
281
+ pick_answer: null,
276
282
  answer_asset: null,
277
283
  },
278
284
  {
279
- id: 6,
285
+ id: 102,
280
286
  question_number: 3,
281
287
  correct_answer: "15",
288
+ pick_answer: "A",
282
289
  answer_asset: null,
283
290
  },
284
291
  ],
@@ -292,7 +299,7 @@ const baseEntry = {
292
299
  duration: "02:00:00.000",
293
300
  description: "Test your skills we've learnt in the previous lesson.",
294
301
  createdAt: "2022-10-19T09:56:10.979Z",
295
- updatedAt: "2022-10-19T12:13:58.102Z",
302
+ updatedAt: "2023-09-07T10:33:16.442Z",
296
303
  publishedAt: null,
297
304
  locale: "en",
298
305
  lesson_type: [
@@ -304,7 +311,7 @@ const baseEntry = {
304
311
  {
305
312
  id: 1,
306
313
  question: "1 + 1 = ",
307
- is_active: true,
314
+ is_active: null,
308
315
  question_number: 1,
309
316
  },
310
317
  {
@@ -316,7 +323,7 @@ const baseEntry = {
316
323
  {
317
324
  id: 3,
318
325
  question: "How many cups are on the photo?",
319
- is_active: false,
326
+ is_active: true,
320
327
  question_number: 3,
321
328
  },
322
329
  ],
@@ -325,36 +332,39 @@ const baseEntry = {
325
332
  id: 1,
326
333
  question_number: 1,
327
334
  correct_answer: "2",
335
+ pick_answer: "C",
328
336
  },
329
337
  {
330
338
  id: 2,
331
339
  question_number: 2,
332
340
  correct_answer: "20",
341
+ pick_answer: null,
333
342
  },
334
343
  {
335
344
  id: 3,
336
345
  question_number: 3,
337
346
  correct_answer: "15",
347
+ pick_answer: "A",
338
348
  },
339
349
  ],
340
350
  },
341
351
  ],
342
352
  localizations: [
343
353
  {
344
- id: 4,
345
- title: "Test: Sčítání",
354
+ id: 56,
355
+ title: "Test: Přidání",
346
356
  start_time: "2022-10-01T13:00:00.000Z",
347
357
  duration: "02:00:00.000",
348
358
  description: "Otestujte si své dovednosti, které jsme se naučili v předchozí lekci.",
349
- createdAt: "2022-10-19T12:13:58.101Z",
350
- updatedAt: "2022-10-20T07:58:33.627Z",
359
+ createdAt: "2023-09-07T10:33:16.436Z",
360
+ updatedAt: "2023-09-07T10:53:54.311Z",
351
361
  publishedAt: null,
352
362
  locale: "cs",
353
363
  lesson_type: [
354
364
  {
355
365
  __component: "lesson.quiz",
356
- id: 2,
357
- title: "Vyberte správnou odpověď",
366
+ id: 34,
367
+ title: "Zvolte správnou odpověď",
358
368
  },
359
369
  ],
360
370
  createdBy: null,
@@ -367,7 +377,7 @@ const baseEntry = {
367
377
  duration: "02:00:00.000",
368
378
  description: "Test your skills we've learnt in the previous lesson.",
369
379
  createdAt: "2022-10-19T09:56:10.979Z",
370
- updatedAt: "2022-10-19T12:13:58.102Z",
380
+ updatedAt: "2023-09-07T10:33:16.442Z",
371
381
  publishedAt: null,
372
382
  locale: "en",
373
383
  },