@localazy/strapi-plugin 0.2.9 → 0.2.12
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/.eslintrc +0 -1
- package/.github/workflows/qa.yml +1 -1
- package/.github/workflows/release.yml +2 -0
- package/.nvmrc +1 -1
- package/CHANGELOG.md +39 -0
- package/admin/src/modules/@common/models/supported-content-type-fields.js +1 -0
- package/admin/src/modules/@common/utils/get-nav.js +1 -1
- package/admin/src/modules/@common/utils/redirect-to-plugin-route.js +1 -1
- package/admin/src/pages/App/index.js +4 -4
- package/package.json +7 -5
- package/server/functions/should-set-downloaded-property.js +35 -2
- package/server/models/supported-content-type-fields.js +1 -0
- package/server/services/localazy-transfer-download-service.js +70 -9
- package/server/utils/flatten-object.js +6 -2
- package/server/utils/pick-entries.js +6 -1
package/.eslintrc
CHANGED
package/.github/workflows/qa.yml
CHANGED
|
@@ -27,6 +27,7 @@ jobs:
|
|
|
27
27
|
steps:
|
|
28
28
|
- uses: localazy/release/prepare@v2
|
|
29
29
|
with:
|
|
30
|
+
node-version: 20
|
|
30
31
|
app-id: ${{ secrets.AUTH_APP_ID }}
|
|
31
32
|
app-key: ${{ secrets.AUTH_APP_KEY }}
|
|
32
33
|
|
|
@@ -38,6 +39,7 @@ jobs:
|
|
|
38
39
|
steps:
|
|
39
40
|
- uses: localazy/release/publish@v2
|
|
40
41
|
with:
|
|
42
|
+
node-version: 20
|
|
41
43
|
app-id: ${{ secrets.AUTH_APP_ID }}
|
|
42
44
|
app-key: ${{ secrets.AUTH_APP_KEY }}
|
|
43
45
|
npm-publish: public
|
package/.nvmrc
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
20
|
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,42 @@
|
|
|
1
|
+
## 0.2.12 (2024-11-14)
|
|
2
|
+
### 🔀 Pull Requests
|
|
3
|
+
|
|
4
|
+
- [Feat add json fields support #65](https://github.com/localazy/strapi-plugin/pull/65)
|
|
5
|
+
|
|
6
|
+
### ✨ Features
|
|
7
|
+
|
|
8
|
+
- add json fields support ([5ef1f08](https://github.com/localazy/strapi-plugin/commit/5ef1f08)) ([#65](https://github.com/localazy/strapi-plugin/pull/65))
|
|
9
|
+
|
|
10
|
+
### 🐛 Bug Fixes
|
|
11
|
+
|
|
12
|
+
- **JSON:** `null` values upload ([5ef1f08](https://github.com/localazy/strapi-plugin/commit/5ef1f08)) ([#65](https://github.com/localazy/strapi-plugin/pull/65))
|
|
13
|
+
- doubled backslashed in URL ([5ef1f08](https://github.com/localazy/strapi-plugin/commit/5ef1f08)) ([#65](https://github.com/localazy/strapi-plugin/pull/65))
|
|
14
|
+
- string array is split into letters ([5ef1f08](https://github.com/localazy/strapi-plugin/commit/5ef1f08)) ([#65](https://github.com/localazy/strapi-plugin/pull/65))
|
|
15
|
+
|
|
16
|
+
## 0.2.11 (2024-11-14)
|
|
17
|
+
### 🔀 Pull Requests
|
|
18
|
+
|
|
19
|
+
- [Feat add json fields support #65](https://github.com/localazy/strapi-plugin/pull/65)
|
|
20
|
+
|
|
21
|
+
### ✨ Features
|
|
22
|
+
|
|
23
|
+
- add json fields support ([5ef1f08](https://github.com/localazy/strapi-plugin/commit/5ef1f08)) ([#65](https://github.com/localazy/strapi-plugin/pull/65))
|
|
24
|
+
|
|
25
|
+
### 🐛 Bug Fixes
|
|
26
|
+
|
|
27
|
+
- **JSON:** `null` values upload ([5ef1f08](https://github.com/localazy/strapi-plugin/commit/5ef1f08)) ([#65](https://github.com/localazy/strapi-plugin/pull/65))
|
|
28
|
+
- doubled backslashed in URL ([5ef1f08](https://github.com/localazy/strapi-plugin/commit/5ef1f08)) ([#65](https://github.com/localazy/strapi-plugin/pull/65))
|
|
29
|
+
- string array is split into letters ([5ef1f08](https://github.com/localazy/strapi-plugin/commit/5ef1f08)) ([#65](https://github.com/localazy/strapi-plugin/pull/65))
|
|
30
|
+
|
|
31
|
+
## 0.2.10 (2024-09-05)
|
|
32
|
+
|
|
33
|
+
### 🧰 Other Commits
|
|
34
|
+
|
|
35
|
+
- **QA:** switch to Node 20 in GH actions ([8ce744a](https://github.com/localazy/strapi-plugin/commit/8ce744a))
|
|
36
|
+
- **release:** switch to Node 20 in GH actions ([1760ff8](https://github.com/localazy/strapi-plugin/commit/1760ff8))
|
|
37
|
+
- add support for Node 20 ([041c0af](https://github.com/localazy/strapi-plugin/commit/041c0af))
|
|
38
|
+
- support Node 20 ([883c3ef](https://github.com/localazy/strapi-plugin/commit/883c3ef))
|
|
39
|
+
|
|
1
40
|
## 0.2.9 (2024-08-06)
|
|
2
41
|
|
|
3
42
|
## 0.2.8 (2024-08-06)
|
|
@@ -5,7 +5,7 @@ import Upload from "@strapi/icons/Upload";
|
|
|
5
5
|
import pluginId from "../../../pluginId";
|
|
6
6
|
import i18n from "../../../i18n";
|
|
7
7
|
|
|
8
|
-
const BASE_PATH = `${process.env.ADMIN_PATH}
|
|
8
|
+
const BASE_PATH = `${process.env.ADMIN_PATH}plugins/${pluginId}`;
|
|
9
9
|
const t = i18n.t;
|
|
10
10
|
const gevNav = () => {
|
|
11
11
|
return [
|
|
@@ -110,7 +110,7 @@ function App() {
|
|
|
110
110
|
<>
|
|
111
111
|
{!isLoggedIn && (
|
|
112
112
|
<Switch>
|
|
113
|
-
<Route path={`${process.env.ADMIN_PATH}
|
|
113
|
+
<Route path={`${process.env.ADMIN_PATH}plugins/${pluginId}/login`} exact>
|
|
114
114
|
<Login
|
|
115
115
|
title={headerTitle}
|
|
116
116
|
subtitle={headerSubtitle}
|
|
@@ -121,19 +121,19 @@ function App() {
|
|
|
121
121
|
|
|
122
122
|
{isLoggedIn && (
|
|
123
123
|
<Switch>
|
|
124
|
-
<Route path={`${process.env.ADMIN_PATH}
|
|
124
|
+
<Route path={`${process.env.ADMIN_PATH}plugins/${pluginId}/download`} exact>
|
|
125
125
|
<Download
|
|
126
126
|
title={headerTitle}
|
|
127
127
|
subtitle={headerSubtitle}
|
|
128
128
|
/>
|
|
129
129
|
</Route>
|
|
130
|
-
<Route path={`${process.env.ADMIN_PATH}
|
|
130
|
+
<Route path={`${process.env.ADMIN_PATH}plugins/${pluginId}/upload`} exact>
|
|
131
131
|
<Upload
|
|
132
132
|
title={headerTitle}
|
|
133
133
|
subtitle={headerSubtitle}
|
|
134
134
|
/>
|
|
135
135
|
</Route>
|
|
136
|
-
<Route path={`${process.env.ADMIN_PATH}
|
|
136
|
+
<Route path={`${process.env.ADMIN_PATH}plugins/${pluginId}/settings`} exact>
|
|
137
137
|
<Settings
|
|
138
138
|
title={headerTitle}
|
|
139
139
|
subtitle={headerSubtitle}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@localazy/strapi-plugin",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.12",
|
|
4
4
|
"description": "The official Strapi Plugin by Localazy.",
|
|
5
5
|
"strapi": {
|
|
6
6
|
"name": "localazy",
|
|
@@ -24,11 +24,11 @@
|
|
|
24
24
|
"email": "team@localazy.com",
|
|
25
25
|
"url": "https://localazy.com"
|
|
26
26
|
},
|
|
27
|
-
"bin": "./install/index.mjs",
|
|
28
27
|
"repository": {
|
|
29
28
|
"type": "git",
|
|
30
29
|
"url": "git@github.com:localazy/strapi-plugin.git"
|
|
31
30
|
},
|
|
31
|
+
"bin": "./install/index.mjs",
|
|
32
32
|
"scripts": {
|
|
33
33
|
"test": "jest --config ./jest.config.js",
|
|
34
34
|
"test:watch": "jest --watch --config ./jest.config.js"
|
|
@@ -61,12 +61,14 @@
|
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@babel/plugin-transform-modules-commonjs": "^7.20.11",
|
|
63
63
|
"@localazy/conventional-changelog-preset": "^1.2.8",
|
|
64
|
-
"@strapi
|
|
64
|
+
"@strapi/eslint-config": "^0.2.1",
|
|
65
65
|
"conventional-changelog": "^5.1.0",
|
|
66
66
|
"conventional-changelog-cli": "^4.1.0",
|
|
67
67
|
"conventional-changelog-writer": "github:localazy/conventional-changelog-writer",
|
|
68
68
|
"conventional-recommended-bump": "^9.0.0",
|
|
69
|
-
"eslint": "^8.
|
|
69
|
+
"eslint": "^8.57.0",
|
|
70
|
+
"eslint-config-prettier": "^8.10.0",
|
|
71
|
+
"eslint-plugin-import": "^2.30.0",
|
|
70
72
|
"eslint-plugin-jest": "^27.2.1",
|
|
71
73
|
"jest": "^29.6.4"
|
|
72
74
|
},
|
|
@@ -78,7 +80,7 @@
|
|
|
78
80
|
}
|
|
79
81
|
],
|
|
80
82
|
"engines": {
|
|
81
|
-
"node": ">=14.19.1 <=
|
|
83
|
+
"node": ">=14.19.1 <=20.x.x",
|
|
82
84
|
"npm": ">=6.0.0"
|
|
83
85
|
},
|
|
84
86
|
"browser": {
|
|
@@ -26,6 +26,12 @@ const getDynamicZonePropertyName = (parsedKey) => {
|
|
|
26
26
|
return parsedKey[dynamicZoneKeySegmentIndex - 1];
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
+
/**
|
|
30
|
+
*
|
|
31
|
+
* @param {*} modelContentTransferSetup
|
|
32
|
+
* @param {*} parsedKeyRest
|
|
33
|
+
* @returns "yes" | "no" | "json"
|
|
34
|
+
*/
|
|
29
35
|
const shouldSetDownloadedProperty = (
|
|
30
36
|
modelContentTransferSetup,
|
|
31
37
|
parsedKeyRest,
|
|
@@ -50,11 +56,38 @@ const shouldSetDownloadedProperty = (
|
|
|
50
56
|
const slicedParsedKeyRest = parsedKeyRest.slice(dynamicZoneKeySegmentIndex + 1);
|
|
51
57
|
const filteredSlicedParsedKeyRest = slicedParsedKeyRest.filter((segment) => isNaN(parseInt(segment)));
|
|
52
58
|
|
|
53
|
-
|
|
59
|
+
if(get(dzContentTransferSetupComponentModel, filteredSlicedParsedKeyRest) === true) {
|
|
60
|
+
return "yes";
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// json fields
|
|
64
|
+
while(filteredSlicedParsedKeyRest.length > 0) {
|
|
65
|
+
// last segment out
|
|
66
|
+
filteredSlicedParsedKeyRest.pop();
|
|
67
|
+
if(get(dzContentTransferSetupComponentModel, filteredSlicedParsedKeyRest) === true) {
|
|
68
|
+
return "json";
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return "no";
|
|
54
73
|
} else {
|
|
55
74
|
const filteredParsedKeyRest = parsedKeyRest
|
|
56
75
|
.filter((partialKey) => isNaN(parseInt(partialKey)));
|
|
57
|
-
|
|
76
|
+
|
|
77
|
+
if(get(modelContentTransferSetup, filteredParsedKeyRest) === true) {
|
|
78
|
+
return "yes";
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// json fields
|
|
82
|
+
while(filteredParsedKeyRest.length > 0) {
|
|
83
|
+
// last segment out
|
|
84
|
+
filteredParsedKeyRest.pop();
|
|
85
|
+
if(get(modelContentTransferSetup, filteredParsedKeyRest) === true) {
|
|
86
|
+
return "json";
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return "no";
|
|
58
91
|
}
|
|
59
92
|
};
|
|
60
93
|
|
|
@@ -9,6 +9,7 @@ const {
|
|
|
9
9
|
} = require("../utils/iso-locales-utils");
|
|
10
10
|
const shouldSetDownloadedProperty = require("../functions/should-set-downloaded-property");
|
|
11
11
|
const set = require("lodash/set");
|
|
12
|
+
const get = require("lodash/get");
|
|
12
13
|
const isEmpty = require("lodash/isEmpty");
|
|
13
14
|
const RequestInitiatorHelper = require('../utils/request-initiator-helper');
|
|
14
15
|
const PluginSettingsServiceHelper = require('../services/helpers/plugin-settings-service-helper');
|
|
@@ -223,6 +224,7 @@ module.exports = ({ strapi }) => ({
|
|
|
223
224
|
*/
|
|
224
225
|
const parsedLocalazyContent = {};
|
|
225
226
|
const strapiContentTypesModels = await StrapiService.getModels();
|
|
227
|
+
const jsonFields = [];
|
|
226
228
|
for (const [isoLocalazy, keys] of Object.entries(localazyContent)) {
|
|
227
229
|
const isoStrapi = isoLocalazyToStrapi(isoLocalazy);
|
|
228
230
|
if (!isoStrapi) {
|
|
@@ -244,20 +246,79 @@ module.exports = ({ strapi }) => ({
|
|
|
244
246
|
parsedKey.uid
|
|
245
247
|
);
|
|
246
248
|
|
|
247
|
-
if (typeof modelContentTransferSetup !== "undefined"
|
|
248
|
-
const
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
249
|
+
if (typeof modelContentTransferSetup !== "undefined") {
|
|
250
|
+
const shouldSetDownloadedPropertyResult = shouldSetDownloadedProperty(modelContentTransferSetup, parsedKey.rest);
|
|
251
|
+
if (shouldSetDownloadedPropertyResult === "no") {
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
let parsedKeyRestWithoutComponents = parsedKey.rest;
|
|
256
|
+
if (shouldSetDownloadedPropertyResult === "json") {
|
|
257
|
+
const setKey = [
|
|
258
|
+
isoStrapi,
|
|
259
|
+
parsedKey.uid,
|
|
260
|
+
parsedKey.id,
|
|
261
|
+
];
|
|
262
|
+
|
|
263
|
+
// handle dynamic zones and components here
|
|
264
|
+
let updatedParsedKeyRestWithoutComponents = parsedKeyRestWithoutComponents;
|
|
265
|
+
let segmentsToAdd = [];
|
|
266
|
+
for (const segment of parsedKeyRestWithoutComponents) {
|
|
267
|
+
const hasEntry = get(modelContentTransferSetup, [...segmentsToAdd, segment]);
|
|
268
|
+
const hasEntryNotFinal = hasEntry && typeof hasEntry !== "boolean";
|
|
269
|
+
// const isDZ = Array.isArray(hasEntry) && hasEntry.every((entry) => entry.__component__);
|
|
270
|
+
// processed till here in iterations and `segment` is numeric
|
|
271
|
+
const isComponent = parseInt(segment) > 0;
|
|
272
|
+
|
|
273
|
+
if (hasEntryNotFinal || (!hasEntry && isComponent)) {
|
|
274
|
+
segmentsToAdd.push(segment);
|
|
275
|
+
setKey.push(segment);
|
|
276
|
+
updatedParsedKeyRestWithoutComponents = updatedParsedKeyRestWithoutComponents.slice(1);
|
|
277
|
+
} else {
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
parsedKeyRestWithoutComponents = updatedParsedKeyRestWithoutComponents;
|
|
282
|
+
|
|
283
|
+
let foundJsonFieldIndex = jsonFields.findIndex((jsonField) => {
|
|
284
|
+
return jsonField.setKey.join() === setKey.join();
|
|
285
|
+
});
|
|
286
|
+
if (foundJsonFieldIndex === -1) {
|
|
287
|
+
jsonFields.push({
|
|
288
|
+
setKey,
|
|
289
|
+
jsonKey: parsedKeyRestWithoutComponents[0],
|
|
290
|
+
jsonValue: {},
|
|
291
|
+
});
|
|
292
|
+
}
|
|
255
293
|
|
|
256
|
-
|
|
294
|
+
foundJsonFieldIndex = foundJsonFieldIndex === -1 ? jsonFields.length - 1 : foundJsonFieldIndex;
|
|
295
|
+
const foundJsonField = jsonFields[foundJsonFieldIndex];
|
|
296
|
+
// rest from index 1
|
|
297
|
+
const restSliced = parsedKeyRestWithoutComponents.slice(1);
|
|
298
|
+
set(foundJsonField, ['jsonValue', ...restSliced], value);
|
|
299
|
+
jsonFields[foundJsonFieldIndex] = foundJsonField;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
if (shouldSetDownloadedPropertyResult === "yes") {
|
|
303
|
+
const setKey = [
|
|
304
|
+
isoStrapi,
|
|
305
|
+
parsedKey.uid,
|
|
306
|
+
parsedKey.id,
|
|
307
|
+
...parsedKeyRestWithoutComponents,
|
|
308
|
+
];
|
|
309
|
+
set(parsedLocalazyContent, setKey, value);
|
|
310
|
+
}
|
|
257
311
|
}
|
|
258
312
|
}
|
|
259
313
|
}
|
|
260
314
|
|
|
315
|
+
/**
|
|
316
|
+
* Set json fields if applicable
|
|
317
|
+
*/
|
|
318
|
+
for (const jsonField of jsonFields) {
|
|
319
|
+
set(parsedLocalazyContent, [...jsonField.setKey, jsonField.jsonKey], jsonField.jsonValue);
|
|
320
|
+
}
|
|
321
|
+
|
|
261
322
|
/**
|
|
262
323
|
* Iterate over parsed Localazy content and insert/update content in Strapi
|
|
263
324
|
*/
|
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
const flattenObject = (object, prefix = "") => {
|
|
4
4
|
const result = {};
|
|
5
5
|
|
|
6
|
+
if (typeof object === "string" || typeof object === "number" || typeof object === "boolean") {
|
|
7
|
+
return object;
|
|
8
|
+
}
|
|
9
|
+
|
|
6
10
|
for (const objectKey in object) {
|
|
7
11
|
if (objectKey === "id") {
|
|
8
12
|
continue;
|
|
@@ -22,9 +26,9 @@ const flattenObject = (object, prefix = "") => {
|
|
|
22
26
|
const flattenedArray = object[objectKey].reduce(
|
|
23
27
|
(accumulator, item, index) => {
|
|
24
28
|
// No id should use the index of the array item
|
|
25
|
-
let key = `${objectKey}[${item
|
|
29
|
+
let key = `${objectKey}[${item?.id || index}]`;
|
|
26
30
|
// is Dynamic Zone
|
|
27
|
-
if (item
|
|
31
|
+
if (item?.id && item?.__component) {
|
|
28
32
|
key = `${objectKey}[${item.id};${item.__component}]`;
|
|
29
33
|
}
|
|
30
34
|
|
|
@@ -22,7 +22,12 @@ const pickEntries = (flatten, pickPaths) => {
|
|
|
22
22
|
if (isDynamicZoneKey(key)) {
|
|
23
23
|
filteredKey = filteredKey.replace(/\[\d+;[\w-]+\./g, `[`);
|
|
24
24
|
}
|
|
25
|
-
if (mappedPickPaths.includes(filteredKey)) {
|
|
25
|
+
// if (mappedPickPaths.includes(filteredKey)) {
|
|
26
|
+
if (
|
|
27
|
+
mappedPickPaths.includes(filteredKey) ||
|
|
28
|
+
// include JSON fields
|
|
29
|
+
mappedPickPaths.some((pickPath) => filteredKey.startsWith(`${pickPath}.`))
|
|
30
|
+
) {
|
|
26
31
|
pickedEntries[key] = flatten[key];
|
|
27
32
|
}
|
|
28
33
|
});
|