@localazy/strapi-plugin 1.0.0-beta.1 → 1.0.0-beta.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 (35) hide show
  1. package/dist/_chunks/{App-BSFfgZKU.mjs → App-1cXVSnL0.mjs} +59 -32
  2. package/dist/_chunks/{App-D1QaIMHX.js → App-CU_T8iLT.js} +66 -39
  3. package/dist/_chunks/{ContentTransferSetup-DtjcF_jM.mjs → ContentTransferSetup-D2R15gJS.mjs} +27 -8
  4. package/dist/_chunks/{ContentTransferSetup-DHXJIxAp.js → ContentTransferSetup-DTcnul1w.js} +27 -8
  5. package/dist/_chunks/{GlobalSettings-BcdibqNS.mjs → GlobalSettings-7pI5vIna.mjs} +8 -5
  6. package/dist/_chunks/{GlobalSettings-BON3kjHK.js → GlobalSettings-D_jeqPWF.js} +8 -5
  7. package/dist/_chunks/{LanguagesSelector-fyAIUp7M.mjs → LanguagesSelector-D2AP7FE0.mjs} +2 -2
  8. package/dist/_chunks/{LanguagesSelector-BeijBEjg.js → LanguagesSelector-DU5YJVQa.js} +2 -2
  9. package/dist/_chunks/{has-model-changed-BMCQX2Dd.js → has-model-changed-9PCipZvK.js} +2 -2
  10. package/dist/_chunks/{has-model-changed-Dvtzpc9v.mjs → has-model-changed-wAFZY5Ma.mjs} +2 -2
  11. package/dist/_chunks/{index-CN3Gyh5F.mjs → index-CT0CH6N8.mjs} +19 -43
  12. package/dist/_chunks/{index-BQw2qi2G.js → index-Ca5_8RSo.js} +18 -42
  13. package/dist/_chunks/{isEqual-B-YVnzrp.js → isEqual--zmPN5yr.js} +1 -1
  14. package/dist/_chunks/{isEqual-CEyT97-3.mjs → isEqual-DPUlu6B0.mjs} +1 -1
  15. package/dist/_chunks/{set-DulHAQhq.mjs → set-BkLLlpnD.mjs} +4 -1
  16. package/dist/_chunks/{set-DUdH3vE5.js → set-DDy9ZASU.js} +4 -1
  17. package/dist/admin/index.js +1 -1
  18. package/dist/admin/index.mjs +1 -1
  19. package/dist/admin/src/modules/@common/utils/iso-locales-utils.d.ts +3 -3
  20. package/dist/admin/src/modules/plugin-settings/locale/en.d.ts +3 -0
  21. package/dist/admin/src/modules/plugin-settings/models/admin-panel-user.d.ts +11 -0
  22. package/dist/admin/src/modules/plugin-settings/services/strapi-users-service.d.ts +2 -1
  23. package/dist/admin/src/state/localazy-identity.d.ts +2 -0
  24. package/dist/server/index.js +109 -32
  25. package/dist/server/index.mjs +109 -32
  26. package/dist/server/src/core/index.d.ts +3 -3
  27. package/dist/server/src/index.d.ts +20 -5
  28. package/dist/server/src/middlewares/index.d.ts +5 -1
  29. package/dist/server/src/middlewares/verify-webhook.d.ts +5 -0
  30. package/dist/server/src/routes/index.d.ts +12 -1
  31. package/dist/server/src/routes/localazy-public-transfer-routes.d.ts +11 -0
  32. package/dist/server/src/services/index.d.ts +3 -3
  33. package/dist/server/src/services/localazy-pubapi-service.d.ts +6 -5
  34. package/package.json +1 -1
  35. package/dist/admin/src/modules/@common/utils/is-plugin-route.d.ts +0 -2
@@ -1,6 +1,5 @@
1
1
  import React__default, { useRef, useEffect, createContext, useState, useMemo, useContext } from "react";
2
2
  import { jsxs, jsx } from "react/jsx-runtime";
