@mwam/sdk 0.3.0 → 0.5.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 +62 -2
- package/dist/index.d.ts +3750 -166
- package/dist/index.js +362 -17
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5,6 +5,39 @@ var noNul = (s) => !s.includes("\0");
|
|
|
5
5
|
var NUL_ISSUE = { message: "must not contain the NUL character (U+0000)" };
|
|
6
6
|
var storableString = () => z.string().refine(noNul, NUL_ISSUE);
|
|
7
7
|
|
|
8
|
+
// ../schemas/src/content/layout.ts
|
|
9
|
+
var SECTION_LAYOUTS = ["one", "halves", "wideLeft", "wideRight", "thirds", "mainSidebar", "sidebarMain"];
|
|
10
|
+
var ROW_LAYOUTS = ["halves", "thirds", "wideLeft", "wideRight"];
|
|
11
|
+
var COLUMN_COUNT = {
|
|
12
|
+
one: 1,
|
|
13
|
+
halves: 2,
|
|
14
|
+
wideLeft: 2,
|
|
15
|
+
wideRight: 2,
|
|
16
|
+
thirds: 3,
|
|
17
|
+
mainSidebar: 2,
|
|
18
|
+
sidebarMain: 2
|
|
19
|
+
};
|
|
20
|
+
new Map(Object.entries(COLUMN_COUNT));
|
|
21
|
+
var SECTION_WIDTHS = ["contained", "full"];
|
|
22
|
+
var SECTION_SPACINGS = ["s", "m", "l"];
|
|
23
|
+
var BACKGROUNDS = ["bg-1", "bg-2", "bg-3", "bg-4", "bg-5", "bg-6"];
|
|
24
|
+
var COLUMN_ALIGNS = ["top", "middle"];
|
|
25
|
+
var SNIPPET_KINDS = ["teacher", "dates", "schedule", "booking", "gallery", "place"];
|
|
26
|
+
var BOOKING_PHONE = ["inline", "bar"];
|
|
27
|
+
var BUTTON_VARIANTS = ["primary", "secondary"];
|
|
28
|
+
var MAX_BUTTON_LABEL = 80;
|
|
29
|
+
var LAYOUT_TYPES = ["section", "column", "row", "subcolumn", "snippet", "button"];
|
|
30
|
+
new Set(LAYOUT_TYPES);
|
|
31
|
+
var PARENTS = {
|
|
32
|
+
section: ["doc"],
|
|
33
|
+
column: ["section"],
|
|
34
|
+
row: ["column"],
|
|
35
|
+
subcolumn: ["row"],
|
|
36
|
+
snippet: ["column", "subcolumn"],
|
|
37
|
+
button: ["column", "subcolumn"]
|
|
38
|
+
};
|
|
39
|
+
new Map(Object.entries(PARENTS));
|
|
40
|
+
|
|
8
41
|
// ../schemas/src/content/nodes.ts
|
|
9
42
|
var markSchema = z.discriminatedUnion("type", [
|
|
10
43
|
z.object({ type: z.literal("bold") }),
|
|
@@ -26,6 +59,9 @@ var imageBlock = imageRef.extend({
|
|
|
26
59
|
caption: storableString().nullable().optional(),
|
|
27
60
|
align: z.enum(ALIGNMENTS).optional()
|
|
28
61
|
});
|
|
62
|
+
var MAX_HTML_SECTION = 2e5;
|
|
63
|
+
var nodeId = z.string().regex(/^[A-Za-z0-9_-]{1,64}$/, "A node id is letters, digits, - and _").nullable().optional();
|
|
64
|
+
var align = z.enum(COLUMN_ALIGNS);
|
|
29
65
|
var nodeSchema = z.lazy(
|
|
30
66
|
() => z.discriminatedUnion("type", [
|
|
31
67
|
textNode,
|
|
@@ -39,35 +75,197 @@ var nodeSchema = z.lazy(
|
|
|
39
75
|
z.object({ type: z.literal("listItem"), content: z.array(nodeSchema).optional() }),
|
|
40
76
|
z.object({ type: z.literal("image"), attrs: imageBlock }),
|
|
41
77
|
z.object({ type: z.literal("beforeAfter"), attrs: z.object({ before: imageRef, after: imageRef, caption: storableString().nullable() }) }),
|
|
42
|
-
z.object({ type: z.literal("eventCard"), attrs: z.object({ eventId: storableString() }) })
|
|
78
|
+
z.object({ type: z.literal("eventCard"), attrs: z.object({ eventId: storableString() }) }),
|
|
79
|
+
z.object({ type: z.literal("htmlSection"), attrs: z.object({ html: storableString().pipe(z.string().max(MAX_HTML_SECTION, `An HTML section can be at most ${MAX_HTML_SECTION} characters`)) }) }),
|
|
80
|
+
z.object({
|
|
81
|
+
type: z.literal("section"),
|
|
82
|
+
attrs: z.object({ id: nodeId, layout: z.enum(SECTION_LAYOUTS), width: z.enum(SECTION_WIDTHS), background: z.enum(BACKGROUNDS).nullable(), spacing: z.enum(SECTION_SPACINGS) }),
|
|
83
|
+
content: z.array(nodeSchema).optional()
|
|
84
|
+
}),
|
|
85
|
+
z.object({ type: z.literal("column"), attrs: z.object({ id: nodeId, sticky: z.boolean(), align }), content: z.array(nodeSchema).optional() }),
|
|
86
|
+
z.object({ type: z.literal("row"), attrs: z.object({ id: nodeId, layout: z.enum(ROW_LAYOUTS) }), content: z.array(nodeSchema).optional() }),
|
|
87
|
+
z.object({ type: z.literal("subcolumn"), attrs: z.object({ id: nodeId, align }), content: z.array(nodeSchema).optional() }),
|
|
88
|
+
z.object({
|
|
89
|
+
type: z.literal("snippet"),
|
|
90
|
+
attrs: z.object({ id: nodeId, kind: z.enum(SNIPPET_KINDS), ref: storableString().pipe(z.string().max(200)).nullable(), phone: z.enum(BOOKING_PHONE).nullable() })
|
|
91
|
+
}),
|
|
92
|
+
z.object({
|
|
93
|
+
type: z.literal("button"),
|
|
94
|
+
attrs: z.object({
|
|
95
|
+
id: nodeId,
|
|
96
|
+
label: storableString().pipe(z.string().trim().min(1, "A button needs words").max(MAX_BUTTON_LABEL, `A button's words can be at most ${MAX_BUTTON_LABEL} characters`)),
|
|
97
|
+
href: storableString().pipe(z.string().max(2e3)),
|
|
98
|
+
variant: z.enum(BUTTON_VARIANTS)
|
|
99
|
+
})
|
|
100
|
+
})
|
|
43
101
|
])
|
|
44
102
|
);
|
|
45
103
|
var MAX_DEPTH = 100;
|
|
46
|
-
|
|
47
|
-
|
|
104
|
+
var MAX_NODES = 5e4;
|
|
105
|
+
function outOfBounds(value) {
|
|
106
|
+
if (typeof value !== "object" || value === null) return null;
|
|
48
107
|
const root = value.content;
|
|
49
108
|
const stack = [{ list: root, depth: 1 }];
|
|
109
|
+
let count = 0;
|
|
50
110
|
while (stack.length > 0) {
|
|
51
111
|
const item = stack.pop();
|
|
52
112
|
if (item === void 0 || !Array.isArray(item.list)) continue;
|
|
53
|
-
if (item.depth > MAX_DEPTH) return
|
|
113
|
+
if (item.depth > MAX_DEPTH) return `document nesting exceeds ${MAX_DEPTH} levels`;
|
|
114
|
+
count += item.list.length;
|
|
115
|
+
if (count > MAX_NODES) return `document has more than ${MAX_NODES} nodes and marks`;
|
|
54
116
|
for (const child of item.list) {
|
|
55
117
|
if (typeof child === "object" && child !== null) {
|
|
118
|
+
const marks = child.marks;
|
|
119
|
+
if (Array.isArray(marks)) {
|
|
120
|
+
count += marks.length;
|
|
121
|
+
if (count > MAX_NODES) return `document has more than ${MAX_NODES} nodes and marks`;
|
|
122
|
+
}
|
|
56
123
|
stack.push({ list: child.content, depth: item.depth + 1 });
|
|
57
124
|
}
|
|
58
125
|
}
|
|
59
126
|
}
|
|
60
|
-
return
|
|
127
|
+
return null;
|
|
61
128
|
}
|
|
62
129
|
var docShape = z.object({
|
|
63
130
|
type: z.literal("doc"),
|
|
64
131
|
content: z.array(nodeSchema)
|
|
65
132
|
});
|
|
66
133
|
var docSchema = z.unknown().superRefine((value, ctx) => {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
134
|
+
const refused = outOfBounds(value);
|
|
135
|
+
if (refused !== null) ctx.addIssue({ code: z.ZodIssueCode.custom, message: refused });
|
|
70
136
|
}).pipe(docShape);
|
|
137
|
+
|
|
138
|
+
// ../schemas/src/content/url.ts
|
|
139
|
+
var ALLOWED = /* @__PURE__ */ new Set(["http:", "https:", "mailto:"]);
|
|
140
|
+
function safeUrl(raw) {
|
|
141
|
+
const probe = Array.from(raw).filter((ch) => (ch.codePointAt(0) ?? 0) > 32).join("").toLowerCase();
|
|
142
|
+
if (probe.replace(/\\/g, "/").startsWith("//")) return null;
|
|
143
|
+
if (raw.startsWith("/") || raw.startsWith("#")) return raw;
|
|
144
|
+
const colon = probe.indexOf(":");
|
|
145
|
+
if (colon === -1) return raw;
|
|
146
|
+
const delim = [probe.indexOf("/"), probe.indexOf("?"), probe.indexOf("#")].filter((i) => i !== -1);
|
|
147
|
+
if (delim.some((i) => i < colon)) return raw;
|
|
148
|
+
if (!ALLOWED.has(probe.slice(0, colon + 1))) return null;
|
|
149
|
+
return raw;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// ../schemas/src/content/render.ts
|
|
153
|
+
var BUTTON_CLASS = {
|
|
154
|
+
primary: "mwam-button mwam-button--primary",
|
|
155
|
+
secondary: "mwam-button mwam-button--secondary"
|
|
156
|
+
};
|
|
157
|
+
new Map(Object.entries(BUTTON_CLASS));
|
|
158
|
+
var WIDTH_CLASS = {
|
|
159
|
+
small: "mwam-image--small",
|
|
160
|
+
medium: "mwam-image--medium",
|
|
161
|
+
wide: "mwam-image--wide",
|
|
162
|
+
full: "mwam-image--full"
|
|
163
|
+
};
|
|
164
|
+
var ALIGN_CLASS = { center: "mwam-align-center", right: "mwam-align-right" };
|
|
165
|
+
new Map(Object.entries(WIDTH_CLASS));
|
|
166
|
+
new Map(Object.entries(ALIGN_CLASS));
|
|
167
|
+
var esc = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
168
|
+
|
|
169
|
+
// ../schemas/src/content/page-html.ts
|
|
170
|
+
var COLS_CLASS = {
|
|
171
|
+
one: "mwam-cols--one",
|
|
172
|
+
halves: "mwam-cols--halves",
|
|
173
|
+
wideLeft: "mwam-cols--wide-left",
|
|
174
|
+
wideRight: "mwam-cols--wide-right",
|
|
175
|
+
thirds: "mwam-cols--thirds",
|
|
176
|
+
mainSidebar: "mwam-cols--main-sidebar",
|
|
177
|
+
sidebarMain: "mwam-cols--sidebar-main"
|
|
178
|
+
};
|
|
179
|
+
var WIDTH_CLASS2 = { contained: "mwam-section--contained", full: "mwam-section--full" };
|
|
180
|
+
var SPACE_CLASS = { s: "mwam-section--space-s", m: "mwam-section--space-m", l: "mwam-section--space-l" };
|
|
181
|
+
var BG_CLASS = Object.fromEntries(BACKGROUNDS.map((k) => [k, `mwam-${k}`]));
|
|
182
|
+
var SNIPPET_CLASS = Object.fromEntries(SNIPPET_KINDS.map((k) => [k, `mwam-snippet--${k}`]));
|
|
183
|
+
var BUTTON_CLASS2 = { primary: "mwam-button mwam-button--primary", secondary: "mwam-button mwam-button--secondary" };
|
|
184
|
+
var lookup = (table) => {
|
|
185
|
+
const map = new Map(Object.entries(table));
|
|
186
|
+
return (value) => map.get(value) ?? null;
|
|
187
|
+
};
|
|
188
|
+
var colsClass = lookup(COLS_CLASS);
|
|
189
|
+
var widthClass2 = lookup(WIDTH_CLASS2);
|
|
190
|
+
var spaceClass = lookup(SPACE_CLASS);
|
|
191
|
+
var bgClass = lookup(BG_CLASS);
|
|
192
|
+
var snippetClass = lookup(SNIPPET_CLASS);
|
|
193
|
+
var buttonClass2 = lookup(BUTTON_CLASS2);
|
|
194
|
+
var classes = (...names) => names.filter((n) => typeof n === "string" && n !== "").join(" ");
|
|
195
|
+
function block(b, opts) {
|
|
196
|
+
switch (b.type) {
|
|
197
|
+
case "html":
|
|
198
|
+
return typeof b["html"] === "string" ? b["html"] : "";
|
|
199
|
+
case "button": {
|
|
200
|
+
const href = safeUrl(String(b["href"] ?? ""));
|
|
201
|
+
if (href === null) return "";
|
|
202
|
+
return `<p class="mwam-button-row"><a class="${buttonClass2(b["variant"]) ?? "mwam-button mwam-button--primary"}" href="${esc(href)}">${esc(String(b["label"] ?? ""))}</a></p>`;
|
|
203
|
+
}
|
|
204
|
+
case "row": {
|
|
205
|
+
const cols = Array.isArray(b["columns"]) ? b["columns"] : [];
|
|
206
|
+
return `<div class="${classes("mwam-row", "mwam-cols", colsClass(b["layout"]))}">` + cols.map((c) => `<div class="${classes("mwam-col", c.align === "middle" && "mwam-col--middle")}">` + (Array.isArray(c.blocks) ? c.blocks.map((x) => block(x, opts)).join("") : "") + "</div>").join("") + "</div>";
|
|
207
|
+
}
|
|
208
|
+
case "snippet": {
|
|
209
|
+
const drawn = opts.snippet?.(b) ?? null;
|
|
210
|
+
const cls = classes("mwam-snippet", snippetClass(b["kind"]), b["phone"] === "bar" && "mwam-snippet--phone-bar");
|
|
211
|
+
return `<div class="${cls}">${drawn ?? ""}</div>`;
|
|
212
|
+
}
|
|
213
|
+
default:
|
|
214
|
+
return "";
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
function pageHtml(page, opts = {}) {
|
|
218
|
+
return `<div class="mwam-page">` + page.sections.map((s) => {
|
|
219
|
+
const cls = classes("mwam-section", widthClass2(s.width), spaceClass(s.spacing), bgClass(s.background));
|
|
220
|
+
const cols = s.columns.map((c) => `<div class="${classes("mwam-col", c.sticky && "mwam-col--sticky", c.align === "middle" && "mwam-col--middle")}">` + c.blocks.map((b) => block(b, opts)).join("") + "</div>").join("");
|
|
221
|
+
return `<section class="${cls}"><div class="mwam-section__inner"><div class="${classes("mwam-cols", colsClass(s.layout))}">${cols}</div></div></section>`;
|
|
222
|
+
}).join("") + "</div>";
|
|
223
|
+
}
|
|
224
|
+
var CSS_VAR = /^--[A-Za-z0-9_-]{1,64}$/;
|
|
225
|
+
var HEX = /^#[0-9A-Fa-f]{6}$/;
|
|
226
|
+
var clamp = (n, lo, hi, fallback) => typeof n === "number" && Number.isFinite(n) ? Math.min(hi, Math.max(lo, Math.round(n))) : fallback;
|
|
227
|
+
function layoutCss(opts = {}) {
|
|
228
|
+
const bp = clamp(opts.breakpoint, 320, 2400, 900);
|
|
229
|
+
const top = clamp(opts.stickyTop, 0, 400, 24);
|
|
230
|
+
const palette = (opts.palette ?? []).flatMap((p) => {
|
|
231
|
+
const cls = bgClass(p.key);
|
|
232
|
+
if (cls === null || !HEX.test(p.color) || !HEX.test(p.text)) return [];
|
|
233
|
+
const value = p.cssVar !== null && CSS_VAR.test(p.cssVar) ? `var(${p.cssVar}, ${p.color})` : p.color;
|
|
234
|
+
return [`.${cls}{background-color:${value};color:${p.text}}`];
|
|
235
|
+
});
|
|
236
|
+
return [
|
|
237
|
+
".mwam-page{display:block}",
|
|
238
|
+
".mwam-section{padding-block:var(--mwam-space-m,3rem)}",
|
|
239
|
+
".mwam-section--space-s{padding-block:var(--mwam-space-s,1.5rem)}",
|
|
240
|
+
".mwam-section--space-l{padding-block:var(--mwam-space-l,5rem)}",
|
|
241
|
+
".mwam-section__inner{box-sizing:border-box;margin-inline:auto;max-width:var(--mwam-measure,75rem);padding-inline:var(--mwam-gutter,1.5rem)}",
|
|
242
|
+
".mwam-section--full>.mwam-section__inner{max-width:none}",
|
|
243
|
+
".mwam-cols{display:grid;gap:var(--mwam-gap,2rem);grid-template-columns:minmax(0,1fr);align-items:start}",
|
|
244
|
+
".mwam-row{margin-block:1rem}",
|
|
245
|
+
".mwam-col{min-width:0}",
|
|
246
|
+
".mwam-col--middle{align-self:center}",
|
|
247
|
+
".mwam-col>:first-child{margin-top:0}",
|
|
248
|
+
".mwam-button-row{margin-block:1rem}",
|
|
249
|
+
".mwam-button{display:inline-block;padding:.75em 1.5em;border-radius:999px;text-decoration:none;border:2px solid currentColor}",
|
|
250
|
+
".mwam-button--primary{background:var(--mwam-accent,#2b2118);color:var(--mwam-on-accent,#fff);border-color:var(--mwam-accent,#2b2118)}",
|
|
251
|
+
`@media (min-width:${String(bp)}px){`,
|
|
252
|
+
".mwam-cols--halves{grid-template-columns:repeat(2,minmax(0,1fr))}",
|
|
253
|
+
".mwam-cols--thirds{grid-template-columns:repeat(3,minmax(0,1fr))}",
|
|
254
|
+
".mwam-cols--wide-left{grid-template-columns:minmax(0,2fr) minmax(0,1fr)}",
|
|
255
|
+
".mwam-cols--wide-right{grid-template-columns:minmax(0,1fr) minmax(0,2fr)}",
|
|
256
|
+
".mwam-cols--main-sidebar{grid-template-columns:minmax(0,1fr) var(--mwam-sidebar,22.5rem)}",
|
|
257
|
+
".mwam-cols--sidebar-main{grid-template-columns:var(--mwam-sidebar,22.5rem) minmax(0,1fr)}",
|
|
258
|
+
`.mwam-col--sticky{position:sticky;top:var(--mwam-sticky-top,${String(top)}px)}`,
|
|
259
|
+
"}",
|
|
260
|
+
`@media (max-width:${String(bp - 1)}px){`,
|
|
261
|
+
// On a phone the booking card set to "bar" is pinned to the bottom of the screen, as WMC's
|
|
262
|
+
// is, and the page leaves room under its last words for it.
|
|
263
|
+
".mwam-snippet--phone-bar{position:fixed;left:0;right:0;bottom:0;z-index:5;margin:0;background:var(--mwam-bar-bg,#fff);box-shadow:0 -1px 0 rgba(0,0,0,.12)}",
|
|
264
|
+
".mwam-page:has(.mwam-snippet--phone-bar){padding-bottom:var(--mwam-bar-room,10rem)}",
|
|
265
|
+
"}",
|
|
266
|
+
...palette
|
|
267
|
+
].join("\n");
|
|
268
|
+
}
|
|
71
269
|
var objectBody = { required_error: "A JSON object body is required", invalid_type_error: "The body must be a JSON object" };
|
|
72
270
|
var EVENT_CATEGORIES = ["MEDITATION", "RETREAT", "DHAMMA_CLASS", "CEREMONY", "OTHER"];
|
|
73
271
|
var ATTENDANCE_MODES = ["OFFLINE", "ONLINE", "MIXED"];
|
|
@@ -82,6 +280,7 @@ var registrationModeSchema = z.enum(REGISTRATION_MODES);
|
|
|
82
280
|
var EVENT_TITLE_MAX = 200;
|
|
83
281
|
var EVENT_SUMMARY_MAX = 500;
|
|
84
282
|
var SEGMENT_LABEL_MAX = 120;
|
|
283
|
+
var SEGMENTS_MAX = 50;
|
|
85
284
|
var SESSION_MAX_MINUTES = 24 * 60;
|
|
86
285
|
var text = (max) => z.string().trim().max(max).refine(noNul, NUL_ISSUE);
|
|
87
286
|
var eventSlugSchema = z.string().min(1).max(120).regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, "Use lowercase letters, numbers and single hyphens");
|
|
@@ -138,6 +337,12 @@ z.object({
|
|
|
138
337
|
}, objectBody).strict();
|
|
139
338
|
sessionInput.innerType().partial().extend({ tell: tellSchema.optional() }).strict();
|
|
140
339
|
z.object({ tell: tellSchema.optional() }, objectBody).strict();
|
|
340
|
+
z.object({ tell: z.boolean() }, objectBody).strict();
|
|
341
|
+
var onlineViaSchema = z.enum(["LINK", "ZOOM"]);
|
|
342
|
+
var signUpModeSchema = z.enum(["EACH_DATE", "ALL_DATES"]);
|
|
343
|
+
var eventPricingSchema = z.enum(["FREE", "DONATION"]);
|
|
344
|
+
var eventCapacitySchema = z.number().int().min(1).max(1e6).nullable();
|
|
345
|
+
z.object({ sessions: z.array(sessionInput).min(1).max(100) }, objectBody).strict();
|
|
141
346
|
var eventFields = {
|
|
142
347
|
slug: eventSlugSchema,
|
|
143
348
|
title: eventTitleSchema,
|
|
@@ -147,6 +352,8 @@ var eventFields = {
|
|
|
147
352
|
coverAssetId: z.string().min(1).max(64).nullable().optional(),
|
|
148
353
|
category: eventCategorySchema.optional(),
|
|
149
354
|
attendance: attendanceModeSchema.optional(),
|
|
355
|
+
/** LINK: each date's own published link. ZOOM: a meeting per date in the monastery's Zoom. */
|
|
356
|
+
onlineVia: onlineViaSchema.optional(),
|
|
150
357
|
timezone: timezoneSchema,
|
|
151
358
|
/** Display only — the badge reading "MONTHLY". The dates that exist are the sessions. */
|
|
152
359
|
recurrenceLabel: text(60).nullable().optional(),
|
|
@@ -156,7 +363,12 @@ var eventFields = {
|
|
|
156
363
|
priceCents: priceCentsSchema.optional(),
|
|
157
364
|
priceCurrency: currencySchema.optional(),
|
|
158
365
|
registration: registrationModeSchema.optional(),
|
|
159
|
-
externalRegistrationUrl: z.string().url().max(2e3).nullable().optional()
|
|
366
|
+
externalRegistrationUrl: z.string().url().max(2e3).nullable().optional(),
|
|
367
|
+
signUp: signUpModeSchema.optional(),
|
|
368
|
+
capacity: eventCapacitySchema.optional(),
|
|
369
|
+
pricing: eventPricingSchema.optional(),
|
|
370
|
+
/** Where a DONATION event's amount starts; null starts at the least. */
|
|
371
|
+
suggestedCents: priceCentsSchema.nullable().optional()
|
|
160
372
|
};
|
|
161
373
|
var registrationIsReachable = (v) => v.registration !== "EXTERNAL" || (v.externalRegistrationUrl ?? "") !== "";
|
|
162
374
|
var REGISTRATION_ISSUE = {
|
|
@@ -173,6 +385,8 @@ z.object({
|
|
|
173
385
|
coverAssetId: z.string().min(1).max(64).nullable().optional(),
|
|
174
386
|
category: eventCategorySchema.optional(),
|
|
175
387
|
attendance: attendanceModeSchema.optional(),
|
|
388
|
+
/** LINK: each date's own published link. ZOOM: a meeting per date in the monastery's Zoom. */
|
|
389
|
+
onlineVia: onlineViaSchema.optional(),
|
|
176
390
|
timezone: timezoneSchema.optional(),
|
|
177
391
|
recurrenceLabel: text(60).nullable().optional(),
|
|
178
392
|
teacherName: text(200).nullable().optional(),
|
|
@@ -182,8 +396,13 @@ z.object({
|
|
|
182
396
|
priceCurrency: currencySchema.optional(),
|
|
183
397
|
registration: registrationModeSchema.optional(),
|
|
184
398
|
externalRegistrationUrl: z.string().url().max(2e3).nullable().optional(),
|
|
399
|
+
signUp: signUpModeSchema.optional(),
|
|
400
|
+
capacity: eventCapacitySchema.optional(),
|
|
401
|
+
pricing: eventPricingSchema.optional(),
|
|
402
|
+
/** Where a DONATION event's amount starts; null starts at the least. */
|
|
403
|
+
suggestedCents: priceCentsSchema.nullable().optional(),
|
|
185
404
|
/** The whole running order at once: a list is a set, not a delta. Omitted leaves it alone. */
|
|
186
|
-
segments: z.array(segmentInput).max(
|
|
405
|
+
segments: z.array(segmentInput).max(SEGMENTS_MAX).optional(),
|
|
187
406
|
/**
|
|
188
407
|
* The `updatedAt` this edit was made against, passed back exactly as the API gave it.
|
|
189
408
|
* Optional, as on a post: without it a PATCH is last-write-wins; with it, the write is
|
|
@@ -325,6 +544,19 @@ var publicEventSummarySchema = z.object({
|
|
|
325
544
|
priceCents: z.number().int(),
|
|
326
545
|
priceCurrency: z.string(),
|
|
327
546
|
registration: registrationModeSchema,
|
|
547
|
+
/**
|
|
548
|
+
* EACH_DATE: a place is booked a date at a time. ALL_DATES: people sign up once for every date
|
|
549
|
+
* (`signUp` in the SDK), and each date's `capacity` and `seatsLeft` are the event's.
|
|
550
|
+
*/
|
|
551
|
+
signUp: z.enum(["EACH_DATE", "ALL_DATES"]).default("EACH_DATE"),
|
|
552
|
+
/**
|
|
553
|
+
* DONATION: booking a date takes a donation by card of at least `priceCents` a place —
|
|
554
|
+
* `register` with `card` and `amountCents`, the card box started with what `giving()`
|
|
555
|
+
* answers as `card`. FREE: nothing is taken, whatever `priceCents` shows.
|
|
556
|
+
*/
|
|
557
|
+
pricing: z.enum(["FREE", "DONATION"]).default("FREE"),
|
|
558
|
+
/** Where a DONATION's amount starts; null starts at `priceCents`. */
|
|
559
|
+
suggestedCents: z.number().int().nullable().default(null),
|
|
328
560
|
/** Where registering happens when `registration` is EXTERNAL. Null otherwise. */
|
|
329
561
|
registrationUrl: z.string().nullable(),
|
|
330
562
|
series: publicSeriesRefSchema.nullable(),
|
|
@@ -337,6 +569,66 @@ var publicEventSummarySchema = z.object({
|
|
|
337
569
|
var publicSessionRowSchema = publicSessionSchema.extend({ event: publicEventSummarySchema });
|
|
338
570
|
var publicSessionListSchema = z.object({ sessions: z.array(publicSessionRowSchema) });
|
|
339
571
|
var publicEventGallerySchema = publicGallerySchema.omit({ event: true });
|
|
572
|
+
var publicTeacherSchema = z.object({
|
|
573
|
+
id: z.string(),
|
|
574
|
+
name: z.string(),
|
|
575
|
+
/** How they are addressed — "Venerable" — written before the name, or null. */
|
|
576
|
+
title: z.string().nullable(),
|
|
577
|
+
bio: z.string().nullable(),
|
|
578
|
+
photo: publicCoverSchema.nullable()
|
|
579
|
+
});
|
|
580
|
+
var publicSnippetBlock = z.object({
|
|
581
|
+
type: z.literal("snippet"),
|
|
582
|
+
/** teacher, dates, schedule, booking, gallery or place. Skip a kind you do not know. */
|
|
583
|
+
kind: z.string(),
|
|
584
|
+
/** The booking card on a phone: where it is, or pinned to the bottom of the screen. */
|
|
585
|
+
phone: z.enum(BOOKING_PHONE).nullable(),
|
|
586
|
+
teacher: publicTeacherSchema.nullable().optional(),
|
|
587
|
+
gallery: publicEventGallerySchema.nullable().optional()
|
|
588
|
+
});
|
|
589
|
+
var publicHtmlBlock = z.object({ type: z.literal("html"), html: z.string() });
|
|
590
|
+
var publicButtonBlock = z.object({ type: z.literal("button"), label: z.string(), href: z.string(), variant: z.enum(BUTTON_VARIANTS) });
|
|
591
|
+
var publicOtherBlock = z.object({ type: z.string() }).passthrough();
|
|
592
|
+
var publicLeafBlock = z.union([publicHtmlBlock, publicButtonBlock, publicSnippetBlock, publicOtherBlock]);
|
|
593
|
+
var publicRowBlock = z.object({
|
|
594
|
+
type: z.literal("row"),
|
|
595
|
+
layout: z.enum(ROW_LAYOUTS),
|
|
596
|
+
columns: z.array(z.object({ align: z.enum(COLUMN_ALIGNS), blocks: z.array(publicLeafBlock) }))
|
|
597
|
+
});
|
|
598
|
+
var publicPageBlock = z.union([publicHtmlBlock, publicButtonBlock, publicSnippetBlock, publicRowBlock, publicOtherBlock]);
|
|
599
|
+
var publicPageSchema = z.object({
|
|
600
|
+
sections: z.array(z.object({
|
|
601
|
+
id: z.string().nullable(),
|
|
602
|
+
/** How the columns share the width. Phones stack them, in order. */
|
|
603
|
+
layout: z.enum(SECTION_LAYOUTS),
|
|
604
|
+
width: z.enum(SECTION_WIDTHS),
|
|
605
|
+
/** One of `style.palette`'s keys, or none. */
|
|
606
|
+
background: z.enum(BACKGROUNDS).nullable(),
|
|
607
|
+
spacing: z.enum(SECTION_SPACINGS),
|
|
608
|
+
columns: z.array(z.object({
|
|
609
|
+
/** Stays in view while the rest of the section scrolls past, on a wide screen. */
|
|
610
|
+
sticky: z.boolean(),
|
|
611
|
+
align: z.enum(COLUMN_ALIGNS),
|
|
612
|
+
blocks: z.array(publicPageBlock)
|
|
613
|
+
}))
|
|
614
|
+
})),
|
|
615
|
+
/** The monastery's own colours and measures, learned from its website (Website style). */
|
|
616
|
+
style: z.object({
|
|
617
|
+
palette: z.array(z.object({
|
|
618
|
+
key: z.enum(BACKGROUNDS),
|
|
619
|
+
/** The site's own CSS variable for it, when it has one. */
|
|
620
|
+
cssVar: z.string().nullable(),
|
|
621
|
+
/** The colour itself, as #rrggbb. */
|
|
622
|
+
color: z.string(),
|
|
623
|
+
/** The text colour that reads on it, as #rrggbb. */
|
|
624
|
+
text: z.string()
|
|
625
|
+
})),
|
|
626
|
+
/** Below this width, in CSS pixels, the site stacks columns. Null: the site's own choice. */
|
|
627
|
+
breakpoint: z.number().int().nullable(),
|
|
628
|
+
/** How far below the top a sticky column stops, in CSS pixels — under the site's header. */
|
|
629
|
+
stickyTop: z.number().int().nullable()
|
|
630
|
+
})
|
|
631
|
+
});
|
|
340
632
|
var publicEventDetailSchema = publicEventSummarySchema.extend({
|
|
341
633
|
bodyHtml: z.string(),
|
|
342
634
|
teacherName: z.string().nullable(),
|
|
@@ -346,7 +638,11 @@ var publicEventDetailSchema = publicEventSummarySchema.extend({
|
|
|
346
638
|
/** Minutes from the session's start — the running order, not clock times. */
|
|
347
639
|
segments: z.array(z.object({ startsMinute: z.number().int(), endsMinute: z.number().int(), label: z.string() })),
|
|
348
640
|
/** Galleries linked to this event in the CRM, published ones only, newest first. */
|
|
349
|
-
galleries: z.array(publicEventGallerySchema)
|
|
641
|
+
galleries: z.array(publicEventGallerySchema),
|
|
642
|
+
/** The page, laid out — or null for a plain description, which is `bodyHtml`. Draw this in place of the description and any sidebar of your own. */
|
|
643
|
+
page: publicPageSchema.nullable(),
|
|
644
|
+
/** The teachers the page shows, in the order it first shows them. */
|
|
645
|
+
teachers: z.array(publicTeacherSchema)
|
|
350
646
|
});
|
|
351
647
|
var publicSeriesSchema = publicSeriesRefSchema.extend({
|
|
352
648
|
summary: z.string().nullable(),
|
|
@@ -362,8 +658,23 @@ var registerInput = z.object({
|
|
|
362
658
|
name: z.string().trim().min(1, "A name is needed").max(200),
|
|
363
659
|
email: z.string().trim().email("That does not look like an email address").max(320),
|
|
364
660
|
/** Them plus anyone they are bringing. Capacity counts seats, not bookings. */
|
|
365
|
-
seats: z.number().int().min(1).max(20).optional()
|
|
661
|
+
seats: z.number().int().min(1).max(20).optional(),
|
|
662
|
+
/**
|
|
663
|
+
* For a DONATION event: the card box's one-use token, held for the booking and taken only
|
|
664
|
+
* once the place is (never stored), with the bank's confirmation where it asked for one.
|
|
665
|
+
*/
|
|
666
|
+
card: z.object({
|
|
667
|
+
sourceId: z.string().min(1).max(2e3).regex(/^\S+$/, "That is not a card box's token"),
|
|
668
|
+
verificationToken: z.string().min(1).max(4e3).regex(/^\S+$/, "That is not a verification token").optional()
|
|
669
|
+
}).strict().optional(),
|
|
670
|
+
/** What they give, in minor units: at least the event's `priceCents` for each place. */
|
|
671
|
+
amountCents: z.number().int().min(1).max(1e8).optional()
|
|
672
|
+
}).strict();
|
|
673
|
+
var signUpInput = z.object({
|
|
674
|
+
name: z.string().trim().min(1, "A name is needed").max(200),
|
|
675
|
+
email: z.string().trim().email("That does not look like an email address").max(320)
|
|
366
676
|
}).strict();
|
|
677
|
+
var signedUpSchema = z.object({ status: z.enum(["CONFIRMED", "WAITLISTED"]) });
|
|
367
678
|
var bookingSchema = z.object({
|
|
368
679
|
status: z.enum(["CONFIRMED", "WAITLISTED", "CANCELLED"]),
|
|
369
680
|
seats: z.number().int(),
|
|
@@ -628,8 +939,17 @@ function createClient({ baseUrl = DEFAULT_BASE_URL, tenant, fetch: given, revali
|
|
|
628
939
|
* error, and a site that treated it as one would tell somebody their booking failed when
|
|
629
940
|
* they are in fact next in line. **Check `status`.**
|
|
630
941
|
*
|
|
631
|
-
* The
|
|
632
|
-
*
|
|
942
|
+
* The person's link to their booking reaches them by email, and only by email: the answer
|
|
943
|
+
* carries no token (since 0.4.0). An address that had already booked the date is answered
|
|
944
|
+
* as a newcomer would be — `status` is what a new booking gets now — and is sent an email
|
|
945
|
+
* saying how things really stand, so this cannot be used to ask who has booked.
|
|
946
|
+
*
|
|
947
|
+
* A date whose event's `pricing` is DONATION takes `card` — the card box's token, the box
|
|
948
|
+
* started with what `giving()` answers as `card` — and `amountCents`, at least the event's
|
|
949
|
+
* `priceCents` for each place. The card is held, the place taken, and only then is the money
|
|
950
|
+
* taken: a full date throws (`conflict`, 409) with nothing taken, never waitlisting; a
|
|
951
|
+
* refused card throws `declined` (402) whose message is for the person. The confirmation
|
|
952
|
+
* email is their receipt.
|
|
633
953
|
*/
|
|
634
954
|
async register(sessionId, who, { visitor } = {}) {
|
|
635
955
|
const input = registerInput.safeParse(who);
|
|
@@ -641,6 +961,24 @@ function createClient({ baseUrl = DEFAULT_BASE_URL, tenant, fetch: given, revali
|
|
|
641
961
|
if (!parsed.success) throw new MwamError("unexpected_shape", shapeProblem(parsed.error.issues));
|
|
642
962
|
return parsed.data;
|
|
643
963
|
},
|
|
964
|
+
/**
|
|
965
|
+
* Signs somebody up once for every date of an event whose `signUp` is ALL_DATES — the
|
|
966
|
+
* dates it has and any added later; booking one of its dates with `register` is refused.
|
|
967
|
+
*
|
|
968
|
+
* The same rules as `register`: WAITLISTED when it is full, **check `status`**; an address
|
|
969
|
+
* already signed up is answered as a newcomer would be and emailed how things stand. The
|
|
970
|
+
* email carries the person's own page, which is where they leave.
|
|
971
|
+
*/
|
|
972
|
+
async signUp(eventSlug, who, { visitor } = {}) {
|
|
973
|
+
const input = signUpInput.safeParse(who);
|
|
974
|
+
if (!input.success) throw new MwamError("invalid", shapeProblem(input.error.issues));
|
|
975
|
+
const parsed = signedUpSchema.safeParse(await read(`/events/${encodeURIComponent(eventSlug)}/sign-up`, {}, {
|
|
976
|
+
method: "POST",
|
|
977
|
+
body: JSON.stringify(input.data)
|
|
978
|
+
}, visitor));
|
|
979
|
+
if (!parsed.success) throw new MwamError("unexpected_shape", shapeProblem(parsed.error.issues));
|
|
980
|
+
return parsed.data;
|
|
981
|
+
},
|
|
644
982
|
/** One booking, by the token from its link. */
|
|
645
983
|
async booking(token) {
|
|
646
984
|
const parsed = bookingSchema.safeParse(await read(`/bookings/${encodeURIComponent(token)}`));
|
|
@@ -733,8 +1071,7 @@ function createClient({ baseUrl = DEFAULT_BASE_URL, tenant, fetch: given, revali
|
|
|
733
1071
|
var postFormats = z.array(z.enum(POST_BODY_FORMATS)).min(1).optional();
|
|
734
1072
|
var takenSchema = z.object({
|
|
735
1073
|
status: z.enum(["CONFIRMED", "WAITLISTED"]),
|
|
736
|
-
seats: z.number().int()
|
|
737
|
-
token: z.string()
|
|
1074
|
+
seats: z.number().int()
|
|
738
1075
|
});
|
|
739
1076
|
var shapeProblem = (issues) => {
|
|
740
1077
|
const first = issues[0];
|
|
@@ -774,6 +1111,14 @@ function eventJsonLd(session, event, opts = { url: "" }) {
|
|
|
774
1111
|
}
|
|
775
1112
|
},
|
|
776
1113
|
...opts.organizer === void 0 ? {} : { organizer: { "@type": "Organization", ...opts.organizer } },
|
|
1114
|
+
// The teachers the event's page shows, as schema.org's performers: who leads it.
|
|
1115
|
+
...event.teachers === void 0 || event.teachers.length === 0 ? {} : {
|
|
1116
|
+
performer: event.teachers.map((t) => ({
|
|
1117
|
+
"@type": "Person",
|
|
1118
|
+
name: t.title === null ? t.name : `${t.title} ${t.name}`,
|
|
1119
|
+
...t.photo === null ? {} : { image: t.photo.url }
|
|
1120
|
+
}))
|
|
1121
|
+
},
|
|
777
1122
|
// schema.org's own word for the programme an event belongs to. Only with a URL: a
|
|
778
1123
|
// superEvent Google cannot follow is a name with nothing behind it.
|
|
779
1124
|
...event.series === void 0 || event.series === null || opts.seriesUrl === void 0 ? {} : { superEvent: { "@type": "EventSeries", name: event.series.name, url: opts.seriesUrl } },
|
|
@@ -788,4 +1133,4 @@ function eventJsonLd(session, event, opts = { url: "" }) {
|
|
|
788
1133
|
};
|
|
789
1134
|
}
|
|
790
1135
|
|
|
791
|
-
export { DEFAULT_BASE_URL, MwamError, createClient, eventJsonLd };
|
|
1136
|
+
export { DEFAULT_BASE_URL, MwamError, createClient, eventJsonLd, layoutCss, pageHtml };
|