@localazy/strapi-plugin 0.1.13-rc.4 → 0.1.13-rc.6

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.
@@ -200,16 +200,14 @@ function GlobalSettings() {
200
200
  <Option value="updated">{t("plugin_settings.editing_data_entry")}</Option>
201
201
  </Select>
202
202
  {/* Deprecate source keys on deletion */}
203
- <div style={{ display: "none" }}>
204
- <br /><br />
205
- <ToggleInput
206
- label={t("plugin_settings.deprecate_source_keys_on_delete")}
207
- hint={t("plugin_settings.deprecate_source_keys_on_delete_info")}
208
- offLabel={t("plugin_settings.off")}
209
- onLabel={t("plugin_settings.on")}
210
- checked={typeof formModel?.upload?.allowDeprecate === "boolean" ? formModel.upload.allowDeprecate : false}
211
- onChange={e => patchFormModel("upload.allowDeprecate", e.target.checked)} />
212
- </div>
203
+ <br /><br />
204
+ <ToggleInput
205
+ label={t("plugin_settings.deprecate_source_keys_on_delete")}
206
+ hint={t("plugin_settings.deprecate_source_keys_on_delete_info")}
207
+ offLabel={t("plugin_settings.off")}
208
+ onLabel={t("plugin_settings.on")}
209
+ checked={typeof formModel?.upload?.allowDeprecate === "boolean" ? formModel.upload.allowDeprecate : false}
210
+ onChange={e => patchFormModel("upload.allowDeprecate", e.target.checked)} />
213
211
  <br /><br />
214
212
  <Divider />
215
213
  {/* Download Settings */}
@@ -1,66 +1,26 @@
1
1
  import set from "lodash-es/set";
2
2
  import get from "lodash-es/get";
3
- import uniq from "lodash-es/uniq";
4
- import deepKeys from "@david-vaclavek/deep-keys";
5
- import sortByModelName from "../../@common/utils/sort-by-model-name";
6
- import arrayOfModelsToObject from "../utils/array-of-models-to-object";
7
3
  import findModelValueByKey from "../utils/find-model-value-by-key";
4
+ import getContentTransferSetupKeysSets from "./get-content-transfer-setup-keys-sets";
8
5
 
9
6
  export default (
10
7
  localizableTree = [],
11
8
  storedSetupSchema = [],
12
9
  allModelsTree = []
13
10
  ) => {
14
- localizableTree = arrayOfModelsToObject(
15
- localizableTree.sort(sortByModelName)
16
- );
17
- storedSetupSchema = arrayOfModelsToObject(
18
- storedSetupSchema.sort(sortByModelName)
19
- );
20
-
21
- const unsortedCurrentModelsSchemaKeys = deepKeys(localizableTree);
22
- const unsortedStoredSetupSchemaKeys = deepKeys(storedSetupSchema);
23
- const unsortedAllModelsSchemaKeys = deepKeys(allModelsTree);
24
-
25
- // components order may have changed; this would prevent properties from mixing up
26
- const regex = /\.\d+\.__component__/;
27
- let currentModelsSchemaComponentKeys = unsortedCurrentModelsSchemaKeys.filter((key) => key.match(regex)).map((key) => key.replace(regex, ''));
28
- let storedSetupSchemaComponentKeys = unsortedStoredSetupSchemaKeys.filter((key) => key.match(regex)).map((key) => key.replace(regex, ''));
29
- let allModelsSchemaComponentKeys = unsortedAllModelsSchemaKeys.filter((key) => key.match(regex)).map((key) => key.replace(regex, ''));
30
- currentModelsSchemaComponentKeys = uniq(currentModelsSchemaComponentKeys);
31
- storedSetupSchemaComponentKeys = uniq(storedSetupSchemaComponentKeys);
32
- allModelsSchemaComponentKeys = uniq(allModelsSchemaComponentKeys);
33
-
34
- currentModelsSchemaComponentKeys.forEach((key) => {
35
- get(localizableTree, key).sort((a, b) => a.__component__ > b.__component__ ? 1 : -1);
36
- });
37
-
38
- storedSetupSchemaComponentKeys.forEach((key) => {
39
- get(storedSetupSchema, key).sort((a, b) => a.__component__ > b.__component__ ? 1 : -1);
40
- });
41
-
42
- allModelsSchemaComponentKeys.forEach((key) => {
43
- get(allModelsTree, key).sort((a, b) => a.__component__ > b.__component__ ? 1 : -1);
44
- });
45
-
46
- const currentModelsSchemaKeys = deepKeys(localizableTree);
47
- const storedSetupSchemaKeys = deepKeys(storedSetupSchema);
48
-
49
- const removedKeys = storedSetupSchemaKeys.filter(
50
- (x) => !currentModelsSchemaKeys.includes(x)
51
- );
52
-
53
- const newKeys = currentModelsSchemaKeys.filter(
54
- (key) => !storedSetupSchemaKeys.includes(key)
55
- );
56
-
57
- const filteredStoredSetupSchemaKeys = storedSetupSchemaKeys.filter(
58
- (key) => !removedKeys.includes(key)
11
+ const {
12
+ oLocalizableTree,
13
+ oStoredSetupSchema,
14
+ newKeys,
15
+ filteredStoredSetupSchemaKeys
16
+ } = getContentTransferSetupKeysSets(
17
+ localizableTree,
18
+ storedSetupSchema,
59
19
  );
60
20
 
61
21
  const destinationObject = {};
62
22
  filteredStoredSetupSchemaKeys.forEach((key) => {
63
- const localizableTreeValueToSet = get(storedSetupSchema, key);
23
+ const localizableTreeValueToSet = get(oStoredSetupSchema, key);
64
24
  const allModelsTreeValueToSet = findModelValueByKey(allModelsTree, key);
65
25
 
66
26
  if (allModelsTreeValueToSet === null) {
@@ -74,7 +34,7 @@ export default (
74
34
  }
75
35
  });
76
36
  newKeys.forEach((key) => {
77
- set(destinationObject, key, get(localizableTree, key));
37
+ set(destinationObject, key, get(oLocalizableTree, key));
78
38
  });
79
39
 
80
40
  const destinationArray = [];
@@ -0,0 +1,85 @@
1
+ import get from "lodash-es/get";
2
+ import uniq from "lodash-es/uniq";
3
+ import deepKeys from "@david-vaclavek/deep-keys";
4
+ import sortByModelName from "../../@common/utils/sort-by-model-name";
5
+ import arrayOfModelsToObject from "../utils/array-of-models-to-object";
6
+
7
+ export default (
8
+ localizableTree = [],
9
+ storedSetupSchema = [],
10
+ ) => {
11
+ localizableTree = arrayOfModelsToObject(
12
+ localizableTree.sort(sortByModelName)
13
+ );
14
+ storedSetupSchema = arrayOfModelsToObject(
15
+ storedSetupSchema.sort(sortByModelName)
16
+ );
17
+
18
+ const currentModelsSchemaKeys = deepKeys(localizableTree);
19
+ const storedSetupSchemaKeys = deepKeys(storedSetupSchema);
20
+
21
+ // components order may have changed; this would prevent properties from mixing up
22
+ const regex = /\.\d+\.__component__/;
23
+ let currentModelsSchemaComponentKeys = currentModelsSchemaKeys.filter((key) => key.match(regex)).map((key) => key.replace(regex, ''));
24
+ let storedSetupSchemaComponentKeys = storedSetupSchemaKeys.filter((key) => key.match(regex)).map((key) => key.replace(regex, ''));
25
+ currentModelsSchemaComponentKeys = uniq(currentModelsSchemaComponentKeys);
26
+ storedSetupSchemaComponentKeys = uniq(storedSetupSchemaComponentKeys);
27
+
28
+ const currentModelsSchemaComponentKeysComponentProp = currentModelsSchemaKeys.filter((key) => key.includes('__component__') && currentModelsSchemaComponentKeys.some((k) => key.includes(k)));
29
+ const storedSetupSchemaComponentKeysComponentProp = storedSetupSchemaKeys.filter((key) => key.includes('__component__') && storedSetupSchemaComponentKeys.some((k) => key.includes(k)));
30
+
31
+ /**
32
+ * Is in the "stored setup schema" but not in the "current model"
33
+ */
34
+ let removedKeys = [];
35
+ removedKeys.push(...storedSetupSchemaComponentKeysComponentProp.map((key) => {
36
+ const storedComponentName = get(storedSetupSchema, key);
37
+ const currentComponentName = get(localizableTree, key);
38
+
39
+ // this must return an array of keys
40
+ if (storedComponentName !== currentComponentName) {
41
+ const part = key.split('.').slice(0, -1).join('.');
42
+
43
+ return storedSetupSchemaKeys.filter((k) => k.includes(part));
44
+ }
45
+
46
+ return [];
47
+ }).reduce((acc, val) => acc.concat(val), []));
48
+ removedKeys.push(...storedSetupSchemaKeys.filter((key) => !currentModelsSchemaKeys.includes(key)));
49
+ removedKeys = uniq(removedKeys);
50
+
51
+ /**
52
+ * Is in the "current model" but not in the "stored setup schema"
53
+ */
54
+ let newKeys = [];
55
+ newKeys.push(...currentModelsSchemaComponentKeysComponentProp.map((key) => {
56
+ const storedComponentName = get(storedSetupSchema, key);
57
+ const currentComponentName = get(localizableTree, key);
58
+
59
+ // this must return an array of keys
60
+ if (storedComponentName !== currentComponentName) {
61
+ const part = key.split('.').slice(0, -1).join('.');
62
+
63
+ return currentModelsSchemaKeys.filter((k) => k.includes(part));
64
+ }
65
+
66
+ return [];
67
+ }).reduce((acc, val) => acc.concat(val), []));
68
+ newKeys.push(...currentModelsSchemaKeys.filter((key) => !storedSetupSchemaKeys.includes(key)));
69
+ newKeys = uniq(newKeys);
70
+
71
+ /**
72
+ * Filter out the removed keys
73
+ */
74
+ const filteredStoredSetupSchemaKeys = storedSetupSchemaKeys.filter(
75
+ (key) => !removedKeys.includes(key)
76
+ );
77
+
78
+ return {
79
+ oLocalizableTree: localizableTree,
80
+ oStoredSetupSchema: storedSetupSchema,
81
+ removedKeys,
82
+ newKeys,
83
+ filteredStoredSetupSchemaKeys,
84
+ }
85
+ }
@@ -1,12 +1,9 @@
1
- import deepKeys from "@david-vaclavek/deep-keys";
2
1
  import get from "lodash-es/get";
3
- import uniq from "lodash-es/uniq";
4
2
  import PluginSettingsService from "../services/plugin-settings-service";
5
3
  import StrapiModelService from "../services/strapi-model-service";
6
4
  import getModelsTree from "../utils/get-models-tree";
7
- import sortByModelName from "../../@common/utils/sort-by-model-name";
8
- import arrayOfModelsToObject from "../utils/array-of-models-to-object";
9
5
  import findModelValueByKey from "../utils/find-model-value-by-key";
6
+ import getContentTransferSetupKeysSets from "./get-content-transfer-setup-keys-sets";
10
7
 
11
8
  /**
12
9
  * Pass parameters optionally so we don't have to fetch them again
@@ -37,53 +34,26 @@ export default async (
37
34
  allModelsTree = getModelsTree(models, models);
38
35
  }
39
36
 
40
- localizableTree = arrayOfModelsToObject(
41
- localizableTree.sort(sortByModelName)
42
- );
43
- storedSetupSchema = arrayOfModelsToObject(
44
- storedSetupSchema.sort(sortByModelName)
45
- );
46
-
47
- const currentModelsSchemaKeys = deepKeys(localizableTree);
48
- const unsortedStoredSetupSchemaKeys = deepKeys(storedSetupSchema);
49
-
50
- // components order may have changed; this would prevent properties from mixing up
51
- const regex = /\.\d+\.__component__/;
52
- let currentModelsSchemaComponentKeys = currentModelsSchemaKeys.filter((key) => key.match(regex)).map((key) => key.replace(regex, ''));
53
- let storedSetupSchemaComponentKeys = unsortedStoredSetupSchemaKeys.filter((key) => key.match(regex)).map((key) => key.replace(regex, ''));
54
- currentModelsSchemaComponentKeys = uniq(currentModelsSchemaComponentKeys);
55
- storedSetupSchemaComponentKeys = uniq(storedSetupSchemaComponentKeys);
56
-
57
- currentModelsSchemaComponentKeys.forEach((key) => {
58
- get(localizableTree, key).sort((a, b) => a.__component__ > b.__component__ ? 1 : -1);
59
- });
60
-
61
- storedSetupSchemaComponentKeys.forEach((key) => {
62
- get(storedSetupSchema, key).sort((a, b) => a.__component__ > b.__component__ ? 1 : -1);
63
- });
64
-
65
- const modelsTreeKeys = deepKeys(localizableTree);
66
- const storedSetupSchemaKeys = deepKeys(storedSetupSchema);
67
-
68
-
69
- const removedKeys = storedSetupSchemaKeys.filter(
70
- (x) => !modelsTreeKeys.includes(x)
71
- );
72
- const newKeys = modelsTreeKeys.filter(
73
- (key) => !storedSetupSchemaKeys.includes(key)
37
+ const {
38
+ oStoredSetupSchema,
39
+ removedKeys,
40
+ newKeys,
41
+ filteredStoredSetupSchemaKeys
42
+ } = getContentTransferSetupKeysSets(
43
+ localizableTree,
44
+ storedSetupSchema,
74
45
  );
75
46
 
76
47
  if (newKeys.length || removedKeys.length) {
77
48
  return true;
78
49
  }
79
50
 
80
- const filteredStoredSetupSchemaKeys = storedSetupSchemaKeys.filter(
81
- (key) => !removedKeys.includes(key)
82
- );
83
-
51
+ /**
52
+ * Check if the values are different (type might have changed; boolean to null or vice versa)
53
+ */
84
54
  // eslint-disable-next-line no-restricted-syntax
85
55
  for (const key of filteredStoredSetupSchemaKeys) {
86
- const localizableTreeValueToSet = get(storedSetupSchema, key);
56
+ const localizableTreeValueToSet = get(oStoredSetupSchema, key);
87
57
  const allModelsTreeValueToSet = findModelValueByKey(allModelsTree, key);
88
58
 
89
59
  if (
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@localazy/strapi-plugin",
3
- "version": "0.1.13-rc.4",
3
+ "version": "0.1.13-rc.6",
4
4
  "description": "The official Strapi Plugin by Localazy.",
5
5
  "strapi": {
6
6
  "name": "localazy",
@@ -39,7 +39,7 @@
39
39
  },
40
40
  "dependencies": {
41
41
  "@david-vaclavek/deep-keys": "^0.5.0",
42
- "@localazy/ts-api": "^1.0.12",
42
+ "@localazy/ts-api": "^1.0.13",
43
43
  "i18next": "^22.4.9",
44
44
  "isomorphic-fetch": "^3.0.0",
45
45
  "js-cookie": "^3.0.1",
@@ -2,6 +2,7 @@
2
2
 
3
3
  const deepPopulateHook = require('./lifecycles/deep-populate-hook');
4
4
  const uploadEventEntryToLocalazyHook = require('./lifecycles/upload-event-entry-to-localazy-hook');
5
+ const deprecateEventEntryInLocalazyHook = require('./lifecycles/deprecate-event-entry-in-localazy-hook');
5
6
  const RequestInitiatorHelper = require('./utils/request-initiator-helper');
6
7
 
7
8
  module.exports = ({ strapi }) => {
@@ -34,6 +35,24 @@ module.exports = ({ strapi }) => {
34
35
  break;
35
36
  }
36
37
  }
38
+ case 'beforeDeleteMany':
39
+ case 'beforeDelete': {
40
+ try {
41
+ if (requestInitiatorHelper.isInitiatedByLocalazyWebhook() || requestInitiatorHelper.isInitiatedByLocalazyPluginUI()) {
42
+ break;
43
+ }
44
+
45
+ // have to await here
46
+ const result = await deprecateEventEntryInLocalazyHook(event);
47
+ if (typeof result !== 'undefined') {
48
+ strapi.log.info(`${action} hook result: ${JSON.stringify(result)}`);
49
+ }
50
+ } catch (e) {
51
+ strapi.log.error(e);
52
+ } finally {
53
+ break;
54
+ }
55
+ }
37
56
  default:
38
57
  break;
39
58
  }
@@ -12,4 +12,5 @@ module.exports = {
12
12
  LOCALAZY_DEFAULT_LOCALE: "en",
13
13
  LOCALAZY_API_USER_JWT_COOKIE_NAME: "LOCALAZY-API-USER-JWT",
14
14
  LOCALAZY_API_USER_COOKIE_EXPIRATION: 7,
15
+ LOCALAZY_PUBLIC_API_LIFTED_LIMITS: true,
15
16
  };
@@ -11,5 +11,6 @@ module.exports = {
11
11
  LOCALAZY_DEFAULT_FILE_EXTENSION: "",
12
12
  LOCALAZY_DEFAULT_LOCALE: "",
13
13
  LOCALAZY_API_USER_JWT_COOKIE_NAME: "",
14
- LOCALAZY_API_USER_COOKIE_EXPIRATION: 7,
14
+ LOCALAZY_API_USER_COOKIE_EXPIRATION: -1,
15
+ LOCALAZY_PUBLIC_API_LIFTED_LIMITS: false,
15
16
  };
@@ -12,4 +12,5 @@ module.exports = {
12
12
  LOCALAZY_DEFAULT_LOCALE: "en",
13
13
  LOCALAZY_API_USER_JWT_COOKIE_NAME: "LOCALAZY-API-USER-JWT",
14
14
  LOCALAZY_API_USER_COOKIE_EXPIRATION: 7,
15
+ LOCALAZY_PUBLIC_API_LIFTED_LIMITS: false,
15
16
  };
@@ -13,4 +13,5 @@ module.exports = {
13
13
  LOCALAZY_DEFAULT_LOCALE: "en",
14
14
  LOCALAZY_API_USER_JWT_COOKIE_NAME: "LOCALAZY-API-USER-JWT",
15
15
  LOCALAZY_API_USER_COOKIE_EXPIRATION: 7,
16
+ LOCALAZY_PUBLIC_API_LIFTED_LIMITS: true,
16
17
  };
@@ -177,11 +177,12 @@ module.exports = {
177
177
  locale,
178
178
  chunks
179
179
  );
180
+ // Use `deprecate: "file"` if there is one chunk of transferred data only!
181
+ const hasMoreTransferFilesChunks = importFile.length > 1;
182
+ const uploadConfig = !hasMoreTransferFilesChunks ? { deprecate: "file" } : {};
180
183
  await LocalazyUploadService.upload(
181
184
  importFile,
182
- // {
183
- // deprecate: "file"
184
- // }
185
+ uploadConfig
185
186
  );
186
187
 
187
188
  ctx.body = {
@@ -4,6 +4,7 @@
4
4
 
5
5
  const getLocalazyApi = require("../utils/get-localazy-api");
6
6
  const delay = require("../utils/delay");
7
+ const config = require("../config").default;
7
8
 
8
9
  module.exports = ({ strapi }) => ({
9
10
  /**
@@ -45,15 +46,21 @@ module.exports = ({ strapi }) => ({
45
46
  }
46
47
  },
47
48
 
48
- splitToChunks(data, CHUNK_LIMIT = 1000) {
49
+ /**
50
+ * Check Directus for the Lifted Limits OAuth Apps IDs
51
+ */
52
+ CHUNK_LIMIT: config.LOCALAZY_PUBLIC_API_LIFTED_LIMITS ? 99900 : 9990,
53
+
54
+ splitToChunks(data, CHUNK_LIMIT = null) {
49
55
  const chunks = [];
50
56
  const keys = Object.keys(data);
51
57
  const keysCount = keys.length;
52
- const chunksCount = Math.ceil(keysCount / CHUNK_LIMIT);
58
+ const localChunkLimit = CHUNK_LIMIT || this.CHUNK_LIMIT;
59
+ const chunksCount = Math.ceil(keysCount / localChunkLimit);
53
60
  for (let i = 0; i < chunksCount; i += 1) {
54
61
  const chunkStrings = {};
55
- const from = CHUNK_LIMIT * i;
56
- const to = CHUNK_LIMIT * (i + 1);
62
+ const from = localChunkLimit * i;
63
+ const to = localChunkLimit * (i + 1);
57
64
 
58
65
  const currentKeys = keys.slice(from, to);
59
66
  currentKeys.forEach((key) => {
@@ -1,33 +0,0 @@
1
- import {
2
- ApolloClient,
3
- HttpLink,
4
- ApolloLink,
5
- InMemoryCache,
6
- } from "@apollo/client";
7
- import Cookies from "js-cookie";
8
-
9
- const createClient = () => {
10
- const httpLink = new HttpLink({ uri: process.env.STRAPI_ADMIN_GRAPHQL_URL });
11
-
12
- const authLink = new ApolloLink((operation, forward) => {
13
- // Retrieve the authorization token from local storage.
14
- const token = Cookies.get('LOCALAZY-API-USER-JWT');
15
-
16
- // Use the setContext method to set the HTTP headers.
17
- operation.setContext({
18
- headers: {
19
- 'Authorization': token ? `Bearer ${token}` : ''
20
- }
21
- });
22
-
23
- // Call the next link in the middleware chain.
24
- return forward(operation);
25
- });
26
-
27
- return new ApolloClient({
28
- link: authLink.concat(httpLink),
29
- cache: new InMemoryCache()
30
- });
31
- }
32
-
33
- export default createClient;