strapi-bulk-publish 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Alexander Vitshas
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,97 @@
1
+ # Strapi Bulk Publish
2
+
3
+ [![npm version](https://img.shields.io/npm/v/strapi-bulk-publish.svg)](https://www.npmjs.com/package/strapi-bulk-publish)
4
+ [![license](https://img.shields.io/npm/l/strapi-bulk-publish.svg)](LICENSE)
5
+
6
+ Strapi 5 plugin to bulk publish content across all locales with a single webhook trigger for frontend rebuild.
7
+
8
+ ## Features
9
+
10
+ - Dedicated admin page listing all draft documents with per-locale status
11
+ - Batch selection and one-click publish across all locales
12
+ - Configurable content type and display field
13
+ - Auto-detection of default locale from Strapi i18n settings
14
+ - Single consolidated webhook call after publishing (no per-locale rebuilds)
15
+ - SSRF protection for webhook URLs
16
+ - Confirmation dialog before bulk actions
17
+ - Custom admin permissions
18
+ - Full i18n support for admin UI
19
+
20
+ ## Compatibility
21
+
22
+ | Strapi | Plugin |
23
+ |--------|--------|
24
+ | 5.x | 1.x |
25
+
26
+ ## Installation
27
+
28
+ ```bash
29
+ npm install strapi-bulk-publish
30
+ ```
31
+
32
+ ## Configuration
33
+
34
+ Add to your `config/plugins.ts` (or `.js`):
35
+
36
+ ```typescript
37
+ export default ({ env }) => ({
38
+ 'bulk-publish': {
39
+ enabled: true,
40
+ config: {
41
+ contentType: 'api::blog-post.blog-post', // required — your content type UID
42
+ titleField: 'title', // optional, default: 'title'
43
+ webhookUrl: '', // optional, can also be set via Settings UI
44
+ },
45
+ },
46
+ });
47
+ ```
48
+
49
+ ### Options
50
+
51
+ | Option | Type | Required | Default | Description |
52
+ |--------|------|----------|---------|-------------|
53
+ | `contentType` | `string` | **yes** | — | Strapi content type UID (e.g. `api::article.article`) |
54
+ | `titleField` | `string` | no | `'title'` | Field name used as the display title in the admin list |
55
+ | `webhookUrl` | `string` | no | `''` | Initial webhook URL; can be changed later in Settings UI |
56
+
57
+ The `webhookUrl` set in config serves as the initial seed value. Once changed through the admin Settings page, the UI value takes precedence.
58
+
59
+ ## Webhook
60
+
61
+ After publishing, a single POST request is sent to the configured webhook URL:
62
+
63
+ ```json
64
+ {
65
+ "event": "bulk-publish",
66
+ "posts": ["documentId1", "documentId2"],
67
+ "publishedAt": "2026-05-08T12:00:00.000Z"
68
+ }
69
+ ```
70
+
71
+ The webhook request has a 10-second timeout. Private/internal URLs (localhost, private IP ranges) are blocked for security.
72
+
73
+ ## Permissions
74
+
75
+ Configure in Settings > Roles:
76
+
77
+ | Action | Purpose |
78
+ |--------|---------|
79
+ | `plugin::bulk-publish.publish` | Access bulk publish page and publish documents |
80
+ | `plugin::bulk-publish.settings` | View and edit webhook URL |
81
+
82
+ ## Prerequisites
83
+
84
+ - **Strapi 5** with the **i18n** plugin enabled
85
+ - At least one content type with **Draft & Publish** and **Internationalization** enabled
86
+
87
+ ## Contributing
88
+
89
+ 1. Fork the repository
90
+ 2. Create your feature branch (`git checkout -b feature/my-feature`)
91
+ 3. Commit your changes (`git commit -am 'Add my feature'`)
92
+ 4. Push to the branch (`git push origin feature/my-feature`)
93
+ 5. Open a Pull Request
94
+
95
+ ## License
96
+
97
+ [MIT](LICENSE)
@@ -0,0 +1,239 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useState, useCallback, useEffect } from "react";
3
+ import { u as useIntl } from "./index-CEh8vkxY.mjs";
4
+ import { Flex, Badge, Main, Box, Typography, Dialog, Button, Loader, Table, Thead, Tr, Th, Checkbox, Tbody, Td } from "@strapi/design-system";
5
+ import { WarningCircle } from "@strapi/icons";
6
+ import { useFetchClient, useNotification, Page } from "@strapi/strapi/admin";
7
+ import { P as PLUGIN_ID, p as pluginPermissions } from "./index-CBDMXg1c.mjs";
8
+ const statusColors = {
9
+ draft: { textColor: "success700", backgroundColor: "success100" },
10
+ published: { textColor: "primary700", backgroundColor: "primary100" },
11
+ missing: { textColor: "warning700", backgroundColor: "warning100" }
12
+ };
13
+ const statusSuffix = {
14
+ draft: "",
15
+ published: " ✓",
16
+ missing: " ✗"
17
+ };
18
+ const LocaleBadges = ({ locales }) => {
19
+ return /* @__PURE__ */ jsx(Flex, { gap: 1, wrap: "wrap", children: locales.map(({ locale, status }) => {
20
+ const colors = statusColors[status];
21
+ return /* @__PURE__ */ jsxs(
22
+ Badge,
23
+ {
24
+ textColor: colors.textColor,
25
+ backgroundColor: colors.backgroundColor,
26
+ size: "S",
27
+ children: [
28
+ locale,
29
+ statusSuffix[status]
30
+ ]
31
+ },
32
+ locale
33
+ );
34
+ }) });
35
+ };
36
+ const HomePage = () => {
37
+ const { formatMessage } = useIntl();
38
+ const { get, post } = useFetchClient();
39
+ const { toggleNotification } = useNotification();
40
+ const [posts, setPosts] = useState([]);
41
+ const [selectedIds, setSelectedIds] = useState(/* @__PURE__ */ new Set());
42
+ const [loading, setLoading] = useState(true);
43
+ const [publishing, setPublishing] = useState(false);
44
+ const fetchPosts = useCallback(async () => {
45
+ try {
46
+ setLoading(true);
47
+ const { data } = await get(`/${PLUGIN_ID}/posts`);
48
+ setPosts(data.data || []);
49
+ } catch {
50
+ toggleNotification({
51
+ type: "danger",
52
+ message: formatMessage({ id: `${PLUGIN_ID}.notification.load.error` })
53
+ });
54
+ } finally {
55
+ setLoading(false);
56
+ }
57
+ }, [get, toggleNotification, formatMessage]);
58
+ useEffect(() => {
59
+ fetchPosts();
60
+ }, [fetchPosts]);
61
+ const handleSelectAll = () => {
62
+ if (selectedIds.size === posts.length) {
63
+ setSelectedIds(/* @__PURE__ */ new Set());
64
+ } else {
65
+ setSelectedIds(new Set(posts.map((p) => p.documentId)));
66
+ }
67
+ };
68
+ const handleSelect = (documentId) => {
69
+ const next = new Set(selectedIds);
70
+ if (next.has(documentId)) {
71
+ next.delete(documentId);
72
+ } else {
73
+ next.add(documentId);
74
+ }
75
+ setSelectedIds(next);
76
+ };
77
+ const handlePublish = async () => {
78
+ if (selectedIds.size === 0) return;
79
+ try {
80
+ setPublishing(true);
81
+ const { data } = await post(`/${PLUGIN_ID}/publish`, {
82
+ documentIds: Array.from(selectedIds)
83
+ });
84
+ const result = data.data;
85
+ const publishedCount = result.published?.length || 0;
86
+ const totalLocales = result.published?.reduce(
87
+ (sum, p) => sum + p.localesPublished.length,
88
+ 0
89
+ ) || 0;
90
+ const errorCount = result.errors?.length || 0;
91
+ let message = formatMessage(
92
+ { id: `${PLUGIN_ID}.notification.publish.success` },
93
+ { count: publishedCount, locales: totalLocales }
94
+ );
95
+ if (result.webhookTriggered) {
96
+ message += " " + formatMessage({ id: `${PLUGIN_ID}.notification.publish.webhook` });
97
+ } else if (result.webhookError) {
98
+ message += " " + formatMessage(
99
+ { id: `${PLUGIN_ID}.notification.publish.webhook-error` },
100
+ { error: result.webhookError }
101
+ );
102
+ }
103
+ if (errorCount > 0) {
104
+ message += " " + formatMessage(
105
+ { id: `${PLUGIN_ID}.notification.publish.errors` },
106
+ { count: errorCount }
107
+ );
108
+ }
109
+ toggleNotification({
110
+ type: errorCount > 0 ? "warning" : "success",
111
+ message
112
+ });
113
+ setSelectedIds(/* @__PURE__ */ new Set());
114
+ await fetchPosts();
115
+ } catch {
116
+ toggleNotification({
117
+ type: "danger",
118
+ message: formatMessage({ id: `${PLUGIN_ID}.notification.publish.error` })
119
+ });
120
+ } finally {
121
+ setPublishing(false);
122
+ }
123
+ };
124
+ const getPostStatus = (locales) => {
125
+ const hasDraft = locales.some((l) => l.status === "draft");
126
+ const hasPublished = locales.some((l) => l.status === "published");
127
+ if (hasDraft && hasPublished) {
128
+ return formatMessage({ id: `${PLUGIN_ID}.status.partial` });
129
+ }
130
+ if (hasDraft) {
131
+ return formatMessage({ id: `${PLUGIN_ID}.status.draft` });
132
+ }
133
+ return formatMessage({ id: `${PLUGIN_ID}.status.published` });
134
+ };
135
+ const getStatusColor = (locales) => {
136
+ const hasDraft = locales.some((l) => l.status === "draft");
137
+ const hasPublished = locales.some((l) => l.status === "published");
138
+ if (hasDraft && hasPublished) return "warning600";
139
+ if (hasDraft) return "danger600";
140
+ return "success600";
141
+ };
142
+ const formatTimeAgo = (dateStr) => {
143
+ const diff = Date.now() - new Date(dateStr).getTime();
144
+ if (diff < 0) return formatMessage({ id: `${PLUGIN_ID}.time.just-now` });
145
+ const minutes = Math.floor(diff / 6e4);
146
+ if (minutes < 1) return formatMessage({ id: `${PLUGIN_ID}.time.just-now` });
147
+ if (minutes < 60) {
148
+ return formatMessage({ id: `${PLUGIN_ID}.time.minutes-ago` }, { count: minutes });
149
+ }
150
+ const hours = Math.floor(minutes / 60);
151
+ if (hours < 24) {
152
+ return formatMessage({ id: `${PLUGIN_ID}.time.hours-ago` }, { count: hours });
153
+ }
154
+ const days = Math.floor(hours / 24);
155
+ return formatMessage({ id: `${PLUGIN_ID}.time.days-ago` }, { count: days });
156
+ };
157
+ return /* @__PURE__ */ jsx(Page.Protect, { permissions: pluginPermissions.publish, children: /* @__PURE__ */ jsxs(Main, { children: [
158
+ /* @__PURE__ */ jsx(Box, { paddingTop: 8, paddingBottom: 4, paddingLeft: 10, paddingRight: 10, children: /* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", alignItems: "center", children: [
159
+ /* @__PURE__ */ jsxs(Box, { children: [
160
+ /* @__PURE__ */ jsx(Typography, { variant: "alpha", tag: "h1", children: formatMessage({ id: `${PLUGIN_ID}.page.title` }) }),
161
+ /* @__PURE__ */ jsx(Typography, { variant: "epsilon", textColor: "neutral600", children: formatMessage({ id: `${PLUGIN_ID}.page.subtitle` }) }),
162
+ /* @__PURE__ */ jsxs(Flex, { gap: 3, paddingTop: 2, children: [
163
+ /* @__PURE__ */ jsxs(Flex, { gap: 1, alignItems: "center", children: [
164
+ /* @__PURE__ */ jsx(Badge, { textColor: "success700", backgroundColor: "success100", size: "S", children: "en" }),
165
+ /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: formatMessage({ id: `${PLUGIN_ID}.legend.draft` }) })
166
+ ] }),
167
+ /* @__PURE__ */ jsxs(Flex, { gap: 1, alignItems: "center", children: [
168
+ /* @__PURE__ */ jsx(Badge, { textColor: "primary700", backgroundColor: "primary100", size: "S", children: "en ✓" }),
169
+ /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: formatMessage({ id: `${PLUGIN_ID}.legend.published` }) })
170
+ ] }),
171
+ /* @__PURE__ */ jsxs(Flex, { gap: 1, alignItems: "center", children: [
172
+ /* @__PURE__ */ jsx(Badge, { textColor: "warning700", backgroundColor: "warning100", size: "S", children: "en ✗" }),
173
+ /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: formatMessage({ id: `${PLUGIN_ID}.legend.missing` }) })
174
+ ] })
175
+ ] })
176
+ ] }),
177
+ /* @__PURE__ */ jsxs(Dialog.Root, { children: [
178
+ /* @__PURE__ */ jsx(Dialog.Trigger, { children: /* @__PURE__ */ jsx(Button, { disabled: selectedIds.size === 0 || publishing, loading: publishing, children: publishing ? formatMessage({ id: `${PLUGIN_ID}.button.publishing` }) : formatMessage(
179
+ { id: `${PLUGIN_ID}.button.publish` },
180
+ { count: selectedIds.size }
181
+ ) }) }),
182
+ /* @__PURE__ */ jsxs(Dialog.Content, { children: [
183
+ /* @__PURE__ */ jsx(Dialog.Header, { children: formatMessage({ id: `${PLUGIN_ID}.confirm.title` }) }),
184
+ /* @__PURE__ */ jsx(Dialog.Body, { icon: /* @__PURE__ */ jsx(WarningCircle, { fill: "danger600" }), children: formatMessage(
185
+ { id: `${PLUGIN_ID}.confirm.body` },
186
+ { count: selectedIds.size }
187
+ ) }),
188
+ /* @__PURE__ */ jsxs(Dialog.Footer, { children: [
189
+ /* @__PURE__ */ jsx(Dialog.Cancel, { children: /* @__PURE__ */ jsx(Button, { variant: "tertiary", children: formatMessage({ id: `${PLUGIN_ID}.button.cancel` }) }) }),
190
+ /* @__PURE__ */ jsx(Dialog.Action, { children: /* @__PURE__ */ jsx(Button, { variant: "danger-light", onClick: handlePublish, loading: publishing, children: formatMessage({ id: `${PLUGIN_ID}.button.confirm` }) }) })
191
+ ] })
192
+ ] })
193
+ ] })
194
+ ] }) }),
195
+ /* @__PURE__ */ jsx(Box, { paddingLeft: 10, paddingRight: 10, paddingBottom: 10, children: loading ? /* @__PURE__ */ jsx(Flex, { justifyContent: "center", paddingTop: 8, children: /* @__PURE__ */ jsx(Loader, { children: formatMessage({ id: `${PLUGIN_ID}.loading.posts` }) }) }) : posts.length === 0 ? /* @__PURE__ */ jsx(Box, { paddingTop: 8, children: /* @__PURE__ */ jsx(Typography, { variant: "delta", textColor: "neutral600", textAlign: "center", children: formatMessage({ id: `${PLUGIN_ID}.empty.message` }) }) }) : /* @__PURE__ */ jsxs(Table, { colCount: 4, rowCount: posts.length + 1, children: [
196
+ /* @__PURE__ */ jsx(Thead, { children: /* @__PURE__ */ jsxs(Tr, { children: [
197
+ /* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(
198
+ Checkbox,
199
+ {
200
+ checked: posts.length > 0 && selectedIds.size === posts.length,
201
+ indeterminate: selectedIds.size > 0 && selectedIds.size < posts.length,
202
+ onCheckedChange: handleSelectAll
203
+ }
204
+ ) }),
205
+ /* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", children: formatMessage({ id: `${PLUGIN_ID}.table.title` }) }) }),
206
+ /* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", children: formatMessage({ id: `${PLUGIN_ID}.table.locales` }) }) }),
207
+ /* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", children: formatMessage({ id: `${PLUGIN_ID}.table.status` }) }) })
208
+ ] }) }),
209
+ /* @__PURE__ */ jsx(Tbody, { children: posts.map((entry) => /* @__PURE__ */ jsxs(Tr, { children: [
210
+ /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(
211
+ Checkbox,
212
+ {
213
+ checked: selectedIds.has(entry.documentId),
214
+ onCheckedChange: () => handleSelect(entry.documentId)
215
+ }
216
+ ) }),
217
+ /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsxs(Box, { children: [
218
+ /* @__PURE__ */ jsx(Typography, { fontWeight: "semiBold", children: entry.title }),
219
+ /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral500", children: formatMessage(
220
+ { id: `${PLUGIN_ID}.table.updated` },
221
+ { time: formatTimeAgo(entry.updatedAt) }
222
+ ) })
223
+ ] }) }),
224
+ /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(LocaleBadges, { locales: entry.locales }) }),
225
+ /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(
226
+ Typography,
227
+ {
228
+ textColor: getStatusColor(entry.locales),
229
+ fontWeight: "semiBold",
230
+ children: getPostStatus(entry.locales)
231
+ }
232
+ ) })
233
+ ] }, entry.documentId)) })
234
+ ] }) })
235
+ ] }) });
236
+ };
237
+ export {
238
+ HomePage
239
+ };
@@ -0,0 +1,239 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const jsxRuntime = require("react/jsx-runtime");
4
+ const React = require("react");
5
+ const index = require("./index-DkTxsEqL.js");
6
+ const designSystem = require("@strapi/design-system");
7
+ const icons = require("@strapi/icons");
8
+ const admin = require("@strapi/strapi/admin");
9
+ const index$1 = require("./index-BBZKQRB2.js");
10
+ const statusColors = {
11
+ draft: { textColor: "success700", backgroundColor: "success100" },
12
+ published: { textColor: "primary700", backgroundColor: "primary100" },
13
+ missing: { textColor: "warning700", backgroundColor: "warning100" }
14
+ };
15
+ const statusSuffix = {
16
+ draft: "",
17
+ published: " ✓",
18
+ missing: " ✗"
19
+ };
20
+ const LocaleBadges = ({ locales }) => {
21
+ return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { gap: 1, wrap: "wrap", children: locales.map(({ locale, status }) => {
22
+ const colors = statusColors[status];
23
+ return /* @__PURE__ */ jsxRuntime.jsxs(
24
+ designSystem.Badge,
25
+ {
26
+ textColor: colors.textColor,
27
+ backgroundColor: colors.backgroundColor,
28
+ size: "S",
29
+ children: [
30
+ locale,
31
+ statusSuffix[status]
32
+ ]
33
+ },
34
+ locale
35
+ );
36
+ }) });
37
+ };
38
+ const HomePage = () => {
39
+ const { formatMessage } = index.useIntl();
40
+ const { get, post } = admin.useFetchClient();
41
+ const { toggleNotification } = admin.useNotification();
42
+ const [posts, setPosts] = React.useState([]);
43
+ const [selectedIds, setSelectedIds] = React.useState(/* @__PURE__ */ new Set());
44
+ const [loading, setLoading] = React.useState(true);
45
+ const [publishing, setPublishing] = React.useState(false);
46
+ const fetchPosts = React.useCallback(async () => {
47
+ try {
48
+ setLoading(true);
49
+ const { data } = await get(`/${index$1.PLUGIN_ID}/posts`);
50
+ setPosts(data.data || []);
51
+ } catch {
52
+ toggleNotification({
53
+ type: "danger",
54
+ message: formatMessage({ id: `${index$1.PLUGIN_ID}.notification.load.error` })
55
+ });
56
+ } finally {
57
+ setLoading(false);
58
+ }
59
+ }, [get, toggleNotification, formatMessage]);
60
+ React.useEffect(() => {
61
+ fetchPosts();
62
+ }, [fetchPosts]);
63
+ const handleSelectAll = () => {
64
+ if (selectedIds.size === posts.length) {
65
+ setSelectedIds(/* @__PURE__ */ new Set());
66
+ } else {
67
+ setSelectedIds(new Set(posts.map((p) => p.documentId)));
68
+ }
69
+ };
70
+ const handleSelect = (documentId) => {
71
+ const next = new Set(selectedIds);
72
+ if (next.has(documentId)) {
73
+ next.delete(documentId);
74
+ } else {
75
+ next.add(documentId);
76
+ }
77
+ setSelectedIds(next);
78
+ };
79
+ const handlePublish = async () => {
80
+ if (selectedIds.size === 0) return;
81
+ try {
82
+ setPublishing(true);
83
+ const { data } = await post(`/${index$1.PLUGIN_ID}/publish`, {
84
+ documentIds: Array.from(selectedIds)
85
+ });
86
+ const result = data.data;
87
+ const publishedCount = result.published?.length || 0;
88
+ const totalLocales = result.published?.reduce(
89
+ (sum, p) => sum + p.localesPublished.length,
90
+ 0
91
+ ) || 0;
92
+ const errorCount = result.errors?.length || 0;
93
+ let message = formatMessage(
94
+ { id: `${index$1.PLUGIN_ID}.notification.publish.success` },
95
+ { count: publishedCount, locales: totalLocales }
96
+ );
97
+ if (result.webhookTriggered) {
98
+ message += " " + formatMessage({ id: `${index$1.PLUGIN_ID}.notification.publish.webhook` });
99
+ } else if (result.webhookError) {
100
+ message += " " + formatMessage(
101
+ { id: `${index$1.PLUGIN_ID}.notification.publish.webhook-error` },
102
+ { error: result.webhookError }
103
+ );
104
+ }
105
+ if (errorCount > 0) {
106
+ message += " " + formatMessage(
107
+ { id: `${index$1.PLUGIN_ID}.notification.publish.errors` },
108
+ { count: errorCount }
109
+ );
110
+ }
111
+ toggleNotification({
112
+ type: errorCount > 0 ? "warning" : "success",
113
+ message
114
+ });
115
+ setSelectedIds(/* @__PURE__ */ new Set());
116
+ await fetchPosts();
117
+ } catch {
118
+ toggleNotification({
119
+ type: "danger",
120
+ message: formatMessage({ id: `${index$1.PLUGIN_ID}.notification.publish.error` })
121
+ });
122
+ } finally {
123
+ setPublishing(false);
124
+ }
125
+ };
126
+ const getPostStatus = (locales) => {
127
+ const hasDraft = locales.some((l) => l.status === "draft");
128
+ const hasPublished = locales.some((l) => l.status === "published");
129
+ if (hasDraft && hasPublished) {
130
+ return formatMessage({ id: `${index$1.PLUGIN_ID}.status.partial` });
131
+ }
132
+ if (hasDraft) {
133
+ return formatMessage({ id: `${index$1.PLUGIN_ID}.status.draft` });
134
+ }
135
+ return formatMessage({ id: `${index$1.PLUGIN_ID}.status.published` });
136
+ };
137
+ const getStatusColor = (locales) => {
138
+ const hasDraft = locales.some((l) => l.status === "draft");
139
+ const hasPublished = locales.some((l) => l.status === "published");
140
+ if (hasDraft && hasPublished) return "warning600";
141
+ if (hasDraft) return "danger600";
142
+ return "success600";
143
+ };
144
+ const formatTimeAgo = (dateStr) => {
145
+ const diff = Date.now() - new Date(dateStr).getTime();
146
+ if (diff < 0) return formatMessage({ id: `${index$1.PLUGIN_ID}.time.just-now` });
147
+ const minutes = Math.floor(diff / 6e4);
148
+ if (minutes < 1) return formatMessage({ id: `${index$1.PLUGIN_ID}.time.just-now` });
149
+ if (minutes < 60) {
150
+ return formatMessage({ id: `${index$1.PLUGIN_ID}.time.minutes-ago` }, { count: minutes });
151
+ }
152
+ const hours = Math.floor(minutes / 60);
153
+ if (hours < 24) {
154
+ return formatMessage({ id: `${index$1.PLUGIN_ID}.time.hours-ago` }, { count: hours });
155
+ }
156
+ const days = Math.floor(hours / 24);
157
+ return formatMessage({ id: `${index$1.PLUGIN_ID}.time.days-ago` }, { count: days });
158
+ };
159
+ return /* @__PURE__ */ jsxRuntime.jsx(admin.Page.Protect, { permissions: index$1.pluginPermissions.publish, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Main, { children: [
160
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 8, paddingBottom: 4, paddingLeft: 10, paddingRight: 10, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", alignItems: "center", children: [
161
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { children: [
162
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "alpha", tag: "h1", children: formatMessage({ id: `${index$1.PLUGIN_ID}.page.title` }) }),
163
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "epsilon", textColor: "neutral600", children: formatMessage({ id: `${index$1.PLUGIN_ID}.page.subtitle` }) }),
164
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 3, paddingTop: 2, children: [
165
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 1, alignItems: "center", children: [
166
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Badge, { textColor: "success700", backgroundColor: "success100", size: "S", children: "en" }),
167
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: formatMessage({ id: `${index$1.PLUGIN_ID}.legend.draft` }) })
168
+ ] }),
169
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 1, alignItems: "center", children: [
170
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Badge, { textColor: "primary700", backgroundColor: "primary100", size: "S", children: "en ✓" }),
171
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: formatMessage({ id: `${index$1.PLUGIN_ID}.legend.published` }) })
172
+ ] }),
173
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 1, alignItems: "center", children: [
174
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Badge, { textColor: "warning700", backgroundColor: "warning100", size: "S", children: "en ✗" }),
175
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: formatMessage({ id: `${index$1.PLUGIN_ID}.legend.missing` }) })
176
+ ] })
177
+ ] })
178
+ ] }),
179
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Dialog.Root, { children: [
180
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Trigger, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { disabled: selectedIds.size === 0 || publishing, loading: publishing, children: publishing ? formatMessage({ id: `${index$1.PLUGIN_ID}.button.publishing` }) : formatMessage(
181
+ { id: `${index$1.PLUGIN_ID}.button.publish` },
182
+ { count: selectedIds.size }
183
+ ) }) }),
184
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Dialog.Content, { children: [
185
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Header, { children: formatMessage({ id: `${index$1.PLUGIN_ID}.confirm.title` }) }),
186
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Body, { icon: /* @__PURE__ */ jsxRuntime.jsx(icons.WarningCircle, { fill: "danger600" }), children: formatMessage(
187
+ { id: `${index$1.PLUGIN_ID}.confirm.body` },
188
+ { count: selectedIds.size }
189
+ ) }),
190
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Dialog.Footer, { children: [
191
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Cancel, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "tertiary", children: formatMessage({ id: `${index$1.PLUGIN_ID}.button.cancel` }) }) }),
192
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Action, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "danger-light", onClick: handlePublish, loading: publishing, children: formatMessage({ id: `${index$1.PLUGIN_ID}.button.confirm` }) }) })
193
+ ] })
194
+ ] })
195
+ ] })
196
+ ] }) }),
197
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingLeft: 10, paddingRight: 10, paddingBottom: 10, children: loading ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { justifyContent: "center", paddingTop: 8, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Loader, { children: formatMessage({ id: `${index$1.PLUGIN_ID}.loading.posts` }) }) }) : posts.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 8, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", textColor: "neutral600", textAlign: "center", children: formatMessage({ id: `${index$1.PLUGIN_ID}.empty.message` }) }) }) : /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Table, { colCount: 4, rowCount: posts.length + 1, children: [
198
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Thead, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Tr, { children: [
199
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { children: /* @__PURE__ */ jsxRuntime.jsx(
200
+ designSystem.Checkbox,
201
+ {
202
+ checked: posts.length > 0 && selectedIds.size === posts.length,
203
+ indeterminate: selectedIds.size > 0 && selectedIds.size < posts.length,
204
+ onCheckedChange: handleSelectAll
205
+ }
206
+ ) }),
207
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", children: formatMessage({ id: `${index$1.PLUGIN_ID}.table.title` }) }) }),
208
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", children: formatMessage({ id: `${index$1.PLUGIN_ID}.table.locales` }) }) }),
209
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", children: formatMessage({ id: `${index$1.PLUGIN_ID}.table.status` }) }) })
210
+ ] }) }),
211
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Tbody, { children: posts.map((entry) => /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Tr, { children: [
212
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsx(
213
+ designSystem.Checkbox,
214
+ {
215
+ checked: selectedIds.has(entry.documentId),
216
+ onCheckedChange: () => handleSelect(entry.documentId)
217
+ }
218
+ ) }),
219
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { children: [
220
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { fontWeight: "semiBold", children: entry.title }),
221
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral500", children: formatMessage(
222
+ { id: `${index$1.PLUGIN_ID}.table.updated` },
223
+ { time: formatTimeAgo(entry.updatedAt) }
224
+ ) })
225
+ ] }) }),
226
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsx(LocaleBadges, { locales: entry.locales }) }),
227
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsx(
228
+ designSystem.Typography,
229
+ {
230
+ textColor: getStatusColor(entry.locales),
231
+ fontWeight: "semiBold",
232
+ children: getPostStatus(entry.locales)
233
+ }
234
+ ) })
235
+ ] }, entry.documentId)) })
236
+ ] }) })
237
+ ] }) });
238
+ };
239
+ exports.HomePage = HomePage;
@@ -0,0 +1,75 @@
1
+ import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
+ import { useState, useCallback, useEffect } from "react";
3
+ import { u as useIntl } from "./index-CEh8vkxY.mjs";
4
+ import { Main, Flex, Loader, Box, Typography, Button, TextInput } from "@strapi/design-system";
5
+ import { useFetchClient, useNotification, Page } from "@strapi/strapi/admin";
6
+ import { P as PLUGIN_ID, p as pluginPermissions } from "./index-CBDMXg1c.mjs";
7
+ const SettingsPage = () => {
8
+ const { formatMessage } = useIntl();
9
+ const { get, put } = useFetchClient();
10
+ const { toggleNotification } = useNotification();
11
+ const [webhookUrl, setWebhookUrl] = useState("");
12
+ const [initialUrl, setInitialUrl] = useState("");
13
+ const [loading, setLoading] = useState(true);
14
+ const [saving, setSaving] = useState(false);
15
+ const fetchSettings = useCallback(async () => {
16
+ try {
17
+ const { data } = await get(`/${PLUGIN_ID}/settings`);
18
+ const url = data.data?.webhookUrl || "";
19
+ setWebhookUrl(url);
20
+ setInitialUrl(url);
21
+ } catch {
22
+ toggleNotification({
23
+ type: "danger",
24
+ message: formatMessage({ id: `${PLUGIN_ID}.notification.settings.error` })
25
+ });
26
+ } finally {
27
+ setLoading(false);
28
+ }
29
+ }, [get, toggleNotification, formatMessage]);
30
+ useEffect(() => {
31
+ fetchSettings();
32
+ }, [fetchSettings]);
33
+ const handleSave = async () => {
34
+ try {
35
+ setSaving(true);
36
+ await put(`/${PLUGIN_ID}/settings`, { webhookUrl });
37
+ setInitialUrl(webhookUrl);
38
+ toggleNotification({
39
+ type: "success",
40
+ message: formatMessage({ id: `${PLUGIN_ID}.notification.settings.success` })
41
+ });
42
+ } catch {
43
+ toggleNotification({
44
+ type: "danger",
45
+ message: formatMessage({ id: `${PLUGIN_ID}.notification.settings.error` })
46
+ });
47
+ } finally {
48
+ setSaving(false);
49
+ }
50
+ };
51
+ const hasChanged = webhookUrl !== initialUrl;
52
+ return /* @__PURE__ */ jsx(Page.Protect, { permissions: pluginPermissions.settings, children: /* @__PURE__ */ jsx(Main, { children: loading ? /* @__PURE__ */ jsx(Flex, { justifyContent: "center", paddingTop: 8, children: /* @__PURE__ */ jsx(Loader, { children: formatMessage({ id: `${PLUGIN_ID}.loading.settings` }) }) }) : /* @__PURE__ */ jsxs(Fragment, { children: [
53
+ /* @__PURE__ */ jsx(Box, { paddingTop: 8, paddingBottom: 4, paddingLeft: 10, paddingRight: 10, children: /* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", alignItems: "center", children: [
54
+ /* @__PURE__ */ jsxs(Box, { children: [
55
+ /* @__PURE__ */ jsx(Typography, { variant: "alpha", tag: "h1", children: formatMessage({ id: `${PLUGIN_ID}.settings.title` }) }),
56
+ /* @__PURE__ */ jsx(Typography, { variant: "epsilon", textColor: "neutral600", children: formatMessage({ id: `${PLUGIN_ID}.settings.subtitle` }) })
57
+ ] }),
58
+ /* @__PURE__ */ jsx(Button, { onClick: handleSave, disabled: !hasChanged || saving, loading: saving, children: formatMessage({ id: `${PLUGIN_ID}.button.save` }) })
59
+ ] }) }),
60
+ /* @__PURE__ */ jsx(Box, { paddingLeft: 10, paddingRight: 10, paddingBottom: 10, children: /* @__PURE__ */ jsx(Box, { background: "neutral0", padding: 6, shadow: "tableShadow", hasRadius: true, children: /* @__PURE__ */ jsx(
61
+ TextInput,
62
+ {
63
+ label: formatMessage({ id: `${PLUGIN_ID}.webhook.label` }),
64
+ placeholder: formatMessage({ id: `${PLUGIN_ID}.webhook.placeholder` }),
65
+ hint: formatMessage({ id: `${PLUGIN_ID}.webhook.hint` }),
66
+ name: "webhookUrl",
67
+ value: webhookUrl,
68
+ onChange: (e) => setWebhookUrl(e.target.value)
69
+ }
70
+ ) }) })
71
+ ] }) }) });
72
+ };
73
+ export {
74
+ SettingsPage
75
+ };