strapi-content-sync-pro 1.0.0
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/LICENSE +21 -0
- package/README.md +206 -0
- package/admin/src/components/ConfigTab.jsx +1038 -0
- package/admin/src/components/ContentTypesTab.jsx +160 -0
- package/admin/src/components/HelpTab.jsx +945 -0
- package/admin/src/components/LogsTab.jsx +136 -0
- package/admin/src/components/MediaTab.jsx +557 -0
- package/admin/src/components/SyncProfilesTab.jsx +715 -0
- package/admin/src/components/SyncTab.jsx +988 -0
- package/admin/src/index.js +31 -0
- package/admin/src/pages/App/index.jsx +129 -0
- package/admin/src/pluginId.js +3 -0
- package/package.json +84 -0
- package/server/src/bootstrap.js +151 -0
- package/server/src/config/index.js +5 -0
- package/server/src/content-types/index.js +7 -0
- package/server/src/content-types/sync-log/schema.json +24 -0
- package/server/src/controllers/alerts.js +59 -0
- package/server/src/controllers/config.js +292 -0
- package/server/src/controllers/content-type-discovery.js +9 -0
- package/server/src/controllers/dependencies.js +109 -0
- package/server/src/controllers/index.js +29 -0
- package/server/src/controllers/ping.js +7 -0
- package/server/src/controllers/sync-config.js +26 -0
- package/server/src/controllers/sync-enforcement.js +323 -0
- package/server/src/controllers/sync-execution.js +134 -0
- package/server/src/controllers/sync-log.js +18 -0
- package/server/src/controllers/sync-media.js +158 -0
- package/server/src/controllers/sync-profiles.js +182 -0
- package/server/src/controllers/sync.js +31 -0
- package/server/src/destroy.js +7 -0
- package/server/src/index.js +21 -0
- package/server/src/middlewares/verify-signature.js +32 -0
- package/server/src/register.js +7 -0
- package/server/src/routes/index.js +111 -0
- package/server/src/services/alerts.js +437 -0
- package/server/src/services/config.js +68 -0
- package/server/src/services/content-type-discovery.js +41 -0
- package/server/src/services/dependency-resolver.js +284 -0
- package/server/src/services/index.js +30 -0
- package/server/src/services/ping.js +7 -0
- package/server/src/services/sync-config.js +45 -0
- package/server/src/services/sync-enforcement.js +362 -0
- package/server/src/services/sync-execution.js +541 -0
- package/server/src/services/sync-log.js +56 -0
- package/server/src/services/sync-media.js +963 -0
- package/server/src/services/sync-profiles.js +380 -0
- package/server/src/services/sync.js +248 -0
- package/server/src/utils/applier.js +89 -0
- package/server/src/utils/comparator.js +83 -0
- package/server/src/utils/fetcher.js +142 -0
- package/server/src/utils/hmac.js +37 -0
- package/server/src/utils/pagination.js +51 -0
- package/server/src/utils/sync-guard.js +29 -0
- package/server/src/utils/sync-id.js +16 -0
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Box,
|
|
4
|
+
Flex,
|
|
5
|
+
Typography,
|
|
6
|
+
Button,
|
|
7
|
+
Alert,
|
|
8
|
+
Switch,
|
|
9
|
+
Badge,
|
|
10
|
+
} from '@strapi/design-system';
|
|
11
|
+
import { useFetchClient } from '@strapi/strapi/admin';
|
|
12
|
+
|
|
13
|
+
const PLUGIN_ID = 'strapi-content-sync-pro';
|
|
14
|
+
|
|
15
|
+
const ContentTypesTab = () => {
|
|
16
|
+
const { get, post } = useFetchClient();
|
|
17
|
+
|
|
18
|
+
const [contentTypes, setContentTypes] = useState([]);
|
|
19
|
+
const [enabledTypes, setEnabledTypes] = useState([]);
|
|
20
|
+
const [profiles, setProfiles] = useState([]);
|
|
21
|
+
const [loading, setLoading] = useState(true);
|
|
22
|
+
const [message, setMessage] = useState(null);
|
|
23
|
+
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
loadData();
|
|
26
|
+
}, []);
|
|
27
|
+
|
|
28
|
+
const loadData = async () => {
|
|
29
|
+
try {
|
|
30
|
+
const [ctRes, scRes, profilesRes] = await Promise.all([
|
|
31
|
+
get(`/${PLUGIN_ID}/content-types`),
|
|
32
|
+
get(`/${PLUGIN_ID}/sync-config`),
|
|
33
|
+
get(`/${PLUGIN_ID}/sync-profiles`),
|
|
34
|
+
]);
|
|
35
|
+
setContentTypes(ctRes.data.data || []);
|
|
36
|
+
const config = scRes.data.data || { contentTypes: [] };
|
|
37
|
+
setEnabledTypes(config.contentTypes?.filter(ct => ct.enabled).map(ct => ct.uid) || []);
|
|
38
|
+
setProfiles(profilesRes.data.data || []);
|
|
39
|
+
} catch (err) {
|
|
40
|
+
console.error('Failed to load data', err);
|
|
41
|
+
setMessage({ type: 'danger', text: err?.response?.data?.error?.message || err.message || 'Failed to load data' });
|
|
42
|
+
} finally {
|
|
43
|
+
setLoading(false);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const isEnabled = (uid) => enabledTypes.includes(uid);
|
|
48
|
+
|
|
49
|
+
const getActiveProfile = (uid) => profiles.find(p => p.contentType === uid && p.isActive);
|
|
50
|
+
|
|
51
|
+
const getProfileCount = (uid) => profiles.filter(p => p.contentType === uid).length;
|
|
52
|
+
|
|
53
|
+
const handleToggle = async (uid) => {
|
|
54
|
+
const wasEnabled = isEnabled(uid);
|
|
55
|
+
const newEnabledTypes = wasEnabled
|
|
56
|
+
? enabledTypes.filter(u => u !== uid)
|
|
57
|
+
: [...enabledTypes, uid];
|
|
58
|
+
|
|
59
|
+
setEnabledTypes(newEnabledTypes);
|
|
60
|
+
|
|
61
|
+
try {
|
|
62
|
+
// Save the config
|
|
63
|
+
const contentTypesConfig = newEnabledTypes.map(u => ({
|
|
64
|
+
uid: u,
|
|
65
|
+
enabled: true,
|
|
66
|
+
}));
|
|
67
|
+
await post(`/${PLUGIN_ID}/sync-config`, { contentTypes: contentTypesConfig });
|
|
68
|
+
|
|
69
|
+
// Auto-generate default profiles if enabling and no profiles exist
|
|
70
|
+
if (!wasEnabled) {
|
|
71
|
+
const existingProfiles = profiles.filter(p => p.contentType === uid);
|
|
72
|
+
if (existingProfiles.length === 0) {
|
|
73
|
+
await post(`/${PLUGIN_ID}/sync-profiles/auto-generate`, { contentType: uid });
|
|
74
|
+
// Reload profiles
|
|
75
|
+
const profilesRes = await get(`/${PLUGIN_ID}/sync-profiles`);
|
|
76
|
+
setProfiles(profilesRes.data.data || []);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
setMessage({
|
|
81
|
+
type: 'success',
|
|
82
|
+
text: wasEnabled
|
|
83
|
+
? `${uid} disabled for sync`
|
|
84
|
+
: `${uid} enabled for sync. Default profiles created.`
|
|
85
|
+
});
|
|
86
|
+
} catch (err) {
|
|
87
|
+
// Revert on error
|
|
88
|
+
setEnabledTypes(enabledTypes);
|
|
89
|
+
setMessage({ type: 'danger', text: err?.response?.data?.error?.message || err.message || 'Failed to update configuration' });
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
if (loading) return <Typography>Loading…</Typography>;
|
|
94
|
+
|
|
95
|
+
return (
|
|
96
|
+
<Box>
|
|
97
|
+
<Typography variant="beta" tag="h2">Content Types</Typography>
|
|
98
|
+
<Box paddingTop={2} paddingBottom={4}>
|
|
99
|
+
<Typography variant="omega" textColor="neutral600">
|
|
100
|
+
Enable content types for synchronization. When enabled, default sync profiles (Full Push, Full Pull, Bidirectional)
|
|
101
|
+
are automatically created. Configure sync behavior in the <strong>Sync Profiles</strong> tab.
|
|
102
|
+
</Typography>
|
|
103
|
+
</Box>
|
|
104
|
+
|
|
105
|
+
{message && (
|
|
106
|
+
<Box paddingBottom={4}>
|
|
107
|
+
<Alert variant={message.type} closeLabel="Close" onClose={() => setMessage(null)}>
|
|
108
|
+
{message.text}
|
|
109
|
+
</Alert>
|
|
110
|
+
</Box>
|
|
111
|
+
)}
|
|
112
|
+
|
|
113
|
+
<Box>
|
|
114
|
+
{contentTypes.map((ct) => {
|
|
115
|
+
const enabled = isEnabled(ct.uid);
|
|
116
|
+
const activeProfile = getActiveProfile(ct.uid);
|
|
117
|
+
const profileCount = getProfileCount(ct.uid);
|
|
118
|
+
|
|
119
|
+
return (
|
|
120
|
+
<Box
|
|
121
|
+
key={ct.uid}
|
|
122
|
+
padding={4}
|
|
123
|
+
background="neutral0"
|
|
124
|
+
shadow="filterShadow"
|
|
125
|
+
marginBottom={3}
|
|
126
|
+
hasRadius
|
|
127
|
+
>
|
|
128
|
+
<Flex justifyContent="space-between" alignItems="center">
|
|
129
|
+
<Box>
|
|
130
|
+
<Flex alignItems="center" gap={2}>
|
|
131
|
+
<Typography variant="delta">{ct.displayName}</Typography>
|
|
132
|
+
{enabled && (
|
|
133
|
+
<Badge active>{profileCount} profile{profileCount !== 1 ? 's' : ''}</Badge>
|
|
134
|
+
)}
|
|
135
|
+
</Flex>
|
|
136
|
+
<Typography variant="pi" textColor="neutral500">{ct.uid}</Typography>
|
|
137
|
+
{enabled && activeProfile && (
|
|
138
|
+
<Box paddingTop={1}>
|
|
139
|
+
<Typography variant="pi" textColor="success600">
|
|
140
|
+
Active: {activeProfile.name}
|
|
141
|
+
</Typography>
|
|
142
|
+
</Box>
|
|
143
|
+
)}
|
|
144
|
+
</Box>
|
|
145
|
+
<Switch
|
|
146
|
+
checked={enabled}
|
|
147
|
+
onCheckedChange={() => handleToggle(ct.uid)}
|
|
148
|
+
visibleLabels
|
|
149
|
+
/>
|
|
150
|
+
</Flex>
|
|
151
|
+
</Box>
|
|
152
|
+
);
|
|
153
|
+
})}
|
|
154
|
+
</Box>
|
|
155
|
+
</Box>
|
|
156
|
+
);
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
export { ContentTypesTab };
|
|
160
|
+
export default ContentTypesTab;
|