@medusajs/cloud 0.0.0-stage → 2.22.6
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/.medusa/server/src/admin/index.js +524 -0
- package/.medusa/server/src/admin/index.mjs +522 -0
- package/.medusa/server/src/api/admin/cloud/announcement-preferences/route.js +29 -0
- package/.medusa/server/src/api/admin/cloud/announcement-preferences/validators.js +12 -0
- package/.medusa/server/src/api/admin/cloud/announcements/route.js +21 -0
- package/.medusa/server/src/api/middlewares.js +42 -0
- package/.medusa/server/src/index.js +4 -0
- package/.medusa/server/src/migration-scripts/create-cloud-rbac-policies.js +30 -0
- package/.medusa/server/src/modules/cloud/__tests__/service.spec.js +275 -0
- package/.medusa/server/src/modules/cloud/index.js +13 -0
- package/.medusa/server/src/modules/cloud/migrations/Migration20261112104234.js +15 -0
- package/.medusa/server/src/modules/cloud/models/cloud-announcement-preference.js +11 -0
- package/.medusa/server/src/modules/cloud/service.js +164 -0
- package/.medusa/server/src/types/index.js +18 -0
- package/.medusa/server/src/types/rbac.js +5 -0
- package/.medusa/server/src/workflows/update-announcement-preferences.js +47 -0
- package/.medusa/server/tailwind.config.js +12 -0
- package/AGENTS.md +78 -0
- package/README.md +39 -2
- package/package.json +110 -4
|
@@ -0,0 +1,522 @@
|
|
|
1
|
+
import { jsxs, Fragment, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { defineWidgetConfig, defineRouteConfig } from "@medusajs/admin-sdk";
|
|
3
|
+
import { ArrowUturnLeft, ArrowUpRightOnBox, XMark, Megaphone, SidebarRight } from "@medusajs/icons";
|
|
4
|
+
import { Drawer, IconButton, Heading, Button, Container, Text, Badge, Label, Switch, toast } from "@medusajs/ui";
|
|
5
|
+
import { useMemo, useState } from "react";
|
|
6
|
+
import { useLocation } from "react-router-dom";
|
|
7
|
+
import DOMPurify from "dompurify";
|
|
8
|
+
import { usePermissions } from "@medusajs/dashboard/hooks";
|
|
9
|
+
import { useQuery, useQueryClient, useMutation } from "@tanstack/react-query";
|
|
10
|
+
import Medusa from "@medusajs/js-sdk";
|
|
11
|
+
DOMPurify.addHook("afterSanitizeAttributes", (node) => {
|
|
12
|
+
if (node.tagName === "A" && node.hasAttribute("href")) {
|
|
13
|
+
node.setAttribute("target", "_blank");
|
|
14
|
+
node.setAttribute("rel", "noopener noreferrer");
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
const sanitizeHtml = (html) => DOMPurify.sanitize(html, { USE_PROFILES: { html: true } });
|
|
18
|
+
const contentClassName = [
|
|
19
|
+
"txt-small text-ui-fg-subtle flex flex-col gap-y-4",
|
|
20
|
+
"[&_h1]:txt-compact-large-plus [&_h2]:txt-compact-medium-plus [&_h3]:txt-compact-small-plus [&_h4]:txt-compact-small-plus",
|
|
21
|
+
"[&_h1]:text-ui-fg-base [&_h2]:text-ui-fg-base [&_h3]:text-ui-fg-base [&_h4]:text-ui-fg-base [&_strong]:text-ui-fg-base [&_b]:text-ui-fg-base",
|
|
22
|
+
"[&_a]:text-ui-fg-interactive [&_a:hover]:text-ui-fg-interactive-hover",
|
|
23
|
+
"[&_ul]:list-disc [&_ol]:list-decimal [&_ul]:pl-5 [&_ol]:pl-5 [&_li+li]:mt-2",
|
|
24
|
+
"[&_blockquote]:border-ui-border-strong [&_blockquote]:border-l-2 [&_blockquote]:pl-3",
|
|
25
|
+
"[&_code]:txt-compact-xsmall [&_code]:bg-ui-bg-subtle [&_code]:rounded [&_code]:px-1 [&_code]:font-mono",
|
|
26
|
+
"[&_pre]:bg-ui-contrast-bg-base [&_pre]:text-ui-contrast-fg-primary [&_pre]:overflow-x-auto [&_pre]:rounded-lg [&_pre]:p-3",
|
|
27
|
+
"[&_pre_code]:bg-transparent [&_pre_code]:p-0",
|
|
28
|
+
"[&_img]:shadow-borders-base [&_img]:max-w-full [&_img]:rounded-lg",
|
|
29
|
+
"[&_hr]:border-ui-border-base"
|
|
30
|
+
].join(" ");
|
|
31
|
+
const AnnouncementDetails = ({
|
|
32
|
+
announcement,
|
|
33
|
+
onBack
|
|
34
|
+
}) => {
|
|
35
|
+
const html = useMemo(
|
|
36
|
+
() => sanitizeHtml(announcement.content ?? ""),
|
|
37
|
+
[announcement.content]
|
|
38
|
+
);
|
|
39
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
40
|
+
/* @__PURE__ */ jsxs(Drawer.Header, { children: [
|
|
41
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2", children: [
|
|
42
|
+
onBack && /* @__PURE__ */ jsx(
|
|
43
|
+
IconButton,
|
|
44
|
+
{
|
|
45
|
+
size: "2xsmall",
|
|
46
|
+
variant: "transparent",
|
|
47
|
+
className: "-ml-1",
|
|
48
|
+
onClick: onBack,
|
|
49
|
+
"aria-label": "Back to all announcements",
|
|
50
|
+
children: /* @__PURE__ */ jsx(ArrowUturnLeft, { className: "text-ui-fg-muted" })
|
|
51
|
+
}
|
|
52
|
+
),
|
|
53
|
+
/* @__PURE__ */ jsx(Drawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { level: "h2", children: announcement.title }) })
|
|
54
|
+
] }),
|
|
55
|
+
/* @__PURE__ */ jsx(Drawer.Description, { className: "sr-only", children: announcement.subtitle ?? announcement.title })
|
|
56
|
+
] }),
|
|
57
|
+
/* @__PURE__ */ jsxs(Drawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto p-6", children: [
|
|
58
|
+
announcement.image_url && /* @__PURE__ */ jsx(
|
|
59
|
+
"img",
|
|
60
|
+
{
|
|
61
|
+
src: announcement.image_url,
|
|
62
|
+
alt: "",
|
|
63
|
+
className: "shadow-borders-base aspect-video w-full rounded-lg object-cover"
|
|
64
|
+
}
|
|
65
|
+
),
|
|
66
|
+
/* @__PURE__ */ jsx(
|
|
67
|
+
"div",
|
|
68
|
+
{
|
|
69
|
+
className: contentClassName,
|
|
70
|
+
dangerouslySetInnerHTML: { __html: html }
|
|
71
|
+
}
|
|
72
|
+
)
|
|
73
|
+
] }),
|
|
74
|
+
/* @__PURE__ */ jsxs(Drawer.Footer, { children: [
|
|
75
|
+
/* @__PURE__ */ jsx(Drawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", children: "Close" }) }),
|
|
76
|
+
announcement.link_url && /* @__PURE__ */ jsx(Button, { size: "small", asChild: true, children: /* @__PURE__ */ jsxs(
|
|
77
|
+
"a",
|
|
78
|
+
{
|
|
79
|
+
href: announcement.link_url,
|
|
80
|
+
target: "_blank",
|
|
81
|
+
rel: "noopener noreferrer",
|
|
82
|
+
children: [
|
|
83
|
+
"Learn more",
|
|
84
|
+
/* @__PURE__ */ jsx(ArrowUpRightOnBox, {})
|
|
85
|
+
]
|
|
86
|
+
}
|
|
87
|
+
) })
|
|
88
|
+
] })
|
|
89
|
+
] });
|
|
90
|
+
};
|
|
91
|
+
const backendUrl = __BACKEND_URL__ ?? "/";
|
|
92
|
+
const authType = __AUTH_TYPE__ ?? "session";
|
|
93
|
+
const jwtTokenStorageKey = __JWT_TOKEN_STORAGE_KEY__ || void 0;
|
|
94
|
+
const sdk = new Medusa({
|
|
95
|
+
baseUrl: backendUrl,
|
|
96
|
+
auth: {
|
|
97
|
+
type: authType,
|
|
98
|
+
jwtTokenStorageKey
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
const cloudAnnouncementsQueryKey = ["cloud", "announcements"];
|
|
102
|
+
const useCloudAnnouncements = () => {
|
|
103
|
+
const { hasPermission } = usePermissions();
|
|
104
|
+
const { data, ...rest } = useQuery({
|
|
105
|
+
queryKey: cloudAnnouncementsQueryKey,
|
|
106
|
+
queryFn: async () => sdk.client.fetch(
|
|
107
|
+
"/admin/cloud/announcements"
|
|
108
|
+
),
|
|
109
|
+
staleTime: 10 * 60 * 1e3,
|
|
110
|
+
refetchOnWindowFocus: false,
|
|
111
|
+
retry: false,
|
|
112
|
+
enabled: hasPermission("cloud_announcement:read")
|
|
113
|
+
});
|
|
114
|
+
return { announcements: data?.announcements ?? [], ...rest };
|
|
115
|
+
};
|
|
116
|
+
const normalizePath = (path) => path.replace(/\/+$/, "") || "/";
|
|
117
|
+
const getAnnouncementForPath = (pathname, announcements, { dismissedIds, since }) => {
|
|
118
|
+
const path = normalizePath(pathname);
|
|
119
|
+
const pending = announcements.filter(
|
|
120
|
+
(announcement) => !dismissedIds.includes(announcement.id) && (!announcement.published_at || Date.parse(announcement.published_at) > Date.parse(since))
|
|
121
|
+
);
|
|
122
|
+
return pending.find(
|
|
123
|
+
(announcement) => announcement.admin_path && normalizePath(announcement.admin_path) === path
|
|
124
|
+
) ?? pending.find((announcement) => !announcement.admin_path);
|
|
125
|
+
};
|
|
126
|
+
const LAST_SEEN_KEY = "medusa_cloud_announcements_last_seen_at";
|
|
127
|
+
const DISMISSED_KEY = "medusa_cloud_dismissed_announcement_ids";
|
|
128
|
+
const SINCE_KEY = "medusa_cloud_announcements_since";
|
|
129
|
+
const read = (key) => {
|
|
130
|
+
try {
|
|
131
|
+
return localStorage.getItem(key);
|
|
132
|
+
} catch {
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
const write = (key, value) => {
|
|
137
|
+
try {
|
|
138
|
+
localStorage.setItem(key, value);
|
|
139
|
+
} catch {
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
const getAnnouncementsSince = () => {
|
|
143
|
+
const stored = read(SINCE_KEY);
|
|
144
|
+
if (stored) {
|
|
145
|
+
return stored;
|
|
146
|
+
}
|
|
147
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
148
|
+
write(SINCE_KEY, now);
|
|
149
|
+
return now;
|
|
150
|
+
};
|
|
151
|
+
const getLastSeenAt = () => read(LAST_SEEN_KEY) ?? getAnnouncementsSince();
|
|
152
|
+
const setLastSeenAt = (value) => write(LAST_SEEN_KEY, value);
|
|
153
|
+
const getDismissedAnnouncementIds = () => {
|
|
154
|
+
try {
|
|
155
|
+
const value = JSON.parse(read(DISMISSED_KEY) ?? "[]");
|
|
156
|
+
return Array.isArray(value) ? value : [];
|
|
157
|
+
} catch {
|
|
158
|
+
return [];
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
const addDismissedAnnouncementId = (id) => write(DISMISSED_KEY, JSON.stringify([...getDismissedAnnouncementIds(), id]));
|
|
162
|
+
const CloudAnnouncementCardWidget = () => {
|
|
163
|
+
const { announcements } = useCloudAnnouncements();
|
|
164
|
+
const { pathname } = useLocation();
|
|
165
|
+
const [dismissedId, setDismissedId] = useState(null);
|
|
166
|
+
const [details, setDetails] = useState(null);
|
|
167
|
+
const announcement = useMemo(
|
|
168
|
+
() => getAnnouncementForPath(pathname, announcements, {
|
|
169
|
+
dismissedIds: getDismissedAnnouncementIds(),
|
|
170
|
+
since: getAnnouncementsSince()
|
|
171
|
+
}),
|
|
172
|
+
[pathname, announcements]
|
|
173
|
+
);
|
|
174
|
+
const dismiss = (announcement2) => {
|
|
175
|
+
addDismissedAnnouncementId(announcement2.id);
|
|
176
|
+
setDismissedId(announcement2.id);
|
|
177
|
+
};
|
|
178
|
+
const viewDetails = (announcement2) => {
|
|
179
|
+
dismiss(announcement2);
|
|
180
|
+
setDetails(announcement2);
|
|
181
|
+
};
|
|
182
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
183
|
+
announcement && announcement.id !== dismissedId && /* @__PURE__ */ jsxs(
|
|
184
|
+
Container,
|
|
185
|
+
{
|
|
186
|
+
role: "status",
|
|
187
|
+
"aria-live": "polite",
|
|
188
|
+
onKeyDown: (event) => event.key === "Escape" && dismiss(announcement),
|
|
189
|
+
className: "animate-in fade-in-0 slide-in-from-bottom-2 overflow-hidden p-0 duration-150",
|
|
190
|
+
children: [
|
|
191
|
+
announcement.image_url && /* @__PURE__ */ jsx(
|
|
192
|
+
"img",
|
|
193
|
+
{
|
|
194
|
+
src: announcement.image_url,
|
|
195
|
+
alt: "",
|
|
196
|
+
className: "h-24 w-full border-b object-cover"
|
|
197
|
+
}
|
|
198
|
+
),
|
|
199
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-1 p-3", children: [
|
|
200
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-start gap-x-2", children: [
|
|
201
|
+
/* @__PURE__ */ jsx(
|
|
202
|
+
Text,
|
|
203
|
+
{
|
|
204
|
+
size: "small",
|
|
205
|
+
leading: "compact",
|
|
206
|
+
weight: "plus",
|
|
207
|
+
className: "line-clamp-2 flex-1",
|
|
208
|
+
children: announcement.title
|
|
209
|
+
}
|
|
210
|
+
),
|
|
211
|
+
/* @__PURE__ */ jsx(
|
|
212
|
+
IconButton,
|
|
213
|
+
{
|
|
214
|
+
size: "2xsmall",
|
|
215
|
+
variant: "transparent",
|
|
216
|
+
className: "text-ui-fg-muted -mr-1 shrink-0",
|
|
217
|
+
onClick: () => dismiss(announcement),
|
|
218
|
+
"aria-label": "Dismiss",
|
|
219
|
+
children: /* @__PURE__ */ jsx(XMark, {})
|
|
220
|
+
}
|
|
221
|
+
)
|
|
222
|
+
] }),
|
|
223
|
+
announcement.subtitle && /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle line-clamp-3", children: announcement.subtitle }),
|
|
224
|
+
/* @__PURE__ */ jsx("div", { className: "mt-2 flex empty:hidden", children: announcement.content ? /* @__PURE__ */ jsx(
|
|
225
|
+
Button,
|
|
226
|
+
{
|
|
227
|
+
size: "small",
|
|
228
|
+
className: "flex-1",
|
|
229
|
+
onClick: () => viewDetails(announcement),
|
|
230
|
+
children: "View details"
|
|
231
|
+
}
|
|
232
|
+
) : announcement.link_url && /* @__PURE__ */ jsx(Button, { size: "small", className: "flex-1", asChild: true, children: /* @__PURE__ */ jsx(
|
|
233
|
+
"a",
|
|
234
|
+
{
|
|
235
|
+
href: announcement.link_url,
|
|
236
|
+
target: "_blank",
|
|
237
|
+
rel: "noopener noreferrer",
|
|
238
|
+
onClick: () => dismiss(announcement),
|
|
239
|
+
children: "Learn more"
|
|
240
|
+
}
|
|
241
|
+
) }) })
|
|
242
|
+
] })
|
|
243
|
+
]
|
|
244
|
+
}
|
|
245
|
+
),
|
|
246
|
+
/* @__PURE__ */ jsx(
|
|
247
|
+
Drawer,
|
|
248
|
+
{
|
|
249
|
+
open: !!details,
|
|
250
|
+
onOpenChange: (open) => !open && setDetails(null),
|
|
251
|
+
children: /* @__PURE__ */ jsx(Drawer.Content, { children: details && /* @__PURE__ */ jsx(AnnouncementDetails, { announcement: details }) })
|
|
252
|
+
}
|
|
253
|
+
)
|
|
254
|
+
] });
|
|
255
|
+
};
|
|
256
|
+
defineWidgetConfig({
|
|
257
|
+
zone: "sidebar.settings.before"
|
|
258
|
+
});
|
|
259
|
+
const publishedAt = (announcement) => announcement.published_at ? Date.parse(announcement.published_at) : 0;
|
|
260
|
+
const formatDate = (value) => value ? new Date(value).toLocaleDateString(void 0, {
|
|
261
|
+
year: "numeric",
|
|
262
|
+
month: "short",
|
|
263
|
+
day: "numeric"
|
|
264
|
+
}) : null;
|
|
265
|
+
const CloudAnnouncementsWidget = () => {
|
|
266
|
+
const { announcements } = useCloudAnnouncements();
|
|
267
|
+
const [open, setOpen] = useState(false);
|
|
268
|
+
const [details, setDetails] = useState(null);
|
|
269
|
+
const [lastSeenAt, setLastSeenAtState] = useState(getLastSeenAt);
|
|
270
|
+
const latest = announcements[0];
|
|
271
|
+
const isUnread = (announcement) => publishedAt(announcement) > (lastSeenAt ? Date.parse(lastSeenAt) : 0);
|
|
272
|
+
const hasUnread = announcements.some(isUnread);
|
|
273
|
+
const markSeen = () => {
|
|
274
|
+
if (latest?.published_at) {
|
|
275
|
+
setLastSeenAt(latest.published_at);
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
const handleOpenChange = (shouldOpen) => {
|
|
279
|
+
setOpen(shouldOpen);
|
|
280
|
+
if (shouldOpen) {
|
|
281
|
+
setDetails(null);
|
|
282
|
+
markSeen();
|
|
283
|
+
} else {
|
|
284
|
+
setLastSeenAtState(getLastSeenAt());
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
return /* @__PURE__ */ jsxs(Drawer, { open, onOpenChange: handleOpenChange, children: [
|
|
288
|
+
!!announcements.length && /* @__PURE__ */ jsx(Drawer.Trigger, { asChild: true, children: /* @__PURE__ */ jsxs(
|
|
289
|
+
IconButton,
|
|
290
|
+
{
|
|
291
|
+
variant: "transparent",
|
|
292
|
+
size: "small",
|
|
293
|
+
className: "text-ui-fg-muted hover:text-ui-fg-subtle relative",
|
|
294
|
+
"aria-label": "What's new in Medusa Cloud",
|
|
295
|
+
children: [
|
|
296
|
+
/* @__PURE__ */ jsx(Megaphone, {}),
|
|
297
|
+
hasUnread && /* @__PURE__ */ jsx("span", { className: "bg-ui-tag-blue-icon absolute right-1 top-1 size-1.5 rounded-full" })
|
|
298
|
+
]
|
|
299
|
+
}
|
|
300
|
+
) }),
|
|
301
|
+
/* @__PURE__ */ jsx(Drawer.Content, { children: details ? /* @__PURE__ */ jsx(
|
|
302
|
+
AnnouncementDetails,
|
|
303
|
+
{
|
|
304
|
+
announcement: details,
|
|
305
|
+
onBack: () => setDetails(null)
|
|
306
|
+
}
|
|
307
|
+
) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
308
|
+
/* @__PURE__ */ jsxs(Drawer.Header, { children: [
|
|
309
|
+
/* @__PURE__ */ jsx(Drawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "What's new" }) }),
|
|
310
|
+
/* @__PURE__ */ jsx(Drawer.Description, { className: "sr-only", children: "The latest announcements from Medusa Cloud" })
|
|
311
|
+
] }),
|
|
312
|
+
/* @__PURE__ */ jsx(Drawer.Body, { className: "overflow-y-auto px-0 py-0", children: announcements.map((announcement) => /* @__PURE__ */ jsx(
|
|
313
|
+
AnnouncementItem,
|
|
314
|
+
{
|
|
315
|
+
announcement,
|
|
316
|
+
unread: isUnread(announcement),
|
|
317
|
+
onViewDetails: () => setDetails(announcement)
|
|
318
|
+
},
|
|
319
|
+
announcement.id
|
|
320
|
+
)) })
|
|
321
|
+
] }) })
|
|
322
|
+
] });
|
|
323
|
+
};
|
|
324
|
+
const AnnouncementItem = ({
|
|
325
|
+
announcement,
|
|
326
|
+
unread,
|
|
327
|
+
onViewDetails
|
|
328
|
+
}) => {
|
|
329
|
+
const date = formatDate(announcement.published_at);
|
|
330
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-3 border-b p-6", children: [
|
|
331
|
+
announcement.image_url && /* @__PURE__ */ jsx(
|
|
332
|
+
"img",
|
|
333
|
+
{
|
|
334
|
+
src: announcement.image_url,
|
|
335
|
+
alt: "",
|
|
336
|
+
className: "aspect-video w-full rounded-md object-cover"
|
|
337
|
+
}
|
|
338
|
+
),
|
|
339
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-1", children: [
|
|
340
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-x-2", children: [
|
|
341
|
+
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", weight: "plus", children: announcement.title }),
|
|
342
|
+
unread && /* @__PURE__ */ jsx(Badge, { size: "2xsmall", color: "blue", children: "New" })
|
|
343
|
+
] }),
|
|
344
|
+
announcement.subtitle && /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: announcement.subtitle })
|
|
345
|
+
] }),
|
|
346
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
|
|
347
|
+
date && /* @__PURE__ */ jsx(Text, { size: "xsmall", className: "text-ui-fg-muted", children: date }),
|
|
348
|
+
announcement.content ? /* @__PURE__ */ jsxs(
|
|
349
|
+
"button",
|
|
350
|
+
{
|
|
351
|
+
type: "button",
|
|
352
|
+
onClick: onViewDetails,
|
|
353
|
+
className: "text-ui-fg-interactive hover:text-ui-fg-interactive-hover txt-compact-small-plus flex items-center gap-x-1",
|
|
354
|
+
children: [
|
|
355
|
+
"View details",
|
|
356
|
+
/* @__PURE__ */ jsx(SidebarRight, {})
|
|
357
|
+
]
|
|
358
|
+
}
|
|
359
|
+
) : announcement.link_url && /* @__PURE__ */ jsxs(
|
|
360
|
+
"a",
|
|
361
|
+
{
|
|
362
|
+
href: announcement.link_url,
|
|
363
|
+
target: "_blank",
|
|
364
|
+
rel: "noopener noreferrer",
|
|
365
|
+
className: "text-ui-fg-interactive hover:text-ui-fg-interactive-hover txt-compact-small-plus flex items-center gap-x-1",
|
|
366
|
+
children: [
|
|
367
|
+
"Learn more",
|
|
368
|
+
/* @__PURE__ */ jsx(ArrowUpRightOnBox, {})
|
|
369
|
+
]
|
|
370
|
+
}
|
|
371
|
+
)
|
|
372
|
+
] })
|
|
373
|
+
] });
|
|
374
|
+
};
|
|
375
|
+
defineWidgetConfig({
|
|
376
|
+
zone: "topbar"
|
|
377
|
+
});
|
|
378
|
+
const cloudAnnouncementPreferencesQueryKey = [
|
|
379
|
+
"cloud",
|
|
380
|
+
"announcement-preferences"
|
|
381
|
+
];
|
|
382
|
+
const useCloudAnnouncementPreferences = () => {
|
|
383
|
+
const { data, ...rest } = useQuery({
|
|
384
|
+
queryKey: cloudAnnouncementPreferencesQueryKey,
|
|
385
|
+
queryFn: async () => sdk.client.fetch(
|
|
386
|
+
"/admin/cloud/announcement-preferences"
|
|
387
|
+
)
|
|
388
|
+
});
|
|
389
|
+
return { preferences: data?.announcement_preferences, ...rest };
|
|
390
|
+
};
|
|
391
|
+
const useUpdateCloudAnnouncementPreferences = () => {
|
|
392
|
+
const queryClient = useQueryClient();
|
|
393
|
+
return useMutation({
|
|
394
|
+
mutationFn: async (body) => sdk.client.fetch(
|
|
395
|
+
"/admin/cloud/announcement-preferences",
|
|
396
|
+
{ method: "POST", body }
|
|
397
|
+
),
|
|
398
|
+
onSuccess: (data) => {
|
|
399
|
+
queryClient.setQueryData(cloudAnnouncementPreferencesQueryKey, data);
|
|
400
|
+
queryClient.invalidateQueries({ queryKey: cloudAnnouncementsQueryKey });
|
|
401
|
+
}
|
|
402
|
+
});
|
|
403
|
+
};
|
|
404
|
+
const categories = [
|
|
405
|
+
{
|
|
406
|
+
id: "security",
|
|
407
|
+
label: "Security updates",
|
|
408
|
+
description: "Security advisories and incidents that affect your app."
|
|
409
|
+
},
|
|
410
|
+
{
|
|
411
|
+
id: "feature",
|
|
412
|
+
label: "Feature announcements",
|
|
413
|
+
description: "New Medusa features and releases."
|
|
414
|
+
},
|
|
415
|
+
{
|
|
416
|
+
id: "cloud",
|
|
417
|
+
label: "Cloud announcements",
|
|
418
|
+
description: "Medusa Cloud features and tips shown on admin pages."
|
|
419
|
+
}
|
|
420
|
+
];
|
|
421
|
+
const AnnouncementSettingsPage = () => {
|
|
422
|
+
const { preferences } = useCloudAnnouncementPreferences();
|
|
423
|
+
const { mutate, isPending } = useUpdateCloudAnnouncementPreferences();
|
|
424
|
+
const { hasPermission } = usePermissions();
|
|
425
|
+
const canUpdate = hasPermission("cloud_announcement:update");
|
|
426
|
+
return /* @__PURE__ */ jsxs(Container, { className: "divide-y p-0", children: [
|
|
427
|
+
/* @__PURE__ */ jsxs("div", { className: "px-6 py-4", children: [
|
|
428
|
+
/* @__PURE__ */ jsx(Heading, { children: "Announcements" }),
|
|
429
|
+
/* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose the announcements your team sees in the admin." })
|
|
430
|
+
] }),
|
|
431
|
+
categories.map(({ id, label, description }) => /* @__PURE__ */ jsxs(
|
|
432
|
+
"div",
|
|
433
|
+
{
|
|
434
|
+
className: "flex items-center justify-between gap-x-4 px-6 py-4",
|
|
435
|
+
children: [
|
|
436
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
437
|
+
/* @__PURE__ */ jsx(Label, { htmlFor: id, size: "small", weight: "plus", children: label }),
|
|
438
|
+
/* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: description })
|
|
439
|
+
] }),
|
|
440
|
+
/* @__PURE__ */ jsx(
|
|
441
|
+
Switch,
|
|
442
|
+
{
|
|
443
|
+
id,
|
|
444
|
+
checked: preferences?.[id] ?? false,
|
|
445
|
+
disabled: !preferences || isPending || !canUpdate,
|
|
446
|
+
onCheckedChange: (checked) => mutate(
|
|
447
|
+
{ [id]: checked },
|
|
448
|
+
{
|
|
449
|
+
onSuccess: () => toast.success(
|
|
450
|
+
`${label} ${checked ? "enabled" : "disabled"}`
|
|
451
|
+
),
|
|
452
|
+
onError: (error) => toast.error(error.message)
|
|
453
|
+
}
|
|
454
|
+
)
|
|
455
|
+
}
|
|
456
|
+
)
|
|
457
|
+
]
|
|
458
|
+
},
|
|
459
|
+
id
|
|
460
|
+
))
|
|
461
|
+
] });
|
|
462
|
+
};
|
|
463
|
+
const config = defineRouteConfig({
|
|
464
|
+
label: "Announcements",
|
|
465
|
+
permissions: ["cloud_announcement:read"]
|
|
466
|
+
});
|
|
467
|
+
const widgetModule = { widgets: [
|
|
468
|
+
{
|
|
469
|
+
Component: CloudAnnouncementCardWidget,
|
|
470
|
+
zone: ["sidebar.settings.before"],
|
|
471
|
+
widgetId: "Widget-4920"
|
|
472
|
+
},
|
|
473
|
+
{
|
|
474
|
+
Component: CloudAnnouncementsWidget,
|
|
475
|
+
zone: ["topbar"],
|
|
476
|
+
widgetId: "Widget-8087"
|
|
477
|
+
}
|
|
478
|
+
] };
|
|
479
|
+
const routeModule = {
|
|
480
|
+
routes: [
|
|
481
|
+
{
|
|
482
|
+
Component: AnnouncementSettingsPage,
|
|
483
|
+
path: "/settings/announcements",
|
|
484
|
+
handle: { label: config.label, translationNs: config.translationNs, permissions: config.permissions }
|
|
485
|
+
}
|
|
486
|
+
]
|
|
487
|
+
};
|
|
488
|
+
const menuItemModule = {
|
|
489
|
+
menuItems: [
|
|
490
|
+
{
|
|
491
|
+
label: config.label,
|
|
492
|
+
icon: void 0,
|
|
493
|
+
path: "/settings/announcements",
|
|
494
|
+
nested: void 0,
|
|
495
|
+
rank: void 0,
|
|
496
|
+
translationNs: void 0,
|
|
497
|
+
permissions: config.permissions
|
|
498
|
+
}
|
|
499
|
+
]
|
|
500
|
+
};
|
|
501
|
+
const formModule = { customFields: {} };
|
|
502
|
+
const displayModule = {
|
|
503
|
+
displays: {}
|
|
504
|
+
};
|
|
505
|
+
const i18nModule = { resources: {} };
|
|
506
|
+
const cellRendererModule = {};
|
|
507
|
+
const layoutModule = { layouts: [] };
|
|
508
|
+
const searchEntityModule = {};
|
|
509
|
+
const plugin = {
|
|
510
|
+
widgetModule,
|
|
511
|
+
routeModule,
|
|
512
|
+
menuItemModule,
|
|
513
|
+
formModule,
|
|
514
|
+
displayModule,
|
|
515
|
+
i18nModule,
|
|
516
|
+
cellRendererModule,
|
|
517
|
+
layoutModule,
|
|
518
|
+
searchEntityModule
|
|
519
|
+
};
|
|
520
|
+
export {
|
|
521
|
+
plugin as default
|
|
522
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.POST = exports.GET = void 0;
|
|
4
|
+
const utils_1 = require("@medusajs/framework/utils");
|
|
5
|
+
const update_announcement_preferences_1 = require("../../../../workflows/update-announcement-preferences");
|
|
6
|
+
const GET = async (req, res) => {
|
|
7
|
+
const query = req.scope.resolve(utils_1.ContainerRegistrationKeys.QUERY);
|
|
8
|
+
const { data: [preferences], } = await query.graph({
|
|
9
|
+
entity: "cloud_announcement_preference",
|
|
10
|
+
fields: ["security", "feature", "cloud"],
|
|
11
|
+
pagination: { take: 1 },
|
|
12
|
+
});
|
|
13
|
+
res.json({
|
|
14
|
+
announcement_preferences: {
|
|
15
|
+
security: preferences?.security ?? true,
|
|
16
|
+
feature: preferences?.feature ?? true,
|
|
17
|
+
cloud: preferences?.cloud ?? true,
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
exports.GET = GET;
|
|
22
|
+
const POST = async (req, res) => {
|
|
23
|
+
const { result } = await (0, update_announcement_preferences_1.updateAnnouncementPreferencesWorkflow)(req.scope).run({
|
|
24
|
+
input: { preferences: req.validatedBody },
|
|
25
|
+
});
|
|
26
|
+
res.json({ announcement_preferences: result });
|
|
27
|
+
};
|
|
28
|
+
exports.POST = POST;
|
|
29
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicm91dGUuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi9zcmMvYXBpL2FkbWluL2Nsb3VkL2Fubm91bmNlbWVudC1wcmVmZXJlbmNlcy9yb3V0ZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFJQSxxREFBcUU7QUFFckUsMkdBQTZHO0FBR3RHLE1BQU0sR0FBRyxHQUFHLEtBQUssRUFDdEIsR0FBK0IsRUFDL0IsR0FBOEQsRUFDOUQsRUFBRTtJQUNGLE1BQU0sS0FBSyxHQUFHLEdBQUcsQ0FBQyxLQUFLLENBQUMsT0FBTyxDQUFDLGlDQUF5QixDQUFDLEtBQUssQ0FBQyxDQUFBO0lBQ2hFLE1BQU0sRUFDSixJQUFJLEVBQUUsQ0FBQyxXQUFXLENBQUMsR0FDcEIsR0FBRyxNQUFNLEtBQUssQ0FBQyxLQUFLLENBQUM7UUFDcEIsTUFBTSxFQUFFLCtCQUErQjtRQUN2QyxNQUFNLEVBQUUsQ0FBQyxVQUFVLEVBQUUsU0FBUyxFQUFFLE9BQU8sQ0FBQztRQUN4QyxVQUFVLEVBQUUsRUFBRSxJQUFJLEVBQUUsQ0FBQyxFQUFFO0tBQ3hCLENBQUMsQ0FBQTtJQUVGLEdBQUcsQ0FBQyxJQUFJLENBQUM7UUFDUCx3QkFBd0IsRUFBRTtZQUN4QixRQUFRLEVBQUUsV0FBVyxFQUFFLFFBQVEsSUFBSSxJQUFJO1lBQ3ZDLE9BQU8sRUFBRSxXQUFXLEVBQUUsT0FBTyxJQUFJLElBQUk7WUFDckMsS0FBSyxFQUFFLFdBQVcsRUFBRSxLQUFLLElBQUksSUFBSTtTQUNsQztLQUNGLENBQUMsQ0FBQTtBQUNKLENBQUMsQ0FBQTtBQXBCWSxRQUFBLEdBQUcsT0FvQmY7QUFFTSxNQUFNLElBQUksR0FBRyxLQUFLLEVBQ3ZCLEdBQTRFLEVBQzVFLEdBQThELEVBQzlELEVBQUU7SUFDRixNQUFNLEVBQUUsTUFBTSxFQUFFLEdBQUcsTUFBTSxJQUFBLHVFQUFxQyxFQUFDLEdBQUcsQ0FBQyxLQUFLLENBQUMsQ0FBQyxHQUFHLENBQzNFO1FBQ0UsS0FBSyxFQUFFLEVBQUUsV0FBVyxFQUFFLEdBQUcsQ0FBQyxhQUFhLEVBQUU7S0FDMUMsQ0FDRixDQUFBO0lBRUQsR0FBRyxDQUFDLElBQUksQ0FBQyxFQUFFLHdCQUF3QixFQUFFLE1BQU0sRUFBRSxDQUFDLENBQUE7QUFDaEQsQ0FBQyxDQUFBO0FBWFksUUFBQSxJQUFJLFFBV2hCIn0=
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AdminUpdateCloudAnnouncementPreferences = void 0;
|
|
4
|
+
const zod_1 = require("@medusajs/framework/zod");
|
|
5
|
+
exports.AdminUpdateCloudAnnouncementPreferences = zod_1.z
|
|
6
|
+
.object({
|
|
7
|
+
security: zod_1.z.boolean().optional(),
|
|
8
|
+
feature: zod_1.z.boolean().optional(),
|
|
9
|
+
cloud: zod_1.z.boolean().optional(),
|
|
10
|
+
})
|
|
11
|
+
.strict();
|
|
12
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidmFsaWRhdG9ycy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uL3NyYy9hcGkvYWRtaW4vY2xvdWQvYW5ub3VuY2VtZW50LXByZWZlcmVuY2VzL3ZhbGlkYXRvcnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBQUEsaURBQTJDO0FBSzlCLFFBQUEsdUNBQXVDLEdBQUcsT0FBQztLQUNyRCxNQUFNLENBQUM7SUFDTixRQUFRLEVBQUUsT0FBQyxDQUFDLE9BQU8sRUFBRSxDQUFDLFFBQVEsRUFBRTtJQUNoQyxPQUFPLEVBQUUsT0FBQyxDQUFDLE9BQU8sRUFBRSxDQUFDLFFBQVEsRUFBRTtJQUMvQixLQUFLLEVBQUUsT0FBQyxDQUFDLE9BQU8sRUFBRSxDQUFDLFFBQVEsRUFBRTtDQUM5QixDQUFDO0tBQ0QsTUFBTSxFQUFFLENBQUEifQ==
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GET = void 0;
|
|
4
|
+
const utils_1 = require("@medusajs/framework/utils");
|
|
5
|
+
const cloud_1 = require("../../../../modules/cloud");
|
|
6
|
+
const GET = async (req, res) => {
|
|
7
|
+
try {
|
|
8
|
+
const announcements = await req.scope
|
|
9
|
+
.resolve(cloud_1.CLOUD_MODULE)
|
|
10
|
+
.listAnnouncements();
|
|
11
|
+
res.json({ announcements });
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
req.scope
|
|
15
|
+
.resolve(utils_1.ContainerRegistrationKeys.LOGGER)
|
|
16
|
+
.warn(`Failed to fetch Medusa Cloud announcements: ${error.message}`);
|
|
17
|
+
res.json({ announcements: [] });
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
exports.GET = GET;
|
|
21
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicm91dGUuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi9zcmMvYXBpL2FkbWluL2Nsb3VkL2Fubm91bmNlbWVudHMvcm91dGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBSUEscURBQXFFO0FBRXJFLHFEQUF3RDtBQUdqRCxNQUFNLEdBQUcsR0FBRyxLQUFLLEVBQ3RCLEdBQStCLEVBQy9CLEdBQXVELEVBQ3ZELEVBQUU7SUFDRixJQUFJLENBQUM7UUFDSCxNQUFNLGFBQWEsR0FBRyxNQUFNLEdBQUcsQ0FBQyxLQUFLO2FBQ2xDLE9BQU8sQ0FBcUIsb0JBQVksQ0FBQzthQUN6QyxpQkFBaUIsRUFBRSxDQUFBO1FBQ3RCLEdBQUcsQ0FBQyxJQUFJLENBQUMsRUFBRSxhQUFhLEVBQUUsQ0FBQyxDQUFBO0lBQzdCLENBQUM7SUFBQyxPQUFPLEtBQUssRUFBRSxDQUFDO1FBQ2YsR0FBRyxDQUFDLEtBQUs7YUFDTixPQUFPLENBQUMsaUNBQXlCLENBQUMsTUFBTSxDQUFDO2FBQ3pDLElBQUksQ0FBQywrQ0FBK0MsS0FBSyxDQUFDLE9BQU8sRUFBRSxDQUFDLENBQUE7UUFFdkUsR0FBRyxDQUFDLElBQUksQ0FBQyxFQUFFLGFBQWEsRUFBRSxFQUFFLEVBQUUsQ0FBQyxDQUFBO0lBQ2pDLENBQUM7QUFDSCxDQUFDLENBQUE7QUFoQlksUUFBQSxHQUFHLE9BZ0JmIn0=
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const framework_1 = require("@medusajs/framework");
|
|
4
|
+
const http_1 = require("@medusajs/framework/http");
|
|
5
|
+
const utils_1 = require("@medusajs/framework/utils");
|
|
6
|
+
const rbac_1 = require("../types/rbac");
|
|
7
|
+
const validators_1 = require("./admin/cloud/announcement-preferences/validators");
|
|
8
|
+
const routes = [
|
|
9
|
+
{
|
|
10
|
+
method: ["GET"],
|
|
11
|
+
matcher: "/admin/cloud/announcements",
|
|
12
|
+
middlewares: [
|
|
13
|
+
(0, http_1.authorize)([
|
|
14
|
+
{ resource: rbac_1.CLOUD_POLICY_RESOURCE, operation: utils_1.PolicyOperation.read },
|
|
15
|
+
]),
|
|
16
|
+
],
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
method: ["GET"],
|
|
20
|
+
matcher: "/admin/cloud/announcement-preferences",
|
|
21
|
+
middlewares: [
|
|
22
|
+
(0, http_1.authorize)([
|
|
23
|
+
{ resource: rbac_1.CLOUD_POLICY_RESOURCE, operation: utils_1.PolicyOperation.read },
|
|
24
|
+
]),
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
method: ["POST"],
|
|
29
|
+
matcher: "/admin/cloud/announcement-preferences",
|
|
30
|
+
middlewares: [
|
|
31
|
+
(0, http_1.authorize)([
|
|
32
|
+
{
|
|
33
|
+
resource: rbac_1.CLOUD_POLICY_RESOURCE,
|
|
34
|
+
operation: utils_1.PolicyOperation.update,
|
|
35
|
+
},
|
|
36
|
+
]),
|
|
37
|
+
(0, http_1.validateAndTransformBody)(validators_1.AdminUpdateCloudAnnouncementPreferences),
|
|
38
|
+
],
|
|
39
|
+
},
|
|
40
|
+
];
|
|
41
|
+
exports.default = (0, framework_1.defineMiddlewares)({ routes });
|
|
42
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWlkZGxld2FyZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9zcmMvYXBpL21pZGRsZXdhcmVzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsbURBQXVEO0FBQ3ZELG1EQUlpQztBQUNqQyxxREFBMkQ7QUFDM0Qsd0NBQXFEO0FBQ3JELGtGQUEyRztBQUUzRyxNQUFNLE1BQU0sR0FBc0I7SUFDaEM7UUFDRSxNQUFNLEVBQUUsQ0FBQyxLQUFLLENBQUM7UUFDZixPQUFPLEVBQUUsNEJBQTRCO1FBQ3JDLFdBQVcsRUFBRTtZQUNYLElBQUEsZ0JBQVMsRUFBQztnQkFDUixFQUFFLFFBQVEsRUFBRSw0QkFBcUIsRUFBRSxTQUFTLEVBQUUsdUJBQWUsQ0FBQyxJQUFJLEVBQUU7YUFDckUsQ0FBQztTQUNIO0tBQ0Y7SUFDRDtRQUNFLE1BQU0sRUFBRSxDQUFDLEtBQUssQ0FBQztRQUNmLE9BQU8sRUFBRSx1Q0FBdUM7UUFDaEQsV0FBVyxFQUFFO1lBQ1gsSUFBQSxnQkFBUyxFQUFDO2dCQUNSLEVBQUUsUUFBUSxFQUFFLDRCQUFxQixFQUFFLFNBQVMsRUFBRSx1QkFBZSxDQUFDLElBQUksRUFBRTthQUNyRSxDQUFDO1NBQ0g7S0FDRjtJQUNEO1FBQ0UsTUFBTSxFQUFFLENBQUMsTUFBTSxDQUFDO1FBQ2hCLE9BQU8sRUFBRSx1Q0FBdUM7UUFDaEQsV0FBVyxFQUFFO1lBQ1gsSUFBQSxnQkFBUyxFQUFDO2dCQUNSO29CQUNFLFFBQVEsRUFBRSw0QkFBcUI7b0JBQy9CLFNBQVMsRUFBRSx1QkFBZSxDQUFDLE1BQU07aUJBQ2xDO2FBQ0YsQ0FBQztZQUNGLElBQUEsK0JBQXdCLEVBQUMsb0RBQXVDLENBQUM7U0FDbEU7S0FDRjtDQUNGLENBQUE7QUFFRCxrQkFBZSxJQUFBLDZCQUFpQixFQUFDLEVBQUUsTUFBTSxFQUFFLENBQUMsQ0FBQSJ9
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// noop, for compiler options
|
|
4
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSw2QkFBNkIifQ==
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = createCloudRbacPolicies;
|
|
4
|
+
const modules_sdk_1 = require("@medusajs/framework/modules-sdk");
|
|
5
|
+
const utils_1 = require("@medusajs/framework/utils");
|
|
6
|
+
const rbac_1 = require("../types/rbac");
|
|
7
|
+
/**
|
|
8
|
+
* Creates the policies guarding the plugin's admin routes, so they can be
|
|
9
|
+
* added to roles. Policies that already exist are left untouched.
|
|
10
|
+
*/
|
|
11
|
+
async function createCloudRbacPolicies({ container }) {
|
|
12
|
+
const logger = container.resolve(utils_1.ContainerRegistrationKeys.LOGGER);
|
|
13
|
+
const rbacModule = container.resolve(utils_1.Modules.RBAC);
|
|
14
|
+
const policies = (0, utils_1.buildPolicies)({
|
|
15
|
+
resource: [rbac_1.CLOUD_POLICY_RESOURCE],
|
|
16
|
+
operation: [utils_1.PolicyOperation.read, utils_1.PolicyOperation.update],
|
|
17
|
+
});
|
|
18
|
+
const existing = await rbacModule.listRbacPolicies({ key: policies.map((policy) => policy.key) }, { select: ["key"] });
|
|
19
|
+
const existingKeys = new Set(existing.map((policy) => policy.key));
|
|
20
|
+
const missing = policies.filter((policy) => !existingKeys.has(policy.key));
|
|
21
|
+
if (!missing.length) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
await rbacModule.createRbacPolicies(missing);
|
|
25
|
+
logger.info(`Created cloud RBAC policies: ${missing.map((p) => p.key).join(", ")}`);
|
|
26
|
+
}
|
|
27
|
+
(0, utils_1.defineFileConfig)({
|
|
28
|
+
isDisabled: () => !modules_sdk_1.MedusaModule.isInstalled(utils_1.Modules.RBAC),
|
|
29
|
+
});
|
|
30
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY3JlYXRlLWNsb3VkLXJiYWMtcG9saWNpZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9zcmMvbWlncmF0aW9uLXNjcmlwdHMvY3JlYXRlLWNsb3VkLXJiYWMtcG9saWNpZXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFlQSwwQ0F3QkM7QUF2Q0QsaUVBQThEO0FBRTlELHFEQU1rQztBQUNsQyx3Q0FBcUQ7QUFFckQ7OztHQUdHO0FBQ1ksS0FBSyxVQUFVLHVCQUF1QixDQUFDLEVBQUUsU0FBUyxFQUFZO0lBQzNFLE1BQU0sTUFBTSxHQUFHLFNBQVMsQ0FBQyxPQUFPLENBQUMsaUNBQXlCLENBQUMsTUFBTSxDQUFDLENBQUE7SUFDbEUsTUFBTSxVQUFVLEdBQUcsU0FBUyxDQUFDLE9BQU8sQ0FBQyxlQUFPLENBQUMsSUFBSSxDQUFDLENBQUE7SUFFbEQsTUFBTSxRQUFRLEdBQUcsSUFBQSxxQkFBYSxFQUFDO1FBQzdCLFFBQVEsRUFBRSxDQUFDLDRCQUFxQixDQUFDO1FBQ2pDLFNBQVMsRUFBRSxDQUFDLHVCQUFlLENBQUMsSUFBSSxFQUFFLHVCQUFlLENBQUMsTUFBTSxDQUFDO0tBQzFELENBQUMsQ0FBQTtJQUNGLE1BQU0sUUFBUSxHQUFHLE1BQU0sVUFBVSxDQUFDLGdCQUFnQixDQUNoRCxFQUFFLEdBQUcsRUFBRSxRQUFRLENBQUMsR0FBRyxDQUFDLENBQUMsTUFBTSxFQUFFLEVBQUUsQ0FBQyxNQUFNLENBQUMsR0FBRyxDQUFDLEVBQUUsRUFDN0MsRUFBRSxNQUFNLEVBQUUsQ0FBQyxLQUFLLENBQUMsRUFBRSxDQUNwQixDQUFBO0lBQ0QsTUFBTSxZQUFZLEdBQUcsSUFBSSxHQUFHLENBQUMsUUFBUSxDQUFDLEdBQUcsQ0FBQyxDQUFDLE1BQU0sRUFBRSxFQUFFLENBQUMsTUFBTSxDQUFDLEdBQUcsQ0FBQyxDQUFDLENBQUE7SUFDbEUsTUFBTSxPQUFPLEdBQUcsUUFBUSxDQUFDLE1BQU0sQ0FBQyxDQUFDLE1BQU0sRUFBRSxFQUFFLENBQUMsQ0FBQyxZQUFZLENBQUMsR0FBRyxDQUFDLE1BQU0sQ0FBQyxHQUFHLENBQUMsQ0FBQyxDQUFBO0lBRTFFLElBQUksQ0FBQyxPQUFPLENBQUMsTUFBTSxFQUFFLENBQUM7UUFDcEIsT0FBTTtJQUNSLENBQUM7SUFFRCxNQUFNLFVBQVUsQ0FBQyxrQkFBa0IsQ0FBQyxPQUFPLENBQUMsQ0FBQTtJQUU1QyxNQUFNLENBQUMsSUFBSSxDQUNULGdDQUFnQyxPQUFPLENBQUMsR0FBRyxDQUFDLENBQUMsQ0FBQyxFQUFFLEVBQUUsQ0FBQyxDQUFDLENBQUMsR0FBRyxDQUFDLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxFQUFFLENBQ3ZFLENBQUE7QUFDSCxDQUFDO0FBRUQsSUFBQSx3QkFBZ0IsRUFBQztJQUNmLFVBQVUsRUFBRSxHQUFHLEVBQUUsQ0FBQyxDQUFDLDBCQUFZLENBQUMsV0FBVyxDQUFDLGVBQU8sQ0FBQyxJQUFJLENBQUM7Q0FDMUQsQ0FBQyxDQUFBIn0=
|