3
- import { useNavigate } from "react-router-dom";
4
3
  const __variableDynamicImportRuntimeHelper = (glob, path, segs) => {
5
4
  const v = glob[path];
6
5
  if (v) {
@@ -55,8 +54,15 @@ const emptyIdentity = {
55
54
  const LocalazyIdentityContextType = createContext(void 0);
56
55
  const LocalazyIdentityProvider = ({ children }) => {
57
56
  const [identity, setIdentity] = useState(emptyIdentity);
57
+ const [isFetchingIdentity, setIsFetchingIdentity] = useState(true);
58
58
  const isLoggedIn = useMemo(() => !!identity.accessToken, [identity.accessToken]);
59
- return /* @__PURE__ */ jsx(LocalazyIdentityContextType.Provider, { value: { identity, setIdentity, isLoggedIn }, children });
59
+ return /* @__PURE__ */ jsx(
60
+ LocalazyIdentityContextType.Provider,
61
+ {
62
+ value: { identity, setIdentity, isLoggedIn, isFetchingIdentity, setIsFetchingIdentity },
63
+ children
64
+ }
65
+ );
60
66
  };
61
67
  const useLocalazyIdentity = () => {
62
68
  const context = useContext(LocalazyIdentityContextType);
@@ -2522,50 +2528,22 @@ class LocalazyUserService {
2522
2528
  }
2523
2529
  }
2524
2530
  }
2525
- var PLUGIN_ROUTES = /* @__PURE__ */ ((PLUGIN_ROUTES2) => {
2526
- PLUGIN_ROUTES2["ROOT"] = "";
2527
- PLUGIN_ROUTES2["LOGIN"] = "login";
2528
- PLUGIN_ROUTES2["UPLOAD"] = "upload";
2529
- PLUGIN_ROUTES2["DOWNLOAD"] = "download";
2530
- PLUGIN_ROUTES2["OVERVIEW"] = "overview";
2531
- PLUGIN_ROUTES2["CONTENT_TRANSFER_SETUP"] = "content-transfer-setup";
2532
- PLUGIN_ROUTES2["GLOBAL_SETTINGS"] = "global-settings";
2533
- return PLUGIN_ROUTES2;
2534
- })(PLUGIN_ROUTES || {});
2535
- const useRedirectToPluginRoute = () => {
2536
- const navigate = useNavigate();
2537
- const navigateToPluginRoute = (route) => {
2538
- if ([
2539
- "content-transfer-setup",
2540
- "global-settings"
2541
- /* GLOBAL_SETTINGS */
2542
- ].includes(route)) {
2543
- navigate(`/settings/${PLUGIN_ID}/${route}`);
2544
- return;
2545
- }
2546
- navigate(`/plugins/${PLUGIN_ID}/${route}`);
2547
- };
2548
- return {
2549
- navigateToPluginRoute
2550
- };
2551
- };
2552
2531
  const FetchIdentity = () => {
2553
- const { setIdentity } = useLocalazyIdentity();
2554
- const { navigateToPluginRoute } = useRedirectToPluginRoute();
2532
+ const { setIdentity, setIsFetchingIdentity } = useLocalazyIdentity();
2555
2533
  useEffect(() => {
2556
2534
  const fetchIdentity = async () => {
2557
2535
  try {
2558
- const identity = await LocalazyUserService.getIdentity();
2559
- setIdentity(identity || emptyIdentity);
2560
- if (!identity?.accessToken) {
2561
- navigateToPluginRoute(PLUGIN_ROUTES.LOGIN);
2562
- }
2536
+ setIsFetchingIdentity(true);
2537
+ const fetchedIdentity = await LocalazyUserService.getIdentity();
2538
+ setIdentity(fetchedIdentity || emptyIdentity);
2563
2539
  } catch (error) {
2564
2540
  console.error("Error fetching identity:", error);
2541
+ } finally {
2542
+ setIsFetchingIdentity(false);
2565
2543
  }
2566
2544
  };
2567
2545
  fetchIdentity();
2568
- }, [setIdentity]);
2546
+ }, [setIdentity, setIsFetchingIdentity]);
2569
2547
  return null;
2570
2548
  };
