@localazy/strapi-plugin 0.1.7 → 0.1.8
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/admin/src/modules/@common/components/PluginPageLoader/index.js +22 -0
- package/admin/src/modules/@common/services/product-analytics-service.js +67 -0
- package/admin/src/modules/@common/utils/format-number.js +1 -0
- package/admin/src/pages/App/index.js +1 -1
- package/admin/src/pages/Download/index.js +12 -1
- package/admin/src/pages/Login/index.js +8 -1
- package/admin/src/pages/Settings/index.js +13 -3
- package/admin/src/pages/Upload/index.js +14 -1
- package/admin/src/plugins/analytics-service.js +14 -0
- package/admin/src/utils/createPluginConnectorAxiosInstance.js +45 -0
- package/package.json +4 -4
- package/server/config/index.js +10 -5
- package/server/config/local/index.js +15 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Flex } from '@strapi/design-system/Flex';
|
|
3
|
+
import { Loader } from "@strapi/design-system/Loader";
|
|
4
|
+
import { useTranslation } from "react-i18next";
|
|
5
|
+
|
|
6
|
+
import "../../../../i18n";
|
|
7
|
+
|
|
8
|
+
function PluginPageLoader() {
|
|
9
|
+
const { t } = useTranslation();
|
|
10
|
+
|
|
11
|
+
return (
|
|
12
|
+
<Flex
|
|
13
|
+
marginTop={10}
|
|
14
|
+
alignItems="center"
|
|
15
|
+
justifyContent="center"
|
|
16
|
+
>
|
|
17
|
+
<Loader>{t("common.loading_content")}</Loader>
|
|
18
|
+
</Flex>
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export default PluginPageLoader;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import AnalyticsService from "../../../plugins/analytics-service";
|
|
2
|
+
|
|
3
|
+
export default class ProductAnalyticsService {
|
|
4
|
+
static async trackAppConnected(userId, project, params = {}) {
|
|
5
|
+
try {
|
|
6
|
+
const data = this.buildData(userId, "Strapi Connected", project, params);
|
|
7
|
+
await AnalyticsService.trackEvent(data.event, {
|
|
8
|
+
...data.data,
|
|
9
|
+
userId,
|
|
10
|
+
category: "Project",
|
|
11
|
+
});
|
|
12
|
+
} catch (e) {
|
|
13
|
+
console.warn(e);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static async trackAppDisconnected(userId, project, params = {}) {
|
|
18
|
+
try {
|
|
19
|
+
const data = this.buildData(userId, "Strapi Disconnected", project, params);
|
|
20
|
+
await AnalyticsService.trackEvent(data.event, {
|
|
21
|
+
...data.data,
|
|
22
|
+
userId,
|
|
23
|
+
category: "Project",
|
|
24
|
+
});
|
|
25
|
+
} catch (e) {
|
|
26
|
+
console.warn(e);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static async trackUploadToLocalazy(userId, project, params = {}) {
|
|
31
|
+
try {
|
|
32
|
+
const data = this.buildData(userId, "Strapi Upload", project, params);
|
|
33
|
+
await AnalyticsService.trackEvent(data.event, {
|
|
34
|
+
...data.data,
|
|
35
|
+
userId,
|
|
36
|
+
category: "Project",
|
|
37
|
+
});
|
|
38
|
+
} catch (e) {
|
|
39
|
+
console.warn(e);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static async trackDownloadToStrapi(userId, project, params = {}) {
|
|
44
|
+
try {
|
|
45
|
+
const data = this.buildData(userId, "Strapi Download", project, params);
|
|
46
|
+
await AnalyticsService.trackEvent(data.event, {
|
|
47
|
+
...data.data,
|
|
48
|
+
userId,
|
|
49
|
+
category: "Project",
|
|
50
|
+
});
|
|
51
|
+
} catch (e) {
|
|
52
|
+
console.warn(e);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
static buildData(userId, event, project, params) {
|
|
57
|
+
return {
|
|
58
|
+
event,
|
|
59
|
+
data: {
|
|
60
|
+
"User Id": userId,
|
|
61
|
+
"Project Id": project.id,
|
|
62
|
+
"Project Name": project.name,
|
|
63
|
+
...params,
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default (value, options = undefined) => new Intl.NumberFormat("en-GB", options).format(value);
|
|
@@ -12,8 +12,8 @@ import { ThemeProvider } from "@strapi/design-system/ThemeProvider";
|
|
|
12
12
|
import { lightTheme } from "@strapi/design-system/themes";
|
|
13
13
|
import { Box } from "@strapi/design-system/Box";
|
|
14
14
|
import { Layout } from "@strapi/design-system/Layout";
|
|
15
|
-
import { Loader } from "@strapi/design-system/Loader";
|
|
16
15
|
import { useTranslation } from "react-i18next";
|
|
16
|
+
import Loader from "../../modules/@common/components/PluginPageLoader";
|
|
17
17
|
import pluginId from "../../pluginId";
|
|
18
18
|
import Download from "../Download";
|
|
19
19
|
import Settings from "../Settings";
|
|
@@ -5,11 +5,11 @@ import { Button } from "@strapi/design-system/Button";
|
|
|
5
5
|
import DownloadIcon from "@strapi/icons/Download";
|
|
6
6
|
import { Box } from "@strapi/design-system/Box";
|
|
7
7
|
import { Alert } from "@strapi/design-system/Alert";
|
|
8
|
-
import { Loader } from "@strapi/design-system/Loader";
|
|
9
8
|
import { useTranslation } from "react-i18next";
|
|
10
9
|
import { Flex } from '@strapi/design-system/Flex';
|
|
11
10
|
import { Divider } from '@strapi/design-system/Divider';
|
|
12
11
|
import { Typography } from "@strapi/design-system/Typography";
|
|
12
|
+
import Loader from "../../modules/@common/components/PluginPageLoader";
|
|
13
13
|
import LocalazyDownloadService from "../../modules/localazy-download/services/localazy-download-service";
|
|
14
14
|
import areLocalesCompatible from "../../modules/@common/utils/are-locales-compatible";
|
|
15
15
|
import hasModelChanged from "../../modules/plugin-settings/functions/has-model-changed";
|
|
@@ -17,6 +17,7 @@ import TransferReport from "../../modules/@common/components/TransferReport";
|
|
|
17
17
|
import ReadDocsButton from "../../modules/localazy-upload/components/ReadDocsButton";
|
|
18
18
|
import "../../i18n";
|
|
19
19
|
import { getLocalazyIdentity } from "../../state/localazy-identity";
|
|
20
|
+
import ProductAnalyticsService from "../../modules/@common/services/product-analytics-service";
|
|
20
21
|
|
|
21
22
|
function Download(props) {
|
|
22
23
|
const { t } = useTranslation();
|
|
@@ -44,6 +45,16 @@ function Download(props) {
|
|
|
44
45
|
setIsDownloading(true);
|
|
45
46
|
const result = await LocalazyDownloadService.download();
|
|
46
47
|
setDownloadResult(result);
|
|
48
|
+
|
|
49
|
+
// track download
|
|
50
|
+
ProductAnalyticsService.trackDownloadToStrapi(
|
|
51
|
+
localazyIdentity.user.id,
|
|
52
|
+
localazyIdentity.project,
|
|
53
|
+
{
|
|
54
|
+
"Target Languages Codes": "all",
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
|
|
47
58
|
setIsDownloading(false);
|
|
48
59
|
setshowDownloadFinishedModal(true);
|
|
49
60
|
};
|
|
@@ -6,19 +6,20 @@
|
|
|
6
6
|
|
|
7
7
|
import React from "react";
|
|
8
8
|
import PropTypes from "prop-types";
|
|
9
|
-
import { Loader } from "@strapi/design-system/Loader";
|
|
10
9
|
import { Link } from "@strapi/design-system/Link";
|
|
11
10
|
import { useHistory } from "react-router-dom";
|
|
12
11
|
import { useTranslation } from "react-i18next";
|
|
13
12
|
import { HeaderLayout } from "@strapi/design-system/Layout";
|
|
14
13
|
import { Box } from "@strapi/design-system/Box";
|
|
15
14
|
import { Typography } from "@strapi/design-system/Typography";
|
|
15
|
+
import Loader from "../../modules/@common/components/PluginPageLoader";
|
|
16
16
|
import { setLocalazyIdentity } from "../../state/localazy-identity";
|
|
17
17
|
import LocalazyUserService from "../../modules/user/services/localazy-user-service";
|
|
18
18
|
import LoginButton from "../../modules/login/components/LoginButton";
|
|
19
19
|
import redirectToPluginRoute, {
|
|
20
20
|
PLUGIN_ROUTES,
|
|
21
21
|
} from "../../modules/@common/utils/redirect-to-plugin-route";
|
|
22
|
+
import ProductAnalyticsService from "../../modules/@common/services/product-analytics-service";
|
|
22
23
|
|
|
23
24
|
import "../../i18n";
|
|
24
25
|
|
|
@@ -40,6 +41,12 @@ function Login(props) {
|
|
|
40
41
|
setLocalazyIdentity(result);
|
|
41
42
|
|
|
42
43
|
if (result.accessToken) {
|
|
44
|
+
// track user login
|
|
45
|
+
ProductAnalyticsService.trackAppConnected(
|
|
46
|
+
result.user.id,
|
|
47
|
+
result.project,
|
|
48
|
+
);
|
|
49
|
+
|
|
43
50
|
redirectToPluginRoute(PLUGIN_ROUTES.DOWNLOAD, history);
|
|
44
51
|
}
|
|
45
52
|
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import React, { useEffect, useState } from "react";
|
|
2
2
|
import PropTypes from "prop-types";
|
|
3
|
-
import { Loader } from "@strapi/design-system/Loader";
|
|
4
3
|
import { HeaderLayout } from "@strapi/design-system/Layout";
|
|
5
4
|
import { Box } from "@strapi/design-system/Box";
|
|
6
5
|
import { useHistory } from "react-router-dom";
|
|
7
6
|
import { useTranslation } from "react-i18next";
|
|
8
7
|
import { Grid } from '@strapi/design-system/Grid';
|
|
9
8
|
import { Divider } from '@strapi/design-system/Divider';
|
|
9
|
+
import Loader from "../../modules/@common/components/PluginPageLoader";
|
|
10
10
|
import LogoutButton from "../../modules/login/components/LogoutButton";
|
|
11
11
|
import redirectToPluginRoute, {
|
|
12
12
|
PLUGIN_ROUTES,
|
|
@@ -16,6 +16,8 @@ import OverviewItem from "../../modules/settings/components/OverviewItem";
|
|
|
16
16
|
import OverviewItemLink from "../../modules/settings/components/OverviewItemLink";
|
|
17
17
|
import PrerequisitiesInfo from "../../modules/settings/components/PrerequisitiesInfo";
|
|
18
18
|
import ProjectService from "../../modules/@common/services/project-service";
|
|
19
|
+
import ProductAnalyticsService from "../../modules/@common/services/product-analytics-service";
|
|
20
|
+
import formatNumber from "../../modules/@common/utils/format-number";
|
|
19
21
|
|
|
20
22
|
import "../../i18n";
|
|
21
23
|
|
|
@@ -45,6 +47,12 @@ function Settings(props) {
|
|
|
45
47
|
* On logout action
|
|
46
48
|
*/
|
|
47
49
|
const onLoggedOut = () => {
|
|
50
|
+
// track user logout
|
|
51
|
+
ProductAnalyticsService.trackAppDisconnected(
|
|
52
|
+
localazyIdentity.user.id,
|
|
53
|
+
localazyIdentity.project,
|
|
54
|
+
);
|
|
55
|
+
|
|
48
56
|
redirectToPluginRoute(PLUGIN_ROUTES.LOGIN, history);
|
|
49
57
|
};
|
|
50
58
|
|
|
@@ -56,7 +64,9 @@ function Settings(props) {
|
|
|
56
64
|
primaryAction={<LogoutButton onResultFetched={onLoggedOut} />}
|
|
57
65
|
as="h2"
|
|
58
66
|
/>
|
|
59
|
-
{(props.isLoading || isLoading) && (
|
|
67
|
+
{(props.isLoading || isLoading) && (
|
|
68
|
+
<Loader>{t("common.loading_content")}</Loader>
|
|
69
|
+
)}
|
|
60
70
|
{!(props.isLoading || isLoading) && (
|
|
61
71
|
<Box paddingRight={10} paddingLeft={10}>
|
|
62
72
|
<Box
|
|
@@ -86,7 +96,7 @@ function Settings(props) {
|
|
|
86
96
|
<OverviewItem
|
|
87
97
|
label={t("settings.remaining_organization_keys")}
|
|
88
98
|
value={
|
|
89
|
-
connectedProject.organization.availableKeys - connectedProject.organization.usedKeys
|
|
99
|
+
formatNumber(connectedProject.organization.availableKeys - connectedProject.organization.usedKeys)
|
|
90
100
|
}
|
|
91
101
|
/>
|
|
92
102
|
<OverviewItemLink
|
|
@@ -9,7 +9,7 @@ import { Button } from "@strapi/design-system/Button";
|
|
|
9
9
|
import UploadIcon from "@strapi/icons/Upload";
|
|
10
10
|
import { Box } from "@strapi/design-system/Box";
|
|
11
11
|
import { Alert } from "@strapi/design-system/Alert";
|
|
12
|
-
import
|
|
12
|
+
import Loader from "../../modules/@common/components/PluginPageLoader";
|
|
13
13
|
import LocalazyUploadService from "../../modules/localazy-upload/services/localazy-upload-service";
|
|
14
14
|
import areLocalesCompatible from "../../modules/@common/utils/are-locales-compatible";
|
|
15
15
|
import { getStrapiDefaultLocale, getLocalazySourceLanguage } from "../../modules/@common/utils/get-default-locale";
|
|
@@ -21,6 +21,8 @@ import ReadDocsButton from "../../modules/localazy-upload/components/ReadDocsBut
|
|
|
21
21
|
import redirectToPluginRoute, {
|
|
22
22
|
PLUGIN_ROUTES,
|
|
23
23
|
} from "../../modules/@common/utils/redirect-to-plugin-route";
|
|
24
|
+
import { getLocalazyIdentity } from "../../state/localazy-identity";
|
|
25
|
+
import ProductAnalyticsService from "../../modules/@common/services/product-analytics-service";
|
|
24
26
|
|
|
25
27
|
import "../../i18n";
|
|
26
28
|
|
|
@@ -38,6 +40,7 @@ function Upload(props) {
|
|
|
38
40
|
const [isUploading, setIsUploading] = useState(false);
|
|
39
41
|
const [strapiDefaultLocale, setStrapiDefaultLocale] = useState(null);
|
|
40
42
|
const [localazySourceLanguage, setLocalazySourceLanguage] = useState(null);
|
|
43
|
+
const [localazyIdentity] = getLocalazyIdentity();
|
|
41
44
|
|
|
42
45
|
const onChangeSettingsClick = () => {
|
|
43
46
|
redirectToPluginRoute(PLUGIN_ROUTES.CONTENT_TRANSFER_SETUP);
|
|
@@ -49,6 +52,16 @@ function Upload(props) {
|
|
|
49
52
|
setIsUploading(true);
|
|
50
53
|
const result = await LocalazyUploadService.upload();
|
|
51
54
|
setUploadResult(result);
|
|
55
|
+
|
|
56
|
+
// track upload
|
|
57
|
+
ProductAnalyticsService.trackUploadToLocalazy(
|
|
58
|
+
localazyIdentity.user.id,
|
|
59
|
+
localazyIdentity.project,
|
|
60
|
+
{
|
|
61
|
+
"Source Language Code": localazySourceLanguage.code,
|
|
62
|
+
}
|
|
63
|
+
);
|
|
64
|
+
|
|
52
65
|
setIsUploading(false);
|
|
53
66
|
setShowUploadFinishedModal(true);
|
|
54
67
|
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import createPluginConnectorAxiosInstance from "../utils/createPluginConnectorAxiosInstance";
|
|
2
|
+
|
|
3
|
+
const ANALYTICS_PATH = "/analytics";
|
|
4
|
+
const axiosInstance = createPluginConnectorAxiosInstance();
|
|
5
|
+
export default class AnalyticsService {
|
|
6
|
+
static async trackEvent(event, data) {
|
|
7
|
+
const result = await axiosInstance.post(`${ANALYTICS_PATH}/track`, {
|
|
8
|
+
event,
|
|
9
|
+
...data,
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
return result.data;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* axios with plugin connector config.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import axios from "axios";
|
|
6
|
+
import { config } from "../../../server";
|
|
7
|
+
|
|
8
|
+
const BASE_PLUGIN_PATH = config.default.LOCALAZY_PLUGIN_CONNECTOR_API_URL;
|
|
9
|
+
|
|
10
|
+
const createPluginConnectorAxiosInstance = (baseUrl = null) => {
|
|
11
|
+
if (baseUrl === null) {
|
|
12
|
+
baseUrl = `${BASE_PLUGIN_PATH}`;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const instance = axios.create({
|
|
16
|
+
baseURL: baseUrl,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
instance.interceptors.request.use(
|
|
20
|
+
async (config) => {
|
|
21
|
+
config.headers = {
|
|
22
|
+
Accept: "application/json",
|
|
23
|
+
"Content-Type": "application/json",
|
|
24
|
+
// Strapi plugin id in terms of plugin connector
|
|
25
|
+
"X-Localazy-Plugin-Id": 1,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
return config;
|
|
29
|
+
},
|
|
30
|
+
(error) => {
|
|
31
|
+
Promise.reject(error);
|
|
32
|
+
}
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
instance.interceptors.response.use(
|
|
36
|
+
(response) => response,
|
|
37
|
+
(error) => {
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
return instance;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export default createPluginConnectorAxiosInstance;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@localazy/strapi-plugin",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "The official Strapi Plugin by Localazy.",
|
|
5
5
|
"strapi": {
|
|
6
6
|
"name": "localazy",
|
|
@@ -28,8 +28,6 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@localazy/ts-api": "^1.0.6",
|
|
31
|
-
"@strapi/design-system": "^1.0.0",
|
|
32
|
-
"@strapi/icons": "^1.0.0",
|
|
33
31
|
"deep-keys": "^0.5.0",
|
|
34
32
|
"i18next": "^21.6.13",
|
|
35
33
|
"isomorphic-fetch": "^3.0.0",
|
|
@@ -41,7 +39,9 @@
|
|
|
41
39
|
"styled-components": "^5.3.3"
|
|
42
40
|
},
|
|
43
41
|
"peerDependencies": {
|
|
44
|
-
"@strapi/strapi": "^4.0.0"
|
|
42
|
+
"@strapi/strapi": "^4.0.0",
|
|
43
|
+
"@strapi/design-system": "^1.0.0",
|
|
44
|
+
"@strapi/icons": "^1.0.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@babel/plugin-transform-modules-commonjs": "^7.17.7",
|
package/server/config/index.js
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
// depending on the STRAPI_ADMIN_LOCALAZY_ENV, use the correct config
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
let config = require("./production/index");
|
|
5
|
+
|
|
6
|
+
if (process.env.STRAPI_ADMIN_LOCALAZY_ENV === "local") {
|
|
7
|
+
config = require("./local/index");
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (process.env.STRAPI_ADMIN_LOCALAZY_ENV === "development") {
|
|
11
|
+
config = require("./development/index");
|
|
12
|
+
}
|
|
8
13
|
|
|
9
14
|
module.exports = {
|
|
10
15
|
default: {
|
|
11
16
|
// Default plugin configuration, merged with the user configuration
|
|
12
17
|
...(config || {}),
|
|
13
18
|
},
|
|
14
|
-
validator() {},
|
|
19
|
+
validator() { },
|
|
15
20
|
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
LOCALAZY_OAUTH_URL: "https://testing.localazy.com/oauth/authorize",
|
|
5
|
+
LOCALAZY_OAUTH_APP_CLIENT_ID: "18503917571895066465",
|
|
6
|
+
LOCALAZY_PLUGIN_CONNECTOR_API_URL: "http://localhost:3000",
|
|
7
|
+
LOCALAZY_PUBLIC_API_URL: "https://testing.localazy.com/pubapi",
|
|
8
|
+
LOCALAZY_PLUGIN_ID: "1",
|
|
9
|
+
LOCALAZY_DEFAULT_FILE_NAME: "strapi.json",
|
|
10
|
+
LOCALAZY_DEFAULT_FILE_PATH: "",
|
|
11
|
+
LOCALAZY_DEFAULT_FILE_EXTENSION: "json",
|
|
12
|
+
LOCALAZY_DEFAULT_LOCALE: "en",
|
|
13
|
+
LOCALAZY_API_USER_JWT_COOKIE_NAME: "LOCALAZY-API-USER-JWT",
|
|
14
|
+
LOCALAZY_API_USER_COOKIE_EXPIRATION: 7,
|
|
15
|
+
};
|