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
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Ejaz Husain Arain
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,206 @@
1
+ # Content Sync Pro Plugin for Strapi
2
+
3
+ A powerful Strapi v5 plugin to copy, migrate, and live-sync content, media, and data between multiple Strapi environments.
4
+
5
+ [![npm version](https://badge.fury.io/js/strapi-content-sync-pro.svg)](https://www.npmjs.com/package/strapi-content-sync-pro)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ ## Features
9
+
10
+ - **Bi-directional Content Sync** - Push, pull, or sync both ways (Local wins, Remote wins, or Latest wins).
11
+ - **Media Sync** - Full media synchronization via HTTP (URL-based) or host-level file copy (`rsync`). Includes MIME type filtering and concurrency controls.
12
+ - **Sync Profiles** - Define WHAT to sync with field-level control (Advanced mode) or preset modes.
13
+ - **Execution Modes** - On-demand, Scheduled (interval, timeout, cron, or external scheduler), or Live (real-time) sync.
14
+ - **Pagination & Large Dataset Support** - Built-in pagination ensures stable memory usage even when syncing thousands of records.
15
+ - **Dependency Analytics** - Automatically detects and syncs related entities and components in the correct order.
16
+ - **Enforcement Checks** - Pre-sync schema compatibility validation, version checks, and server time drift checks.
17
+ - **Alerts & Logging** - Detailed sync logs. Receive success/failure alerts via Email (using Strapi's email provider) or Webhooks.
18
+ - **Secure Communication** - API token authentication combined with HMAC-SHA256 request signing using a shared secret.
19
+
20
+ ## Installation
21
+
22
+ - Strapi v5.0.0 or higher
23
+ - Node.js 20.0.0 or higher
24
+
25
+ ## Installation
26
+
27
+ ```bash
28
+ npm install strapi-content-sync-pro
29
+ ```
30
+
31
+ Or with yarn:
32
+
33
+ ```bash
34
+ yarn add strapi-content-sync-pro
35
+ ```
36
+
37
+ ## Configuration
38
+
39
+ ### 1. Enable the plugin
40
+
41
+ Add to your `config/plugins.js` (or `config/plugins.ts`):
42
+
43
+ ```javascript
44
+ module.exports = {
45
+ 'strapi-content-sync-pro': {
46
+ enabled: true,
47
+ },
48
+ };
49
+ ```
50
+
51
+ ### 2. Rebuild Strapi
52
+
53
+ ```bash
54
+ npm run build
55
+ npm run develop
56
+ ```
57
+
58
+ ### 3. Configure via Admin UI
59
+
60
+ 1. Navigate to **Content Sync Pro Plugin** in the admin sidebar
61
+ 2. Go to **Configuration** tab
62
+ 3. Enter your remote server details:
63
+ - **Base URL**: The remote Strapi instance URL (e.g., `https://api.example.com`)
64
+ - **API Token**: Generate from remote Strapi's Settings → API Tokens
65
+ - **Instance ID**: Unique identifier for this instance
66
+ - **Shared Secret**: Same secret on both instances for HMAC signing
67
+
68
+ ## Quick Start
69
+
70
+ ### Step 1: Configure Connection
71
+ In the **Configuration** tab, set up the remote server connection.
72
+
73
+ ### Step 2: Enable Content Types
74
+ In the **Content Types** tab, toggle on the content types you want to sync. Default profiles are auto-generated.
75
+
76
+ ### Step 3: Run Sync
77
+ In the **Sync** tab, click "Sync All Active Profiles" or run individual profiles.
78
+
79
+ ## Sync Profiles
80
+
81
+ Sync Profiles define **what** to sync and **how** conflicts are resolved.
82
+
83
+ ### Simple Mode (Presets)
84
+ - **Full Push** - Push all data to remote, local wins
85
+ - **Full Pull** - Pull all data from remote, remote wins
86
+ - **Bidirectional** - Two-way sync, latest wins
87
+
88
+ ### Advanced Mode
89
+ Configure individual field policies:
90
+ - **Both** - Field syncs both directions
91
+ - **Push** - Field only pushes to remote
92
+ - **Pull** - Field only pulls from remote
93
+ - **Exclude** - Field is never synced
94
+
95
+ ## Execution Modes
96
+
97
+ Configure **when** sync runs in the Sync tab:
98
+
99
+ | Mode | Description |
100
+ |------|-------------|
101
+ | **On Demand** | Manual trigger only |
102
+ | **Scheduled** | Interval, Timeout, Cron expression, or External scheduler |
103
+ | **Live** | Real-time sync on content changes via lifecycle hooks |
104
+
105
+ ### Scheduled Sync Types
106
+
107
+ | Type | Description |
108
+ |------|-------------|
109
+ | **Interval** (`setInterval`) | Fires every N minutes. Simple but can overlap. |
110
+ | **Timeout** (chained `setTimeout`) | Waits for the previous run to finish. No overlap. |
111
+ | **Cron** (wall-clock) | Standard cron expression via `strapi.cron`. Recommended for production. |
112
+ | **External** | No in-process timer. Use system cron, Kubernetes CronJob, GitHub Actions, etc. |
113
+
114
+ ## Media Sync
115
+
116
+ Full media synchronization between Strapi instances:
117
+
118
+ - **URL Strategy** (HTTP) — Works with any upload provider (local, S3, Cloudinary). Downloads and re-uploads via the Upload API.
119
+ - **rsync Strategy** — Host-level file copy using the `rsync` binary. Fastest for local-provider setups with SSH access.
120
+ - **Profile-based** — Create media sync profiles with direction, conflict strategy, MIME filters, filename patterns, and execution settings.
121
+ - **DB + File Sync** — Syncs both the `plugin::upload.file` database rows and the actual file bytes.
122
+
123
+ ## Enforcement
124
+
125
+ Pre-sync validation (Configuration → Enforcement):
126
+
127
+ - **Schema Match** - Verify content type schemas match (strict/compatible/none)
128
+ - **Version Check** - Verify Strapi versions (exact/minor/major/none)
129
+ - **DateTime Sync** - Verify server clocks are synchronized
130
+
131
+ ## Alerts
132
+
133
+ Get notified of sync events (Configuration → Alerts):
134
+
135
+ - **Strapi Logs** - Logs to sync log and server console
136
+ - **Email** - Requires Strapi email plugin configured
137
+ - **Webhook** - POST to any HTTP endpoint
138
+
139
+ ## API Endpoints
140
+
141
+ ### Admin Routes (authenticated)
142
+
143
+ | Method | Path | Description |
144
+ |--------|------|-------------|
145
+ | `GET` | `/strapi-content-sync-pro/config` | Get connection config |
146
+ | `POST` | `/strapi-content-sync-pro/config` | Update connection config |
147
+ | `POST` | `/strapi-content-sync-pro/sync-now` | Trigger manual sync |
148
+ | `GET` | `/strapi-content-sync-pro/sync-profiles` | List sync profiles |
149
+ | `GET` | `/strapi-content-sync-pro/logs` | View sync logs |
150
+
151
+ ### Public Routes (HMAC signed)
152
+
153
+ | Method | Path | Description |
154
+ |--------|------|-------------|
155
+ | `POST` | `/strapi-content-sync-pro/receive` | Receive data from remote |
156
+
157
+ ## Security
158
+
159
+ - **API Tokens**: Use Strapi's built-in API token system
160
+ - **HMAC-SHA256**: All inter-instance requests are signed
161
+ - **Masked Secrets**: Sensitive data is masked in API responses
162
+
163
+ ## Example: E-commerce Sync
164
+
165
+ Sync products from a central catalog to multiple storefronts:
166
+
167
+ 1. **Central Catalog** (source):
168
+ - Create "Full Push" profile for `api::product.product`
169
+ - Set execution mode to "Live"
170
+
171
+ 2. **Storefront** (target):
172
+ - Create "Full Pull" profile for `api::product.product`
173
+ - Set execution mode to "Scheduled" (every 5 minutes)
174
+
175
+ ## Troubleshooting
176
+
177
+ ### Common Issues
178
+
179
+ | Error | Solution |
180
+ |-------|----------|
181
+ | "Remote server not configured" | Add Base URL and API Token in Configuration |
182
+ | "401 Unauthorized" | Regenerate API token on remote server |
183
+ | "HMAC verification failed" | Ensure shared secret matches on both instances |
184
+ | "Schema mismatch" | Sync content type schemas or set enforcement to "compatible" |
185
+
186
+ ### Viewing Logs
187
+
188
+ Check the **Logs** tab for detailed sync history including:
189
+ - Timestamp and duration
190
+ - Content type and record ID
191
+ - Direction (push/pull)
192
+ - Status and error messages
193
+
194
+ ## Contributing
195
+
196
+ Contributions are welcome! Please open an issue or submit a pull request.
197
+
198
+ ## License
199
+
200
+ MIT License - see [LICENSE](LICENSE) for details.
201
+
202
+ ## Author
203
+
204
+ **Ejaz Husain Arain**
205
+ - GitHub: [@eharain](https://github.com/eharain)
206
+ - Email: eharain@yahoo.com