@gatewaze/admin-embed 0.1.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/README.md +42 -0
- package/dist/AiSkillsPicker-dbFhcanE.js +373 -0
- package/dist/ContentAccessPage-D0HRqPFc.js +264 -0
- package/dist/DataTable-fe6yRVpF.js +1984 -0
- package/dist/DetailPageHeader-D_v7924k.js +69 -0
- package/dist/EditionEmail-CyhC8232.js +8382 -0
- package/dist/GuideContent-DBXKCu7r.js +7580 -0
- package/dist/HostMediaTab-BsIBEQ1v.js +440 -0
- package/dist/InboxPage-C8ivCKdx.js +1112 -0
- package/dist/NewsletterCanvasEditor--B06apn3.js +11453 -0
- package/dist/NewsletterSetupWizard-BqV6-fa5.js +347 -0
- package/dist/NewsletterSignup-DRVZIpOs.js +224 -0
- package/dist/Page-D3u8IZ2a.js +14 -0
- package/dist/Toaster-Cde0i6IA.js +18 -0
- package/dist/Tooltip-CqxUlW1d.js +746 -0
- package/dist/_collectionSlug_-B3UN6M-Q.js +308 -0
- package/dist/_collection_-Qz4k_Qjl.js +139 -0
- package/dist/_edition_-DQXwkI_-.js +301 -0
- package/dist/_id_-CtT7rT9f.js +257 -0
- package/dist/_id_-CzScE4Qn.js +1197 -0
- package/dist/_virtual_gatewaze-modules-BeloWlOa.js +991 -0
- package/dist/admin-B0Mmrh_O.js +1239 -0
- package/dist/admin-CcfoK6vD.js +17 -0
- package/dist/admin-embed.js +21844 -0
- package/dist/admin.css +2 -0
- package/dist/block-editor-vXBShAue.js +226 -0
- package/dist/brand-DklYwIeA.js +11 -0
- package/dist/brick-editor-CmBitMMK.js +225 -0
- package/dist/broadcastService-CBqXNt_N.js +190 -0
- package/dist/classnames-uWIYaD6z.js +44 -0
- package/dist/contentAccessService-Cs7tdAo-.js +59 -0
- package/dist/context-jzuubYRz.js +5 -0
- package/dist/createSafeContext-P1pK0sAN.js +17 -0
- package/dist/detail-B8SVFJJr.js +26285 -0
- package/dist/detail-uFBxRbLF.js +2966 -0
- package/dist/dist-DTrOExw8.js +38806 -0
- package/dist/edition-slug-CARO24Bs.js +7 -0
- package/dist/export-edition-html-C_hdXQu5.js +18893 -0
- package/dist/floating-ui.dom-Cyv879E9.js +987 -0
- package/dist/hooks-C377EXJG.js +2974 -0
- package/dist/img/mlops-logo.png +0 -0
- package/dist/img/mlops-logo2.png +0 -0
- package/dist/index.d.ts +105 -0
- package/dist/jsx-runtime-CjozyJt-.js +180 -0
- package/dist/lib-CylJmhlJ.js +828 -0
- package/dist/list-C0cz0aQz.js +451 -0
- package/dist/list-CIVgIGsU.js +166 -0
- package/dist/logo/mlops-alt.png +0 -0
- package/dist/logo/mlops-logo.png +0 -0
- package/dist/new-r4KWpqa6.js +80 -0
- package/dist/outline-DwDYhYcF.js +6538 -0
- package/dist/pages-Ersfxcz7.js +216 -0
- package/dist/preview/12627f.jpg +0 -0
- package/dist/preview/af009d.jpg +0 -0
- package/dist/public-api-LD11kMxh.js +238 -0
- package/dist/react-DB2tPNit.js +933 -0
- package/dist/react-dom-giQNVXng.js +267 -0
- package/dist/registry-4XrV9iNG.js +7 -0
- package/dist/render-BtUWfMUt.js +59634 -0
- package/dist/resolvePeopleByEmail-hivX2l07.js +828 -0
- package/dist/runtime-config.js +10 -0
- package/dist/sends-BkPO6PG2.js +182 -0
- package/dist/server.browser-Pj3QUa7k.js +15227 -0
- package/dist/shim-BCerG8nb.js +6681 -0
- package/dist/sonnerHostBridge-CXuCMM3R.js +665 -0
- package/dist/src-BWDAOzZO.js +799 -0
- package/dist/starter-templates-CFs-QUdF.js +3077 -0
- package/dist/storage-VDSvnkvR.js +39 -0
- package/dist/templateParser-BQ2IsJ6c.js +49 -0
- package/dist/templates-rjQjWsRr.js +253 -0
- package/dist/theme/gatewaze/android-icon-144x144.png +0 -0
- package/dist/theme/gatewaze/android-icon-192x192.png +0 -0
- package/dist/theme/gatewaze/android-icon-36x36.png +0 -0
- package/dist/theme/gatewaze/android-icon-48x48.png +0 -0
- package/dist/theme/gatewaze/android-icon-72x72.png +0 -0
- package/dist/theme/gatewaze/android-icon-96x96.png +0 -0
- package/dist/theme/gatewaze/favicon-144x144.png +0 -0
- package/dist/theme/gatewaze/favicon-16x16.png +0 -0
- package/dist/theme/gatewaze/favicon-192x192.png +0 -0
- package/dist/theme/gatewaze/favicon-32x32.png +0 -0
- package/dist/theme/gatewaze/favicon-96x96.png +0 -0
- package/dist/theme/gatewaze/favicon.ico +0 -0
- package/dist/theme/gatewaze/gatewaze-icon-512.png +0 -0
- package/dist/theme/gatewaze/gatewaze-logo-black.svg +24 -0
- package/dist/theme/gatewaze/gatewaze-logo-white.svg +20 -0
- package/dist/theme/gatewaze/gatewaze-poweredby-black.svg +25 -0
- package/dist/theme/gatewaze/gatewaze-poweredby-white.svg +25 -0
- package/dist/theme/gatewaze/logo_black.svg +24 -0
- package/dist/theme/gatewaze/logo_white.svg +20 -0
- package/dist/theme-D6odw5nx.js +586 -0
- package/dist/ui-DRIo9Krs.js +9747 -0
- package/dist/upload-DMNfZ6FX.js +505 -0
- package/dist/useModuleFeature-DgsFIUpv.js +8 -0
- package/dist/utils-BcVvIjaY.js +36 -0
- package/dist/with-selector-B8eSdVx_.js +100 -0
- package/package.json +33 -0
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { c as e, n as t, t as n } from "./react-DB2tPNit.js";
|
|
2
|
+
import { t as r } from "./jsx-runtime-CjozyJt-.js";
|
|
3
|
+
import { t as i } from "./edition-slug-CARO24Bs.js";
|
|
4
|
+
import { n as a, r as o } from "./brand-DklYwIeA.js";
|
|
5
|
+
import { i as s, n as c, r as l, t as u } from "./NewsletterSignup-DRVZIpOs.js";
|
|
6
|
+
//#region \0stub:/Users/dan/Git/gatewaze/gw-embed-build/packages/admin/src/lib/modules/ModuleSlot
|
|
7
|
+
var d = /* @__PURE__ */ t(((e, t) => {
|
|
8
|
+
t.exports = {};
|
|
9
|
+
})), f = /* @__PURE__ */ e(n()), p = /* @__PURE__ */ e(o()), m = a(), h = d(), g = r(), _ = /* @__PURE__ */ new Set(["onboarding"]);
|
|
10
|
+
function v({ collectionSlug: e }) {
|
|
11
|
+
let t = l(e), n = !1;
|
|
12
|
+
try {
|
|
13
|
+
n = (0, h.hasPortalSlot)("newsletters:signup", _, _);
|
|
14
|
+
} catch {
|
|
15
|
+
n = !1;
|
|
16
|
+
}
|
|
17
|
+
return t.sub?.subscribed ? /* @__PURE__ */ (0, g.jsx)(c, {
|
|
18
|
+
sub: t.sub,
|
|
19
|
+
unsubState: t.unsubState,
|
|
20
|
+
unsubscribe: t.unsubscribe
|
|
21
|
+
}) : t.user && t.sub === void 0 ? null : n ? /* @__PURE__ */ (0, g.jsxs)(g.Fragment, { children: [/* @__PURE__ */ (0, g.jsx)(h.ModuleSlot, {
|
|
22
|
+
name: "newsletters:signup",
|
|
23
|
+
enabledModuleIds: ["onboarding"],
|
|
24
|
+
enabledFeatures: ["onboarding"],
|
|
25
|
+
props: {
|
|
26
|
+
collectionSlug: e,
|
|
27
|
+
onFallbackSubscribe: async (t) => {
|
|
28
|
+
try {
|
|
29
|
+
await (0, m.getSupabaseClient)().functions.invoke("newsletter-signup", { body: {
|
|
30
|
+
email: t,
|
|
31
|
+
collection: e
|
|
32
|
+
} });
|
|
33
|
+
} catch {}
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
fallback: /* @__PURE__ */ (0, g.jsx)(u, {
|
|
37
|
+
collectionSlug: e,
|
|
38
|
+
subscription: t
|
|
39
|
+
})
|
|
40
|
+
}), /* @__PURE__ */ (0, g.jsx)(s, {})] }) : /* @__PURE__ */ (0, g.jsx)(u, {
|
|
41
|
+
collectionSlug: e,
|
|
42
|
+
subscription: t
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
var y = 6;
|
|
46
|
+
function b(e) {
|
|
47
|
+
return new Date(e).toLocaleDateString("en-US", {
|
|
48
|
+
year: "numeric",
|
|
49
|
+
month: "short",
|
|
50
|
+
day: "numeric"
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function x(e) {
|
|
54
|
+
return e.replace(/[-_]+/g, " ").replace(/\b\w/g, (e) => e.toUpperCase());
|
|
55
|
+
}
|
|
56
|
+
function S() {
|
|
57
|
+
let [e, t] = (0, f.useState)([]), [n, r] = (0, f.useState)(!0);
|
|
58
|
+
return (0, f.useEffect)(() => {
|
|
59
|
+
async function e() {
|
|
60
|
+
try {
|
|
61
|
+
let e = (0, m.getSupabaseClient)(), { data: n } = await e.from("newsletters_template_collections").select("id, name, slug, description, accent_color, content_category, require_login").eq("setup_complete", !0).order("name");
|
|
62
|
+
if (!n || n.length === 0) {
|
|
63
|
+
t([]), r(!1);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
let { data: i } = await e.from("newsletters_editions").select("id, title, edition_date, collection_id, preheader").eq("status", "published").order("edition_date", { ascending: !1 }), a = /* @__PURE__ */ new Map();
|
|
67
|
+
for (let e of i || []) {
|
|
68
|
+
let t = a.get(e.collection_id) || [];
|
|
69
|
+
t.push(e), a.set(e.collection_id, t);
|
|
70
|
+
}
|
|
71
|
+
t(n.filter((e) => a.has(e.id)).map((e) => ({
|
|
72
|
+
newsletter: e,
|
|
73
|
+
editions: a.get(e.id) || []
|
|
74
|
+
})));
|
|
75
|
+
} catch (e) {
|
|
76
|
+
console.error("Error loading newsletters:", e);
|
|
77
|
+
} finally {
|
|
78
|
+
r(!1);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
e();
|
|
82
|
+
}, []), n ? /* @__PURE__ */ (0, g.jsxs)("div", {
|
|
83
|
+
className: "pub-wrap",
|
|
84
|
+
children: [/* @__PURE__ */ (0, g.jsx)("div", {
|
|
85
|
+
className: "pub-h",
|
|
86
|
+
children: /* @__PURE__ */ (0, g.jsx)("h1", { children: "Newsletters" })
|
|
87
|
+
}), /* @__PURE__ */ (0, g.jsx)("div", {
|
|
88
|
+
className: "pub-empty",
|
|
89
|
+
children: "Loading…"
|
|
90
|
+
})]
|
|
91
|
+
}) : e.length === 0 ? /* @__PURE__ */ (0, g.jsxs)("div", {
|
|
92
|
+
className: "pub-wrap",
|
|
93
|
+
children: [/* @__PURE__ */ (0, g.jsx)("div", {
|
|
94
|
+
className: "pub-h",
|
|
95
|
+
children: /* @__PURE__ */ (0, g.jsx)("h1", { children: "Newsletters" })
|
|
96
|
+
}), /* @__PURE__ */ (0, g.jsx)("div", {
|
|
97
|
+
className: "pub-empty",
|
|
98
|
+
children: "No newsletters available yet."
|
|
99
|
+
})]
|
|
100
|
+
}) : /* @__PURE__ */ (0, g.jsxs)("div", {
|
|
101
|
+
className: "pub-wrap pub-fade",
|
|
102
|
+
children: [/* @__PURE__ */ (0, g.jsxs)("div", {
|
|
103
|
+
className: "pub-h",
|
|
104
|
+
children: [/* @__PURE__ */ (0, g.jsx)("h1", { children: "Newsletters" }), /* @__PURE__ */ (0, g.jsx)("p", { children: "Subscribe to a newsletter and catch up on recent editions." })]
|
|
105
|
+
}), e.map(({ newsletter: e, editions: t }) => {
|
|
106
|
+
let n = (t) => `/newsletters/${e.slug}/${i(t.edition_date, t.title)}`, r = t[0], a = t.slice(1, y), o = e.accent_color ? { "--nl-accent": e.accent_color } : void 0;
|
|
107
|
+
return /* @__PURE__ */ (0, g.jsx)("section", {
|
|
108
|
+
className: "pub-nl",
|
|
109
|
+
children: /* @__PURE__ */ (0, g.jsxs)("div", {
|
|
110
|
+
className: "pub-nl-card",
|
|
111
|
+
style: o,
|
|
112
|
+
children: [/* @__PURE__ */ (0, g.jsx)("div", {
|
|
113
|
+
className: "pub-nl-top",
|
|
114
|
+
children: /* @__PURE__ */ (0, g.jsxs)("div", {
|
|
115
|
+
className: "pub-nl-id",
|
|
116
|
+
children: [
|
|
117
|
+
/* @__PURE__ */ (0, g.jsxs)("div", {
|
|
118
|
+
className: "pub-nl-titlerow",
|
|
119
|
+
children: [/* @__PURE__ */ (0, g.jsx)("h2", {
|
|
120
|
+
className: "pub-nl-name",
|
|
121
|
+
children: /* @__PURE__ */ (0, g.jsx)(p.default, {
|
|
122
|
+
href: `/newsletters/${e.slug}`,
|
|
123
|
+
style: {
|
|
124
|
+
color: "inherit",
|
|
125
|
+
textDecoration: "none"
|
|
126
|
+
},
|
|
127
|
+
children: e.name
|
|
128
|
+
})
|
|
129
|
+
}), e.content_category && /* @__PURE__ */ (0, g.jsx)("span", {
|
|
130
|
+
className: "pub-nl-badge",
|
|
131
|
+
children: x(e.content_category)
|
|
132
|
+
})]
|
|
133
|
+
}),
|
|
134
|
+
e.description && /* @__PURE__ */ (0, g.jsx)("p", {
|
|
135
|
+
className: "pub-nl-desc",
|
|
136
|
+
children: e.description
|
|
137
|
+
}),
|
|
138
|
+
e.require_login ? /* @__PURE__ */ (0, g.jsx)("p", {
|
|
139
|
+
className: "pub-nl-note",
|
|
140
|
+
children: "Subscribers only — sign in to read."
|
|
141
|
+
}) : /* @__PURE__ */ (0, g.jsxs)("div", {
|
|
142
|
+
className: "pub-nl-sub",
|
|
143
|
+
children: [/* @__PURE__ */ (0, g.jsx)("div", {
|
|
144
|
+
className: "pub-nl-sub-h",
|
|
145
|
+
children: "Get new editions in your inbox"
|
|
146
|
+
}), /* @__PURE__ */ (0, g.jsx)(v, { collectionSlug: e.slug })]
|
|
147
|
+
})
|
|
148
|
+
]
|
|
149
|
+
})
|
|
150
|
+
}), /* @__PURE__ */ (0, g.jsxs)("div", {
|
|
151
|
+
className: "pub-nl-editions",
|
|
152
|
+
children: [
|
|
153
|
+
r && /* @__PURE__ */ (0, g.jsxs)(p.default, {
|
|
154
|
+
href: n(r),
|
|
155
|
+
className: "pub-nl-feature",
|
|
156
|
+
children: [/* @__PURE__ */ (0, g.jsxs)("div", {
|
|
157
|
+
style: { minWidth: 0 },
|
|
158
|
+
children: [
|
|
159
|
+
/* @__PURE__ */ (0, g.jsx)("div", {
|
|
160
|
+
className: "eyebrow",
|
|
161
|
+
children: "Latest edition"
|
|
162
|
+
}),
|
|
163
|
+
/* @__PURE__ */ (0, g.jsx)("div", {
|
|
164
|
+
className: "date",
|
|
165
|
+
children: b(r.edition_date)
|
|
166
|
+
}),
|
|
167
|
+
/* @__PURE__ */ (0, g.jsx)("h3", { children: r.title || "Untitled edition" }),
|
|
168
|
+
r.preheader && /* @__PURE__ */ (0, g.jsx)("p", { children: r.preheader })
|
|
169
|
+
]
|
|
170
|
+
}), /* @__PURE__ */ (0, g.jsx)("span", {
|
|
171
|
+
className: "arrow",
|
|
172
|
+
"aria-hidden": !0,
|
|
173
|
+
children: "→"
|
|
174
|
+
})]
|
|
175
|
+
}),
|
|
176
|
+
a.length > 0 && /* @__PURE__ */ (0, g.jsxs)(g.Fragment, { children: [/* @__PURE__ */ (0, g.jsx)("div", {
|
|
177
|
+
className: "pub-nl-eyebrow",
|
|
178
|
+
children: "Past editions"
|
|
179
|
+
}), /* @__PURE__ */ (0, g.jsx)("ul", {
|
|
180
|
+
className: "pub-nl-rows",
|
|
181
|
+
children: a.map((e) => /* @__PURE__ */ (0, g.jsx)("li", { children: /* @__PURE__ */ (0, g.jsxs)(p.default, {
|
|
182
|
+
href: n(e),
|
|
183
|
+
className: "pub-nl-row",
|
|
184
|
+
children: [/* @__PURE__ */ (0, g.jsx)("span", {
|
|
185
|
+
className: "pub-nl-row-date",
|
|
186
|
+
children: b(e.edition_date)
|
|
187
|
+
}), /* @__PURE__ */ (0, g.jsxs)("span", {
|
|
188
|
+
className: "pub-nl-row-main",
|
|
189
|
+
children: [/* @__PURE__ */ (0, g.jsx)("span", {
|
|
190
|
+
className: "pub-nl-row-title",
|
|
191
|
+
children: e.title || "Untitled edition"
|
|
192
|
+
}), e.preheader && /* @__PURE__ */ (0, g.jsx)("span", {
|
|
193
|
+
className: "pub-nl-row-pre",
|
|
194
|
+
children: e.preheader
|
|
195
|
+
})]
|
|
196
|
+
})]
|
|
197
|
+
}) }, e.id))
|
|
198
|
+
})] }),
|
|
199
|
+
t.length > y && /* @__PURE__ */ (0, g.jsxs)(p.default, {
|
|
200
|
+
href: `/newsletters/${e.slug}`,
|
|
201
|
+
className: "pub-nl-viewall",
|
|
202
|
+
children: [
|
|
203
|
+
"View all ",
|
|
204
|
+
t.length,
|
|
205
|
+
" editions →"
|
|
206
|
+
]
|
|
207
|
+
})
|
|
208
|
+
]
|
|
209
|
+
})]
|
|
210
|
+
})
|
|
211
|
+
}, e.id);
|
|
212
|
+
})]
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
//#endregion
|
|
216
|
+
export { S as default };
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
//#region ../../../gatewaze-modules/modules/newsletters/public-api.ts
|
|
2
|
+
var e = [
|
|
3
|
+
"id",
|
|
4
|
+
"title",
|
|
5
|
+
"edition_date",
|
|
6
|
+
"preheader",
|
|
7
|
+
"content_category",
|
|
8
|
+
"collection_id",
|
|
9
|
+
"created_at",
|
|
10
|
+
"updated_at"
|
|
11
|
+
], t = [
|
|
12
|
+
"id",
|
|
13
|
+
"name",
|
|
14
|
+
"slug",
|
|
15
|
+
"description",
|
|
16
|
+
"accent_color",
|
|
17
|
+
"content_category",
|
|
18
|
+
"from_name",
|
|
19
|
+
"is_default"
|
|
20
|
+
], n = [
|
|
21
|
+
"id",
|
|
22
|
+
"block_type",
|
|
23
|
+
"block_order",
|
|
24
|
+
"content"
|
|
25
|
+
], r = [
|
|
26
|
+
"id",
|
|
27
|
+
"block_id",
|
|
28
|
+
"brick_type",
|
|
29
|
+
"brick_order",
|
|
30
|
+
"content"
|
|
31
|
+
];
|
|
32
|
+
function i(i, a) {
|
|
33
|
+
let o = a.supabase;
|
|
34
|
+
i.get("/", a.requireScope("read"), async (e, n) => {
|
|
35
|
+
try {
|
|
36
|
+
let { limit: r, offset: i } = a.parsePagination(e.query), s = a.parseFields(e.query.fields, [...t], [...t]), c = o.from("newsletters_template_collections").select(s.join(","), { count: "exact" }).order("name", { ascending: !0 }).range(i, i + r - 1);
|
|
37
|
+
if (e.query.content_category) {
|
|
38
|
+
let t = String(e.query.content_category).split(",").map((e) => e.trim()).filter(Boolean);
|
|
39
|
+
c = t.length > 1 ? c.in("content_category", t) : c.eq("content_category", t[0]);
|
|
40
|
+
}
|
|
41
|
+
let { data: l, count: u, error: d } = await c;
|
|
42
|
+
if (d) return n.status(500).json({ error: {
|
|
43
|
+
code: "QUERY_ERROR",
|
|
44
|
+
message: d.message
|
|
45
|
+
} });
|
|
46
|
+
a.setCache(n, {
|
|
47
|
+
kind: "public",
|
|
48
|
+
maxAge: 300,
|
|
49
|
+
sMaxAge: 600
|
|
50
|
+
});
|
|
51
|
+
let f = i + r < (u || 0);
|
|
52
|
+
n.json({
|
|
53
|
+
data: l,
|
|
54
|
+
pagination: {
|
|
55
|
+
total: u,
|
|
56
|
+
limit: r,
|
|
57
|
+
offset: i,
|
|
58
|
+
has_more: f
|
|
59
|
+
},
|
|
60
|
+
_links: {
|
|
61
|
+
self: e.originalUrl,
|
|
62
|
+
...f ? { next: `${e.baseUrl}?offset=${i + r}&limit=${r}` } : {}
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
} catch (e) {
|
|
66
|
+
if (e.code === "VALIDATION_ERROR") return n.status(400).json({ error: e });
|
|
67
|
+
console.error("[newsletters] public-api list error:", e), n.status(500).json({ error: {
|
|
68
|
+
code: "INTERNAL",
|
|
69
|
+
message: "Internal server error"
|
|
70
|
+
} });
|
|
71
|
+
}
|
|
72
|
+
}), i.get("/:slug", a.requireScope("read"), async (e, n) => {
|
|
73
|
+
try {
|
|
74
|
+
let r = a.parseFields(e.query.fields, [...t], [...t]), { data: i, error: s } = await o.from("newsletters_template_collections").select(r.join(",")).eq("slug", e.params.slug).single();
|
|
75
|
+
if (s || !i) return n.status(404).json({ error: {
|
|
76
|
+
code: "NOT_FOUND",
|
|
77
|
+
message: "Newsletter not found"
|
|
78
|
+
} });
|
|
79
|
+
a.setCache(n, {
|
|
80
|
+
kind: "public",
|
|
81
|
+
maxAge: 300,
|
|
82
|
+
sMaxAge: 600
|
|
83
|
+
}), n.json({
|
|
84
|
+
data: i,
|
|
85
|
+
_links: {
|
|
86
|
+
self: e.originalUrl,
|
|
87
|
+
editions: `${e.baseUrl}/${e.params.slug}/editions`
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
} catch (e) {
|
|
91
|
+
console.error("[newsletters] public-api get error:", e), n.status(500).json({ error: {
|
|
92
|
+
code: "INTERNAL",
|
|
93
|
+
message: "Internal server error"
|
|
94
|
+
} });
|
|
95
|
+
}
|
|
96
|
+
}), i.get("/:slug/editions", a.requireScope("read"), async (t, n) => {
|
|
97
|
+
try {
|
|
98
|
+
let { limit: r, offset: i } = a.parsePagination(t.query), s = a.parseFields(t.query.fields, [...e], [...e]), { data: c, error: l } = await o.from("newsletters_template_collections").select("id").eq("slug", t.params.slug).single();
|
|
99
|
+
if (l || !c) return n.status(404).json({ error: {
|
|
100
|
+
code: "NOT_FOUND",
|
|
101
|
+
message: "Newsletter not found"
|
|
102
|
+
} });
|
|
103
|
+
let u = o.from("newsletters_editions").select(s.join(","), { count: "exact" }).eq("collection_id", c.id).eq("status", "published").order("edition_date", { ascending: !1 }).range(i, i + r - 1);
|
|
104
|
+
if (t.query.from && (u = u.gte("edition_date", t.query.from)), t.query.to && (u = u.lte("edition_date", t.query.to)), t.query.content_category) {
|
|
105
|
+
let e = String(t.query.content_category).split(",").map((e) => e.trim()).filter(Boolean);
|
|
106
|
+
u = e.length > 1 ? u.in("content_category", e) : u.eq("content_category", e[0]);
|
|
107
|
+
}
|
|
108
|
+
let { data: d, count: f, error: p } = await u;
|
|
109
|
+
if (p) return n.status(500).json({ error: {
|
|
110
|
+
code: "QUERY_ERROR",
|
|
111
|
+
message: p.message
|
|
112
|
+
} });
|
|
113
|
+
a.setCache(n, {
|
|
114
|
+
kind: "public",
|
|
115
|
+
maxAge: 60,
|
|
116
|
+
sMaxAge: 300
|
|
117
|
+
});
|
|
118
|
+
let m = i + r < (f || 0);
|
|
119
|
+
n.json({
|
|
120
|
+
data: d,
|
|
121
|
+
pagination: {
|
|
122
|
+
total: f,
|
|
123
|
+
limit: r,
|
|
124
|
+
offset: i,
|
|
125
|
+
has_more: m
|
|
126
|
+
},
|
|
127
|
+
_links: {
|
|
128
|
+
self: t.originalUrl,
|
|
129
|
+
...m ? { next: `${t.baseUrl}/${t.params.slug}/editions?offset=${i + r}&limit=${r}` } : {}
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
} catch (e) {
|
|
133
|
+
if (e.code === "VALIDATION_ERROR") return n.status(400).json({ error: e });
|
|
134
|
+
console.error("[newsletters] public-api editions list error:", e), n.status(500).json({ error: {
|
|
135
|
+
code: "INTERNAL",
|
|
136
|
+
message: "Internal server error"
|
|
137
|
+
} });
|
|
138
|
+
}
|
|
139
|
+
}), i.get("/editions/:id", a.requireScope("read"), async (t, n) => {
|
|
140
|
+
try {
|
|
141
|
+
let r = a.parseFields(t.query.fields, [...e], [...e]), { data: i, error: s } = await o.from("newsletters_editions").select(r.join(",")).eq("id", t.params.id).eq("status", "published").single();
|
|
142
|
+
if (s || !i) return n.status(404).json({ error: {
|
|
143
|
+
code: "NOT_FOUND",
|
|
144
|
+
message: "Edition not found"
|
|
145
|
+
} });
|
|
146
|
+
let { data: c } = await o.rpc("content_access_visible", {
|
|
147
|
+
p_content_type: "newsletter_edition",
|
|
148
|
+
p_entity_id: t.params.id,
|
|
149
|
+
p_published_at: i.edition_date ?? null
|
|
150
|
+
});
|
|
151
|
+
if (c === !1) return n.status(404).json({ error: {
|
|
152
|
+
code: "NOT_FOUND",
|
|
153
|
+
message: "Edition not found"
|
|
154
|
+
} });
|
|
155
|
+
a.setCache(n, {
|
|
156
|
+
kind: "public",
|
|
157
|
+
maxAge: 60,
|
|
158
|
+
sMaxAge: 600
|
|
159
|
+
}), n.json({
|
|
160
|
+
data: i,
|
|
161
|
+
_links: {
|
|
162
|
+
self: t.originalUrl,
|
|
163
|
+
content: `${t.baseUrl}/editions/${t.params.id}/content`
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
} catch (e) {
|
|
167
|
+
console.error("[newsletters] public-api edition get error:", e), n.status(500).json({ error: {
|
|
168
|
+
code: "INTERNAL",
|
|
169
|
+
message: "Internal server error"
|
|
170
|
+
} });
|
|
171
|
+
}
|
|
172
|
+
}), i.get("/editions/:id/content", a.requireScope("read"), async (e, t) => {
|
|
173
|
+
try {
|
|
174
|
+
let { data: i, error: s } = await o.from("newsletters_editions").select("id, status, title, edition_date, content_category").eq("id", e.params.id).eq("status", "published").single();
|
|
175
|
+
if (s || !i) return t.status(404).json({ error: {
|
|
176
|
+
code: "NOT_FOUND",
|
|
177
|
+
message: "Edition not found"
|
|
178
|
+
} });
|
|
179
|
+
let { data: c } = await o.rpc("content_access_visible", {
|
|
180
|
+
p_content_type: "newsletter_edition",
|
|
181
|
+
p_entity_id: i.id,
|
|
182
|
+
p_published_at: i.edition_date ?? null
|
|
183
|
+
});
|
|
184
|
+
if (c === !1) return t.status(404).json({ error: {
|
|
185
|
+
code: "NOT_FOUND",
|
|
186
|
+
message: "Edition not found"
|
|
187
|
+
} });
|
|
188
|
+
let { data: l, error: u } = await o.from("newsletters_edition_blocks").select(n.join(",")).eq("edition_id", i.id).order("block_order", { ascending: !0 });
|
|
189
|
+
if (u) return t.status(500).json({ error: {
|
|
190
|
+
code: "QUERY_ERROR",
|
|
191
|
+
message: u.message
|
|
192
|
+
} });
|
|
193
|
+
let d = (l ?? []).map((e) => e.id), f = [];
|
|
194
|
+
if (d.length > 0) {
|
|
195
|
+
let { data: e, error: n } = await o.from("newsletters_edition_bricks").select(r.join(",")).in("block_id", d).order("brick_order", { ascending: !0 });
|
|
196
|
+
if (n) return t.status(500).json({ error: {
|
|
197
|
+
code: "QUERY_ERROR",
|
|
198
|
+
message: n.message
|
|
199
|
+
} });
|
|
200
|
+
f = e ?? [];
|
|
201
|
+
}
|
|
202
|
+
let p = {};
|
|
203
|
+
for (let e of f) (p[e.block_id] ??= []).push({
|
|
204
|
+
id: e.id,
|
|
205
|
+
brick_type: e.brick_type,
|
|
206
|
+
brick_order: e.brick_order,
|
|
207
|
+
content: e.content
|
|
208
|
+
});
|
|
209
|
+
let m = (l ?? []).map((e) => ({
|
|
210
|
+
...e,
|
|
211
|
+
bricks: p[e.id] ?? []
|
|
212
|
+
}));
|
|
213
|
+
a.setCache(t, {
|
|
214
|
+
kind: "public",
|
|
215
|
+
maxAge: 60,
|
|
216
|
+
sMaxAge: 600
|
|
217
|
+
}), t.json({
|
|
218
|
+
data: {
|
|
219
|
+
edition: {
|
|
220
|
+
id: i.id,
|
|
221
|
+
title: i.title,
|
|
222
|
+
edition_date: i.edition_date,
|
|
223
|
+
content_category: i.content_category
|
|
224
|
+
},
|
|
225
|
+
blocks: m
|
|
226
|
+
},
|
|
227
|
+
_links: { self: e.originalUrl }
|
|
228
|
+
});
|
|
229
|
+
} catch (e) {
|
|
230
|
+
console.error("[newsletters] public-api edition content error:", e), t.status(500).json({ error: {
|
|
231
|
+
code: "INTERNAL",
|
|
232
|
+
message: "Internal server error"
|
|
233
|
+
} });
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
//#endregion
|
|
238
|
+
export { i as registerPublicApi };
|