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.
Files changed (55) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +206 -0
  3. package/admin/src/components/ConfigTab.jsx +1038 -0
  4. package/admin/src/components/ContentTypesTab.jsx +160 -0
  5. package/admin/src/components/HelpTab.jsx +945 -0
  6. package/admin/src/components/LogsTab.jsx +136 -0
  7. package/admin/src/components/MediaTab.jsx +557 -0
  8. package/admin/src/components/SyncProfilesTab.jsx +715 -0
  9. package/admin/src/components/SyncTab.jsx +988 -0
  10. package/admin/src/index.js +31 -0
  11. package/admin/src/pages/App/index.jsx +129 -0
  12. package/admin/src/pluginId.js +3 -0
  13. package/package.json +84 -0
  14. package/server/src/bootstrap.js +151 -0
  15. package/server/src/config/index.js +5 -0
  16. package/server/src/content-types/index.js +7 -0
  17. package/server/src/content-types/sync-log/schema.json +24 -0
  18. package/server/src/controllers/alerts.js +59 -0
  19. package/server/src/controllers/config.js +292 -0
  20. package/server/src/controllers/content-type-discovery.js +9 -0
  21. package/server/src/controllers/dependencies.js +109 -0
  22. package/server/src/controllers/index.js +29 -0
  23. package/server/src/controllers/ping.js +7 -0
  24. package/server/src/controllers/sync-config.js +26 -0
  25. package/server/src/controllers/sync-enforcement.js +323 -0
  26. package/server/src/controllers/sync-execution.js +134 -0
  27. package/server/src/controllers/sync-log.js +18 -0
  28. package/server/src/controllers/sync-media.js +158 -0
  29. package/server/src/controllers/sync-profiles.js +182 -0
  30. package/server/src/controllers/sync.js +31 -0
  31. package/server/src/destroy.js +7 -0
  32. package/server/src/index.js +21 -0
  33. package/server/src/middlewares/verify-signature.js +32 -0
  34. package/server/src/register.js +7 -0
  35. package/server/src/routes/index.js +111 -0
  36. package/server/src/services/alerts.js +437 -0
  37. package/server/src/services/config.js +68 -0
  38. package/server/src/services/content-type-discovery.js +41 -0
  39. package/server/src/services/dependency-resolver.js +284 -0
  40. package/server/src/services/index.js +30 -0
  41. package/server/src/services/ping.js +7 -0
  42. package/server/src/services/sync-config.js +45 -0
  43. package/server/src/services/sync-enforcement.js +362 -0
  44. package/server/src/services/sync-execution.js +541 -0
  45. package/server/src/services/sync-log.js +56 -0
  46. package/server/src/services/sync-media.js +963 -0
  47. package/server/src/services/sync-profiles.js +380 -0
  48. package/server/src/services/sync.js +248 -0
  49. package/server/src/utils/applier.js +89 -0
  50. package/server/src/utils/comparator.js +83 -0
  51. package/server/src/utils/fetcher.js +142 -0
  52. package/server/src/utils/hmac.js +37 -0
  53. package/server/src/utils/pagination.js +51 -0
  54. package/server/src/utils/sync-guard.js +29 -0
  55. 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;