2571
2549
  const index = {
@@ -2596,7 +2574,7 @@ const addMenuLink = (app) => {
2596
2574
  defaultMessage: getTranslation("name")
2597
2575
  },
2598
2576
  Component: async () => {
2599
- const { App } = await import("./App-BSFfgZKU.mjs");
2577
+ const { App } = await import("./App-1cXVSnL0.mjs");
2600
2578
  const { LocalazyIdentityProvider: LocalazyIdentityProvider2 } = await Promise.resolve().then(() => localazyIdentity);
2601
2579
  const WrappedApp = () => React__default.createElement(LocalazyIdentityProvider2, {
2602
2580
  children: React__default.createElement(React__default.Fragment, {}, [
@@ -2627,7 +2605,7 @@ const addSettingsSection = (app) => {
2627
2605
  },
2628
2606
  to: `/settings/${PLUGIN_ID}/global-settings`,
2629
2607
  Component: async () => {
2630
- const { GlobalSettings } = await import("./GlobalSettings-BcdibqNS.mjs");
2608
+ const { GlobalSettings } = await import("./GlobalSettings-7pI5vIna.mjs");
2631
2609
  const { LocalazyIdentityProvider: LocalazyIdentityProvider2 } = await Promise.resolve().then(() => localazyIdentity);
2632
2610
  const WrappedGlobalSettings = () => React__default.createElement(LocalazyIdentityProvider2, { children: React__default.createElement(GlobalSettings, {}) });
2633
2611
  return WrappedGlobalSettings;
@@ -2643,7 +2621,7 @@ const addSettingsSection = (app) => {
2643
2621
  },
2644
2622
  to: `/settings/${PLUGIN_ID}/content-transfer-setup`,
2645
2623
  Component: async () => {
2646
- const { ContentTransferSetup } = await import("./ContentTransferSetup-DtjcF_jM.mjs");
2624
+ const { ContentTransferSetup } = await import("./ContentTransferSetup-D2R15gJS.mjs");
2647
2625
  const { LocalazyIdentityProvider: LocalazyIdentityProvider2 } = await Promise.resolve().then(() => localazyIdentity);
2648
2626
  const WrappedContentTransferSetup = () => React__default.createElement(LocalazyIdentityProvider2, {
2649
2627
  children: React__default.createElement(React__default.Fragment, {}, [
@@ -2669,10 +2647,8 @@ const addPlugin = (app) => {
2669
2647
  export {
2670
2648
  LocalazyUserService as L,
2671
2649
  PLUGIN_ID as P,
2672
- useLocalazyIdentity as a,
2673
- PLUGIN_ROUTES as b,
2674
2650
  createStrapiApiAxiosInstance as c,
2675
2651
  emptyIdentity as e,
2676
2652
  index as i,
2677
- useRedirectToPluginRoute as u
2653
+ useLocalazyIdentity as u
2678
2654
  };
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  const React = require("react");
3
3
  const jsxRuntime = require("react/jsx-runtime");
4
- const reactRouterDom = require("react-router-dom");
5
4
  const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
6
5
  const React__default = /* @__PURE__ */ _interopDefault(React);
7
6
  const __variableDynamicImportRuntimeHelper = (glob, path, segs) => {
@@ -58,8 +57,15 @@ const emptyIdentity = {
58
57
  const LocalazyIdentityContextType = React.createContext(void 0);
59
58
  const LocalazyIdentityProvider = ({ children }) => {
60
59
  const [identity, setIdentity] = React.useState(emptyIdentity);
60
+ const [isFetchingIdentity, setIsFetchingIdentity] = React.useState(true);
61
61
  const isLoggedIn = React.useMemo(() => !!identity.accessToken, [identity.accessToken]);
62
- return /* @__PURE__ */ jsxRuntime.jsx(LocalazyIdentityContextType.Provider, { value: { identity, setIdentity, isLoggedIn }, children });
62
+ return /* @__PURE__ */ jsxRuntime.jsx(
63
+ LocalazyIdentityContextType.Provider,
64
+ {
65
+ value: { identity, setIdentity, isLoggedIn, isFetchingIdentity, setIsFetchingIdentity },
66
+ children
67
+ }
68
+ );
63
69
  };
64
70
  const useLocalazyIdentity = () => {
65
71
  const context = React.useContext(LocalazyIdentityContextType);
@@ -2525,50 +2531,22 @@ class LocalazyUserService {
2525
2531
  }
2526
2532
  }
2527
2533
  }
2528
- var PLUGIN_ROUTES = /* @__PURE__ */ ((PLUGIN_ROUTES2) => {
2529
- PLUGIN_ROUTES2["ROOT"] = "";
2530
- PLUGIN_ROUTES2["LOGIN"] = "login";
2531
- PLUGIN_ROUTES2["UPLOAD"] = "upload";
2532
- PLUGIN_ROUTES2["DOWNLOAD"] = "download";
2533
- PLUGIN_ROUTES2["OVERVIEW"] = "overview";
2534
- PLUGIN_ROUTES2["CONTENT_TRANSFER_SETUP"] = "content-transfer-setup";
2535
- PLUGIN_ROUTES2["GLOBAL_SETTINGS"] = "global-settings";
2536
- return PLUGIN_ROUTES2;
2537
- })(PLUGIN_ROUTES || {});
2538
- const useRedirectToPluginRoute = () => {
2539
- const navigate = reactRouterDom.useNavigate();
2540
- const navigateToPluginRoute = (route) => {
2541
- if ([
2542
- "content-transfer-setup",
2543
- "global-settings"
2544
- /* GLOBAL_SETTINGS */
2545
- ].includes(route)) {
2546
- navigate(`/settings/${PLUGIN_ID}/${route}`);
2547
- return;
2548
- }
2549
- navigate(`/plugins/${PLUGIN_ID}/${route}`);
2550
- };
2551
- return {
2552
- navigateToPluginRoute
2553
- };
2554
- };
2555
2534
  const FetchIdentity = () => {
2556
- const { setIdentity } = useLocalazyIdentity();
2557
- const { navigateToPluginRoute } = useRedirectToPluginRoute();
2535
+ const { setIdentity, setIsFetchingIdentity } = useLocalazyIdentity();
2558
2536
  React.useEffect(() => {
2559
2537
  const fetchIdentity = async () => {
2560
2538
  try {
2561
- const identity = await LocalazyUserService.getIdentity();
2562
- setIdentity(identity || emptyIdentity);
2563
- if (!identity?.accessToken) {
2564
- navigateToPluginRoute(PLUGIN_ROUTES.LOGIN);
2565
- }
2539
+ setIsFetchingIdentity(true);
2540
+ const fetchedIdentity = await LocalazyUserService.getIdentity();
2541
+ setIdentity(fetchedIdentity || emptyIdentity);
2566
2542
  } catch (error) {
2567
2543
  console.error("Error fetching identity:", error);
2544
+ } finally {
2545
+ setIsFetchingIdentity(false);
2568
2546
  }
2569
2547
  };
2570
2548
  fetchIdentity();
2571
- }, [setIdentity]);
2549
+ }, [setIdentity, setIsFetchingIdentity]);
2572
2550
  return null;
2573
2551
  };
2574
2552
  const index = {
@@ -2599,7 +2577,7 @@ const addMenuLink = (app) => {
2599
2577
  defaultMessage: getTranslation("name")
2600
2578
  },
2601
2579
  Component: async () => {
2602
- const { App } = await Promise.resolve().then(() => require("./App-D1QaIMHX.js"));
2580
+ const { App } = await Promise.resolve().then(() => require("./App-CU_T8iLT.js"));
2603
2581
  const { LocalazyIdentityProvider: LocalazyIdentityProvider2 } = await Promise.resolve().then(() => localazyIdentity);
2604
2582
  const WrappedApp = () => React__default.default.createElement(LocalazyIdentityProvider2, {
2605
2583
  children: React__default.default.createElement(React__default.default.Fragment, {}, [
@@ -2630,7 +2608,7 @@ const addSettingsSection = (app) => {
2630
2608
  },
2631
2609
  to: `/settings/${PLUGIN_ID}/global-settings`,
2632
2610
  Component: async () => {
2633
- const { GlobalSettings } = await Promise.resolve().then(() => require("./GlobalSettings-BON3kjHK.js"));
2611
+ const { GlobalSettings } = await Promise.resolve().then(() => require("./GlobalSettings-D_jeqPWF.js"));
2634
2612
  const { LocalazyIdentityProvider: LocalazyIdentityProvider2 } = await Promise.resolve().then(() => localazyIdentity);
2635
2613
  const WrappedGlobalSettings = () => React__default.default.createElement(LocalazyIdentityProvider2, { children: React__default.default.createElement(GlobalSettings, {}) });
2636
2614
  return WrappedGlobalSettings;
@@ -2646,7 +2624,7 @@ const addSettingsSection = (app) => {
2646
2624
  },
2647
2625
  to: `/settings/${PLUGIN_ID}/content-transfer-setup`,
2648
2626
  Component: async () => {
2649
- const { ContentTransferSetup } = await Promise.resolve().then(() => require("./ContentTransferSetup-DHXJIxAp.js"));
2627
+ const { ContentTransferSetup } = await Promise.resolve().then(() => require("./ContentTransferSetup-DTcnul1w.js"));
2650
2628
  const { LocalazyIdentityProvider: LocalazyIdentityProvider2 } = await Promise.resolve().then(() => localazyIdentity);
2651
2629
  const WrappedContentTransferSetup = () => React__default.default.createElement(LocalazyIdentityProvider2, {
2652
2630
  children: React__default.default.createElement(React__default.default.Fragment, {}, [
@@ -2671,9 +2649,7 @@ const addPlugin = (app) => {
2671
2649
  };
2672
2650
  exports.LocalazyUserService = LocalazyUserService;
2673
2651
  exports.PLUGIN_ID = PLUGIN_ID;
2674
- exports.PLUGIN_ROUTES = PLUGIN_ROUTES;
2675
2652
  exports.createStrapiApiAxiosInstance = createStrapiApiAxiosInstance;
2676
2653
  exports.emptyIdentity = emptyIdentity;
2677
2654
  exports.index = index;
2678
2655
  exports.useLocalazyIdentity = useLocalazyIdentity;
2679
- exports.useRedirectToPluginRoute = useRedirectToPluginRoute;
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- const set = require("./set-DUdH3vE5.js");
2
+ const set = require("./set-DDy9ZASU.js");
3
3
  function arraySome(array, predicate) {
4
4
  var index = -1, length = array == null ? 0 : array.length;
5
5
  while (++index < length) {
@@ -1,4 +1,4 @@
1
- import { _ as SetCache, $ as cacheHas, a0 as Symbol$1, a1 as eq, a2 as Uint8Array, Z as setToArray, a3 as getAllKeys, a4 as getTag, a5 as isBuffer, a6 as Stack, a7 as isTypedArray, Q as isArray, a8 as isObjectLike } from "./set-DulHAQhq.mjs";
1
+ import { _ as SetCache, $ as cacheHas, a0 as Symbol$1, a1 as eq, a2 as Uint8Array, Z as setToArray, a3 as getAllKeys, a4 as getTag, a5 as isBuffer, a6 as Stack, a7 as isTypedArray, Q as isArray, a8 as isObjectLike } from "./set-BkLLlpnD.mjs";
2
2
  function arraySome(array, predicate) {
3
3
  var index = -1, length = array == null ? 0 : array.length;
4
4
  while (++index < length) {
@@ -4,7 +4,7 @@ import { jsxs, Fragment as Fragment$1, jsx } from "react/jsx-runtime";
4
4
  import * as ReactDOM from "react-dom";
5
5
  import ReactDOM__default, { flushSync, createPortal } from "react-dom";
6
6
  import { useTheme, ThemeProvider, createGlobalStyle, css, styled, keyframes } from "styled-components";
7
- import { c as createStrapiApiAxiosInstance } from "./index-CN3Gyh5F.mjs";
7
+ import { c as createStrapiApiAxiosInstance } from "./index-CT0CH6N8.mjs";
8
8
  function $b1b2314f5f9a1d84$export$25bec8c6f54ee79a(callback) {
9
9
  const callbackRef = useRef(callback);
10
10
  useEffect(() => {
@@ -53618,6 +53618,9 @@ const en_plugin_settings = {
53618
53618
  step_3: "Check <1>Enable localization for this Content-Type</1>",
53619
53619
  step_4: "Repeat for all Content-Types you want to translate",
53620
53620
  step_5: "Return to this screen and finish the transfer setup",
53621
+ tree_item_count_zero: "(no selected fields)",
53622
+ tree_item_count_one: "({{count}} selected field)",
53623
+ tree_item_count_other: "({{count}} selected fields)",
53621
53624
  general: "General"
53622
53625
  };
53623
53626
  const initI18nParams = () => {
@@ -3,7 +3,7 @@ const React = require("react");
3
3
  const jsxRuntime = require("react/jsx-runtime");
4
4
  const ReactDOM = require("react-dom");
5
5
  const styled = require("styled-components");
6
- const index$1 = require("./index-BQw2qi2G.js");
6
+ const index$1 = require("./index-Ca5_8RSo.js");
7
7
  function _interopNamespace(e) {
8
8
  if (e && e.__esModule) return e;
9
9
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
@@ -53636,6 +53636,9 @@ const en_plugin_settings = {
53636
53636
  step_3: "Check <1>Enable localization for this Content-Type</1>",
53637
53637
  step_4: "Repeat for all Content-Types you want to translate",
53638
53638
  step_5: "Return to this screen and finish the transfer setup",
53639
+ tree_item_count_zero: "(no selected fields)",
53640
+ tree_item_count_one: "({{count}} selected field)",
53641
+ tree_item_count_other: "({{count}} selected fields)",
53639
53642
  general: "General"
53640
53643
  };
53641
53644
  const initI18nParams = () => {
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
- const index = require("../_chunks/index-BQw2qi2G.js");
2
+ const index = require("../_chunks/index-Ca5_8RSo.js");
3
3
  require("react");
4
4
  module.exports = index.index;
@@ -1,4 +1,4 @@
1
- import { i } from "../_chunks/index-CN3Gyh5F.mjs";
1
+ import { i } from "../_chunks/index-CT0CH6N8.mjs";
2
2
  import "react";
3
3
  export {
4
4
  i as default
@@ -1,3 +1,3 @@
1
- import { Locales } from '@localazy/api-client';
2
- export declare const isoStrapiToLocalazy: (isoStrapi: string) => Locales | '';
3
- export declare const isoLocalazyToStrapi: (isoLocalazy: Locales) => string;
1
+ declare const isoStrapiToLocalazy: (isoStrapi: string) => string | null;
2
+ declare const isoLocalazyToStrapi: (isoLocalazy: string) => string | null;
3
+ export { isoStrapiToLocalazy, isoLocalazyToStrapi };
@@ -44,6 +44,9 @@ declare const _default: {
44
44
  step_3: string;
45
45
  step_4: string;
46
46
  step_5: string;
47
+ tree_item_count_zero: string;
48
+ tree_item_count_one: string;
49
+ tree_item_count_other: string;
47
50
  general: string;
48
51
  };
49
52
  export default _default;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Admin panel user model
3
+ *
4
+ * Feel free to extend this model with additional properties
5
+ */
6
+ export type AdminPanelUser = {
7
+ id: number;
8
+ firstname: string;
9
+ lastname?: string;
10
+ email: string;
11
+ };
@@ -1,3 +1,4 @@
1
+ import { AdminPanelUser } from '../models/admin-panel-user';
1
2
  export default class PluginSettingsService {
2
- static getAdminPanelUsers(): Promise<any>;
3
+ static getAdminPanelUsers(): Promise<AdminPanelUser[]>;
3
4
  }
@@ -3,6 +3,8 @@ import React, { ReactNode } from 'react';
3
3
  interface LocalazyIdentityContextType {
4
4
  identity: LocalazyIdentity;
5
5
  setIdentity: React.Dispatch<React.SetStateAction<LocalazyIdentity>>;
6
+ isFetchingIdentity: boolean;
7
+ setIsFetchingIdentity: React.Dispatch<React.SetStateAction<boolean>>;
6
8
  isLoggedIn: boolean;
7
9
  }
8
10
  declare const LocalazyIdentityContextType: React.Context<LocalazyIdentityContextType | undefined>;
@@ -24208,13 +24208,66 @@ const controllers = {
24208
24208
  PluginSettingsController,
24209
24209
  LocalazyTransferController
24210
24210
  };
24211
- const middlewares = {};
24211
+ const verifyWebhook = (config2, { strapi: strapi2 }) => {
24212
+ return async (ctx, next) => {
24213
+ try {
24214
+ const pluginSettingsServiceHelper = new PluginSettingsServiceHelper();
24215
+ await pluginSettingsServiceHelper.setup();
24216
+ if (!pluginSettingsServiceHelper.shouldAllowWebhookDownloadProcess()) {
24217
+ throw new Error("Localazy Plugin: Webhook download process is disabled; terminating execution");
24218
+ }
24219
+ const requestBody = ctx.request.body;
24220
+ strapi2.log.info(`Localazy Plugin: Webhook of type '${requestBody.type}' procedure started`);
24221
+ const LocalazyPubApiService = getLocalazyPubAPIService();
24222
+ const LocalazyUserService2 = getLocalazyUserService();
24223
+ const user = await LocalazyUserService2.getUser();
24224
+ const secret = await LocalazyPubApiService.getWebhooksSecret(user.project.id);
24225
+ const xLocalazyHmac = ctx.request.header["x-localazy-hmac"];
24226
+ const xLocalazyTimestamp = ctx.request.header["x-localazy-timestamp"];
24227
+ const THRESHOLD = 9e5;
24228
+ const intXLocalazyTimestamp = parseInt(xLocalazyTimestamp);
24229
+ if (Number.isNaN(intXLocalazyTimestamp)) {
24230
+ throw new Error("Localazy Plugin: Webhook request invalid timestamp provided; terminating execution");
24231
+ }
24232
+ if (intXLocalazyTimestamp * 1e3 + THRESHOLD < Date.now()) {
24233
+ throw new Error("Localazy Plugin: Webhook request is older than threshold; terminating execution");
24234
+ }
24235
+ const strapiHmac = require$$0__default.default.createHmac("sha256", secret);
24236
+ const signedMessage = strapiHmac.update(`${xLocalazyTimestamp}-${JSON.stringify(requestBody)}`).digest("hex");
24237
+ if (xLocalazyHmac !== signedMessage) {
24238
+ throw new Error("Localazy Plugin: Webhook verification did not pass; terminating execution");
24239
+ } else {
24240
+ strapi2.log.info("Localazy Plugin: Webhook verification passed");
24241
+ }
24242
+ if (!ctx.state.user) {
24243
+ const webhookAuthorId = pluginSettingsServiceHelper.getWebhookAuthorId();
24244
+ if (Number.isNaN(webhookAuthorId)) {
24245
+ throw new Error("Localazy Plugin: Webhook author is not set; terminating execution");
24246
+ }
24247
+ ctx.state.user = {
24248
+ id: webhookAuthorId
24249
+ };
24250
+ }
24251
+ await next();
24252
+ strapi2.log.info(`Localazy Plugin: Webhook of type '${requestBody.type}' procedure finished`);
24253
+ } catch (e3) {
24254
+ strapi2.log.warn(e3.message);
24255
+ ctx.body = {
24256
+ success: false,
24257
+ message: e3.message
24258
+ };
24259
+ }
24260
+ };
24261
+ };
24262
+ const middlewares = {
24263
+ verifyWebhook
24264
+ };
24212
24265
  const policies = {};
24213
- const ROUTE_PREFIX$5 = "/user";
24266
+ const ROUTE_PREFIX$6 = "/user";
24214
24267
  const LocalazyUserRoutes = [
24215
24268
  {
24216
24269
  method: "GET",
24217
- path: `${ROUTE_PREFIX$5}`,
24270
+ path: `${ROUTE_PREFIX$6}`,
24218
24271
  handler: "LocalazyUserController.getUser",
24219
24272
  config: {
24220
24273
  policies: []
@@ -24222,7 +24275,7 @@ const LocalazyUserRoutes = [
24222
24275
  },
24223
24276
  {
24224
24277
  method: "PUT",
24225
- path: `${ROUTE_PREFIX$5}`,
24278
+ path: `${ROUTE_PREFIX$6}`,
24226
24279
  handler: "LocalazyUserController.updateUser",
24227
24280
  config: {
24228
24281
  policies: []
@@ -24230,18 +24283,18 @@ const LocalazyUserRoutes = [
24230
24283
  },
24231
24284
  {
24232
24285
  method: "DELETE",
24233
- path: `${ROUTE_PREFIX$5}`,
24286
+ path: `${ROUTE_PREFIX$6}`,
24234
24287
  handler: "LocalazyUserController.deleteUser",
24235
24288
  config: {
24236
24289
  policies: []
24237
24290
  }
24238
24291
  }
24239
24292
  ];
24240
- const ROUTE_PREFIX$4 = "/auth";
24293
+ const ROUTE_PREFIX$5 = "/auth";
24241
24294
  const LocalazyAuthRoutes = [
24242
24295
  {
24243
24296
  method: "GET",
24244
- path: `${ROUTE_PREFIX$4}/generate-keys`,
24297
+ path: `${ROUTE_PREFIX$5}/generate-keys`,
24245
24298
  handler: "LocalazyAuthController.generateKeys",
24246
24299
  config: {
24247
24300
  policies: []
@@ -24249,18 +24302,18 @@ const LocalazyAuthRoutes = [
24249
24302
  },
24250
24303
  {
24251
24304
  method: "GET",
24252
- path: `${ROUTE_PREFIX$4}/continuous-poll`,
24305
+ path: `${ROUTE_PREFIX$5}/continuous-poll`,
24253
24306
  handler: "LocalazyAuthController.continuousPoll",
24254
24307
  config: {
24255
24308
  policies: []
24256
24309
  }
24257
24310
  }
24258
24311
  ];
24259
- const ROUTE_PREFIX$3 = "/plugin-settings";
24312
+ const ROUTE_PREFIX$4 = "/plugin-settings";
24260
24313
  const PluginSettingsRoutes = [
24261
24314
  {
24262
24315
  method: "GET",
24263
- path: `${ROUTE_PREFIX$3}/content-transfer-setup`,
24316
+ path: `${ROUTE_PREFIX$4}/content-transfer-setup`,
24264
24317
  handler: "PluginSettingsController.getContentTransferSetup",
24265
24318
  config: {
24266
24319
  policies: []
@@ -24268,7 +24321,7 @@ const PluginSettingsRoutes = [
24268
24321
  },
24269
24322
  {
24270
24323
  method: "PUT",
24271
- path: `${ROUTE_PREFIX$3}/content-transfer-setup`,
24324
+ path: `${ROUTE_PREFIX$4}/content-transfer-setup`,
24272
24325
  handler: "PluginSettingsController.updateContentTransferSetup",
24273
24326
  config: {
24274
24327
  policies: []
@@ -24276,7 +24329,7 @@ const PluginSettingsRoutes = [
24276
24329
  },
24277
24330
  {
24278
24331
  method: "GET",
24279
- path: `${ROUTE_PREFIX$3}/plugin-settings`,
24332
+ path: `${ROUTE_PREFIX$4}/plugin-settings`,
24280
24333
  handler: "PluginSettingsController.getPluginSettings",
24281
24334
  config: {
24282
24335
  policies: []
@@ -24284,18 +24337,18 @@ const PluginSettingsRoutes = [
24284
24337
  },
24285
24338
  {
24286
24339
  method: "PUT",
24287
- path: `${ROUTE_PREFIX$3}/plugin-settings`,
24340
+ path: `${ROUTE_PREFIX$4}/plugin-settings`,
24288
24341
  handler: "PluginSettingsController.updatePluginSettings",
24289
24342
  config: {
24290
24343
  policies: []
24291
24344
  }
24292
24345
  }
24293
24346
  ];
24294
- const ROUTE_PREFIX$2 = "/strapi";
24347
+ const ROUTE_PREFIX$3 = "/strapi";
24295
24348
  const StrapiRoutes = [
24296
24349
  {
24297
24350
  method: "GET",
24298
- path: `${ROUTE_PREFIX$2}/models`,
24351
+ path: `${ROUTE_PREFIX$3}/models`,
24299
24352
  handler: "StrapiController.getModels",
24300
24353
  config: {
24301
24354
  policies: []
@@ -24303,7 +24356,7 @@ const StrapiRoutes = [
24303
24356
  },
24304
24357
  {
24305
24358
  method: "GET",
24306
- path: `${ROUTE_PREFIX$2}/localizable-models`,
24359
+ path: `${ROUTE_PREFIX$3}/localizable-models`,
24307
24360
  handler: "StrapiController.getLocalizableModels",
24308
24361
  config: {
24309
24362
  policies: []
@@ -24311,7 +24364,7 @@ const StrapiRoutes = [
24311
24364
  },
24312
24365
  {
24313
24366
  method: "POST",
24314
- path: `${ROUTE_PREFIX$2}/lifecycle/localazy-webhooks`,
24367
+ path: `${ROUTE_PREFIX$3}/lifecycle/localazy-webhooks`,
24315
24368
  handler: "StrapiController.postLifecycleLocalazyWebhooks",
24316
24369
  config: {
24317
24370
  policies: []
@@ -24319,18 +24372,18 @@ const StrapiRoutes = [
24319
24372
  },
24320
24373
  {
24321
24374
  method: "GET",
24322
- path: `${ROUTE_PREFIX$2}/version`,
24375
+ path: `${ROUTE_PREFIX$3}/version`,
24323
24376
  handler: "StrapiController.getPluginVersion",
24324
24377
  config: {
24325
24378
  policies: []
24326
24379
  }
24327
24380
  }
24328
24381
  ];
24329
- const ROUTE_PREFIX$1 = "/transfer";
24382
+ const ROUTE_PREFIX$2 = "/transfer";
24330
24383
  const LocalazyTransferRoutes = [
24331
24384
  {
24332
24385
  method: "POST",
24333
- path: `${ROUTE_PREFIX$1}/upload`,
24386
+ path: `${ROUTE_PREFIX$2}/upload`,
24334
24387
  handler: "LocalazyTransferController.upload",
24335
24388
  config: {
24336
24389
  policies: []
@@ -24338,27 +24391,40 @@ const LocalazyTransferRoutes = [
24338
24391
  },
24339
24392
  {
24340
24393
  method: "POST",
24341
- path: `${ROUTE_PREFIX$1}/download`,
24394
+ path: `${ROUTE_PREFIX$2}/download`,
24342
24395
  handler: "LocalazyTransferController.download",
24343
24396
  config: {
24344
24397
  policies: []
24345
24398
  }
24346
24399
  }
24347
24400
  ];
24348
- const ROUTE_PREFIX = "/project";
24401
+ const ROUTE_PREFIX$1 = "/project";
24349
24402
  const LocalazyProjectRoutes = [
24350
24403
  {
24351
24404
  method: "GET",
24352
- path: `${ROUTE_PREFIX}`,
24405
+ path: `${ROUTE_PREFIX$1}`,
24353
24406
  handler: "LocalazyProjectController.getConnectedProject",
24354
24407
  config: {
24355
24408
  policies: []
24356
24409
  }
24357
24410
  }
24358
24411
  ];
24412
+ const ROUTE_PREFIX = "/public/transfer";
24413
+ const LocalazyPublicTransferRoutes = [
24414
+ {
24415
+ method: "POST",
24416
+ path: `${ROUTE_PREFIX}/download`,
24417
+ handler: "LocalazyTransferController.download",
24418
+ config: {
24419
+ policies: [],
24420
+ auth: false,
24421
+ // make the route public
24422
+ middlewares: [`plugin::${PLUGIN_NAME}.verifyWebhook`]
24423
+ }
24424
+ }
24425
+ ];
24359
24426
  const routes = {
24360
24427
  "content-api": {
24361
- type: "content-api",
24362
24428
  routes: [...StrapiRoutes]
24363
24429
  },
24364
24430
  admin: {
@@ -24371,8 +24437,10 @@ const routes = {
24371
24437
  ...LocalazyTransferRoutes,
24372
24438
  ...LocalazyProjectRoutes
24373
24439
  ]
24440
+ },
24441
+ LocalazyPublicTransferRoutes: {
24442
+ routes: [...LocalazyPublicTransferRoutes]
24374
24443
  }
24375
- // localazyPublicTransferRoutes,
24376
24444
  };
24377
24445
  const KEY$2 = "identity";
24378
24446
  const emptyIdentity = {
@@ -24512,13 +24580,23 @@ const LocalazyPubAPIService = ({ strapi: strapi2 }) => ({
24512
24580
  }
24513
24581
  },
24514
24582
  async getProject(projectId, addOrganization = true, addLanguages = true) {
24515
- const projects = await this.listProjects(addOrganization, addLanguages);
24516
- return projects.find((project) => project.id === projectId);
24583
+ try {
24584
+ const projects = await this.listProjects(addOrganization, addLanguages);
24585
+ return projects.find((project) => project.id === projectId) || null;
24586
+ } catch (e3) {
24587
+ strapi2.log.error(e3);
24588
+ return null;
24589
+ }
24517
24590
  },
24518
24591
  async getWebhooksSecret(projectId) {
24519
- const LocalazyApi = await LocalazyApiClientFactory();
24520
- const result = await LocalazyApi.webhooks.getSecret({ project: projectId });
24521
- return result;
24592
+ try {
24593
+ const LocalazyApi = await LocalazyApiClientFactory();
24594
+ const result = await LocalazyApi.webhooks.getSecret({ project: projectId });
24595
+ return result;
24596
+ } catch (e3) {
24597
+ strapi2.log.error(e3);
24598
+ return null;
24599
+ }
24522
24600
  }
24523
24601
  });
24524
24602
  const KEY$1 = "content-transfer-setup";
@@ -25964,11 +26042,10 @@ const StrapiLocalazyI18nService = ({ strapi: strapi2 }) => ({
25964
26042
  uid,
25965
26043
  isoStrapi
25966
26044
  );
25967
- const filteredUpdateEntry = dropPropertyDeep(updateEntry, "documentId");
25968
26045
  const updatedEntry = await StrapiI18nService2.updateLocalizationForAnExistingEntry(
25969
26046
  uid,
25970
26047
  localizedDocumentId,
25971
- filteredUpdateEntry,
26048
+ updateEntry,
25972
26049
  isoStrapi
25973
26050
  );
25974
26051
  return updatedEntry;