@mwam/sdk 0.3.0 → 0.4.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 CHANGED
@@ -157,7 +157,7 @@ verificationToken })` from your server. Square keeps the card in the monastery's
157
157
  and charges it each month; each month is receipted. The donor is emailed a private link to
158
158
  `/give/monthly/{token}` on your site — a page that shows `monthlyGift(token)` and offers
159
159
  `stopMonthlyGift(token)`. Apple Pay shows only on
160
- an address an Admin has turned it on for, in **Giving**; the address must serve Square's file
160
+ an address an Admin has turned it on for, in **Monastery settings → Payments**; the address must serve Square's file
161
161
  at `/.well-known/apple-developer-merchantid-domain-association`.
162
162
 
163
163
  A missing, wrong or withdrawn key is refused on every call, so a broken key shows up at once. To replace one: make the new key, deploy it, then withdraw the old.
@@ -174,7 +174,9 @@ A missing, wrong or withdrawn key is refused on every call, so a broken key show
174
174
  | `getEvent(slug)` | One event and every date it has, with its `cover` and the `galleries` linked to it |
175
175
  | `listSeries()` · `getSeries(slug)` | Programmes, and the events in each |
176
176
  | `listGalleries({ limit? })` · `getGallery(slug)` | Published galleries; every picture has alt text |
177
- | `register(sessionId, who, { visitor? })` | Takes a place, or a place on the waitlist |
177
+ | `register(sessionId, who, { visitor? })` | Takes a place, or a place on the waitlist. Answers `{ status, seats }` and no token (since 0.4.0): the person's link goes to them by email, and an address that had already booked is answered as a newcomer would be |
178
+ | `signUp(eventSlug, who, { visitor? })` | For an event whose `signUp` is `ALL_DATES` (a weekly class): one sign-up for every date it has and any added later. Answers `{ status }`, CONFIRMED or WAITLISTED, with the same rules as `register`; booking one of its dates with `register` is refused. The person leaves from their own page, which the email links to |
179
+ | `register(sessionId, { name, email, seats?, card, amountCents }, { visitor? })` | For a date whose event's `pricing` is `DONATION` (each place gives at least `priceCents`): `card` is the card box's `{ sourceId, verificationToken? }`, the box started with `giving().card`. The card is held, the place taken, then the money taken; a full date throws `conflict` with nothing taken, a refused card throws `declined` with a message for the person. The confirmation email is the receipt |
178
180
  | `booking(token)` · `cancelBooking(token)` | One booking, by the token from its email |
179
181
  | `giving()` | Whether a gift can be taken now, in what currency, and what to start Square's card box with |
180
182
  | `give(gift, { visitor? })` | Starts a gift; answers with the payment page |
package/dist/index.d.ts CHANGED
@@ -165,6 +165,25 @@ declare const publicSessionRowSchema: z.ZodObject<z.objectUtil.extendShape<{
165
165
  "EXTERNAL",
166
166
  "OURS"
167
167
  ]>;
168
+ /**
169
+ * EACH_DATE: a place is booked a date at a time. ALL_DATES: people sign up once for every date
170
+ * (`signUp` in the SDK), and each date's `capacity` and `seatsLeft` are the event's.
171
+ */
172
+ signUp: z.ZodDefault<z.ZodEnum<[
173
+ "EACH_DATE",
174
+ "ALL_DATES"
175
+ ]>>;
176
+ /**
177
+ * DONATION: booking a date takes a donation by card of at least `priceCents` a place —
178
+ * `register` with `card` and `amountCents`, the card box started with what `giving()`
179
+ * answers as `card`. FREE: nothing is taken, whatever `priceCents` shows.
180
+ */
181
+ pricing: z.ZodDefault<z.ZodEnum<[
182
+ "FREE",
183
+ "DONATION"
184
+ ]>>;
185
+ /** Where a DONATION's amount starts; null starts at `priceCents`. */
186
+ suggestedCents: z.ZodDefault<z.ZodNullable<z.ZodNumber>>;
168
187
  /** Where registering happens when `registration` is EXTERNAL. Null otherwise. */
169
188
  registrationUrl: z.ZodNullable<z.ZodString>;
170
189
  series: z.ZodNullable<z.ZodObject<{
@@ -209,6 +228,9 @@ declare const publicSessionRowSchema: z.ZodObject<z.objectUtil.extendShape<{
209
228
  priceCents: number;
210
229
  priceCurrency: string;
211
230
  registration: "NONE" | "EXTERNAL" | "OURS";
231
+ signUp: "EACH_DATE" | "ALL_DATES";
232
+ pricing: "FREE" | "DONATION";
233
+ suggestedCents: number | null;
212
234
  cover: {
213
235
  alt: string;
214
236
  url: string;
@@ -242,6 +264,9 @@ declare const publicSessionRowSchema: z.ZodObject<z.objectUtil.extendShape<{
242
264
  slug: string;
243
265
  name: string;
244
266
  } | null;
267
+ signUp?: "EACH_DATE" | "ALL_DATES" | undefined;
268
+ pricing?: "FREE" | "DONATION" | undefined;
269
+ suggestedCents?: number | null | undefined;
245
270
  }>;
246
271
  }>, "strip", z.ZodTypeAny, {
247
272
  status: "SCHEDULED" | "CANCELLED" | "POSTPONED" | "RESCHEDULED" | "MOVED_ONLINE";
@@ -260,6 +285,9 @@ declare const publicSessionRowSchema: z.ZodObject<z.objectUtil.extendShape<{
260
285
  priceCents: number;
261
286
  priceCurrency: string;
262
287
  registration: "NONE" | "EXTERNAL" | "OURS";
288
+ signUp: "EACH_DATE" | "ALL_DATES";
289
+ pricing: "FREE" | "DONATION";
290
+ suggestedCents: number | null;
263
291
  cover: {
264
292
  alt: string;
265
293
  url: string;
@@ -311,6 +339,9 @@ declare const publicSessionRowSchema: z.ZodObject<z.objectUtil.extendShape<{
311
339
  slug: string;
312
340
  name: string;
313
341
  } | null;
342
+ signUp?: "EACH_DATE" | "ALL_DATES" | undefined;
343
+ pricing?: "FREE" | "DONATION" | undefined;
344
+ suggestedCents?: number | null | undefined;
314
345
  };
315
346
  id: string;
316
347
  place: {
@@ -349,6 +380,25 @@ declare const publicEventDetailSchema: z.ZodObject<z.objectUtil.extendShape<{
349
380
  "EXTERNAL",
350
381
  "OURS"
351
382
  ]>;
383
+ /**
384
+ * EACH_DATE: a place is booked a date at a time. ALL_DATES: people sign up once for every date
385
+ * (`signUp` in the SDK), and each date's `capacity` and `seatsLeft` are the event's.
386
+ */
387
+ signUp: z.ZodDefault<z.ZodEnum<[
388
+ "EACH_DATE",
389
+ "ALL_DATES"
390
+ ]>>;
391
+ /**
392
+ * DONATION: booking a date takes a donation by card of at least `priceCents` a place —
393
+ * `register` with `card` and `amountCents`, the card box started with what `giving()`
394
+ * answers as `card`. FREE: nothing is taken, whatever `priceCents` shows.
395
+ */
396
+ pricing: z.ZodDefault<z.ZodEnum<[
397
+ "FREE",
398
+ "DONATION"
399
+ ]>>;
400
+ /** Where a DONATION's amount starts; null starts at `priceCents`. */
401
+ suggestedCents: z.ZodDefault<z.ZodNullable<z.ZodNumber>>;
352
402
  /** Where registering happens when `registration` is EXTERNAL. Null otherwise. */
353
403
  registrationUrl: z.ZodNullable<z.ZodString>;
354
404
  series: z.ZodNullable<z.ZodObject<{
@@ -586,6 +636,24 @@ declare const publicEventDetailSchema: z.ZodObject<z.objectUtil.extendShape<{
586
636
  }[];
587
637
  }>, "many">;
588
638
  }>, "strip", z.ZodTypeAny, {
639
+ sessions: {
640
+ status: "SCHEDULED" | "CANCELLED" | "POSTPONED" | "RESCHEDULED" | "MOVED_ONLINE";
641
+ startsAt: string;
642
+ endsAt: string;
643
+ statusNote: string | null;
644
+ capacity: number | null;
645
+ id: string;
646
+ place: {
647
+ streetAddress: string | null;
648
+ locality: string | null;
649
+ region: string | null;
650
+ postalCode: string | null;
651
+ country: string | null;
652
+ onlineUrl: string | null;
653
+ name: string | null;
654
+ };
655
+ seatsLeft: number | null;
656
+ }[];
589
657
  slug: string;
590
658
  title: string;
591
659
  summary: string | null;
@@ -599,6 +667,9 @@ declare const publicEventDetailSchema: z.ZodObject<z.objectUtil.extendShape<{
599
667
  priceCents: number;
600
668
  priceCurrency: string;
601
669
  registration: "NONE" | "EXTERNAL" | "OURS";
670
+ signUp: "EACH_DATE" | "ALL_DATES";
671
+ pricing: "FREE" | "DONATION";
672
+ suggestedCents: number | null;
602
673
  segments: {
603
674
  startsMinute: number;
604
675
  endsMinute: number;
@@ -636,6 +707,8 @@ declare const publicEventDetailSchema: z.ZodObject<z.objectUtil.extendShape<{
636
707
  slug: string;
637
708
  name: string;
638
709
  } | null;
710
+ bodyHtml: string;
711
+ }, {
639
712
  sessions: {
640
713
  status: "SCHEDULED" | "CANCELLED" | "POSTPONED" | "RESCHEDULED" | "MOVED_ONLINE";
641
714
  startsAt: string;
@@ -654,8 +727,6 @@ declare const publicEventDetailSchema: z.ZodObject<z.objectUtil.extendShape<{
654
727
  };
655
728
  seatsLeft: number | null;
656
729
  }[];
657
- bodyHtml: string;
658
- }, {
659
730
  slug: string;
660
731
  title: string;
661
732
  summary: string | null;
@@ -706,25 +777,10 @@ declare const publicEventDetailSchema: z.ZodObject<z.objectUtil.extendShape<{
706
777
  slug: string;
707
778
  name: string;
708
779
  } | null;
709
- sessions: {
710
- status: "SCHEDULED" | "CANCELLED" | "POSTPONED" | "RESCHEDULED" | "MOVED_ONLINE";
711
- startsAt: string;
712
- endsAt: string;
713
- statusNote: string | null;
714
- capacity: number | null;
715
- id: string;
716
- place: {
717
- streetAddress: string | null;
718
- locality: string | null;
719
- region: string | null;
720
- postalCode: string | null;
721
- country: string | null;
722
- onlineUrl: string | null;
723
- name: string | null;
724
- };
725
- seatsLeft: number | null;
726
- }[];
727
780
  bodyHtml: string;
781
+ signUp?: "EACH_DATE" | "ALL_DATES" | undefined;
782
+ pricing?: "FREE" | "DONATION" | undefined;
783
+ suggestedCents?: number | null | undefined;
728
784
  }>;
729
785
  declare const publicSeriesSchema: z.ZodObject<z.objectUtil.extendShape<{
730
786
  slug: z.ZodString;
@@ -756,6 +812,25 @@ declare const publicSeriesSchema: z.ZodObject<z.objectUtil.extendShape<{
756
812
  "EXTERNAL",
757
813
  "OURS"
758
814
  ]>;
815
+ /**
816
+ * EACH_DATE: a place is booked a date at a time. ALL_DATES: people sign up once for every date
817
+ * (`signUp` in the SDK), and each date's `capacity` and `seatsLeft` are the event's.
818
+ */
819
+ signUp: z.ZodDefault<z.ZodEnum<[
820
+ "EACH_DATE",
821
+ "ALL_DATES"
822
+ ]>>;
823
+ /**
824
+ * DONATION: booking a date takes a donation by card of at least `priceCents` a place —
825
+ * `register` with `card` and `amountCents`, the card box started with what `giving()`
826
+ * answers as `card`. FREE: nothing is taken, whatever `priceCents` shows.
827
+ */
828
+ pricing: z.ZodDefault<z.ZodEnum<[
829
+ "FREE",
830
+ "DONATION"
831
+ ]>>;
832
+ /** Where a DONATION's amount starts; null starts at `priceCents`. */
833
+ suggestedCents: z.ZodDefault<z.ZodNullable<z.ZodNumber>>;
759
834
  /** Where registering happens when `registration` is EXTERNAL. Null otherwise. */
760
835
  registrationUrl: z.ZodNullable<z.ZodString>;
761
836
  series: z.ZodNullable<z.ZodObject<{
@@ -889,6 +964,9 @@ declare const publicSeriesSchema: z.ZodObject<z.objectUtil.extendShape<{
889
964
  priceCents: number;
890
965
  priceCurrency: string;
891
966
  registration: "NONE" | "EXTERNAL" | "OURS";
967
+ signUp: "EACH_DATE" | "ALL_DATES";
968
+ pricing: "FREE" | "DONATION";
969
+ suggestedCents: number | null;
892
970
  cover: {
893
971
  alt: string;
894
972
  url: string;
@@ -958,6 +1036,9 @@ declare const publicSeriesSchema: z.ZodObject<z.objectUtil.extendShape<{
958
1036
  };
959
1037
  seatsLeft: number | null;
960
1038
  } | null;
1039
+ signUp?: "EACH_DATE" | "ALL_DATES" | undefined;
1040
+ pricing?: "FREE" | "DONATION" | undefined;
1041
+ suggestedCents?: number | null | undefined;
961
1042
  }>, "many">;
962
1043
  }>, "strip", z.ZodTypeAny, {
963
1044
  slug: string;
@@ -974,6 +1055,9 @@ declare const publicSeriesSchema: z.ZodObject<z.objectUtil.extendShape<{
974
1055
  priceCents: number;
975
1056
  priceCurrency: string;
976
1057
  registration: "NONE" | "EXTERNAL" | "OURS";
1058
+ signUp: "EACH_DATE" | "ALL_DATES";
1059
+ pricing: "FREE" | "DONATION";
1060
+ suggestedCents: number | null;
977
1061
  cover: {
978
1062
  alt: string;
979
1063
  url: string;
@@ -1048,6 +1132,9 @@ declare const publicSeriesSchema: z.ZodObject<z.objectUtil.extendShape<{
1048
1132
  };
1049
1133
  seatsLeft: number | null;
1050
1134
  } | null;
1135
+ signUp?: "EACH_DATE" | "ALL_DATES" | undefined;
1136
+ pricing?: "FREE" | "DONATION" | undefined;
1137
+ suggestedCents?: number | null | undefined;
1051
1138
  }[];
1052
1139
  }>;
1053
1140
  declare const publicSeriesListSchema: z.ZodObject<{
@@ -1088,6 +1175,16 @@ export type PublicSeriesList = z.infer<typeof publicSeriesListSchema>;
1088
1175
  export type PublicSession = z.infer<typeof publicSessionSchema>;
1089
1176
  export type PublicSessionRow = z.infer<typeof publicSessionRowSchema>;
1090
1177
  export type PublicEventDetail = z.infer<typeof publicEventDetailSchema>;
1178
+ declare const signedUpSchema: z.ZodObject<{
1179
+ status: z.ZodEnum<[
1180
+ "CONFIRMED",
1181
+ "WAITLISTED"
1182
+ ]>;
1183
+ }, "strip", z.ZodTypeAny, {
1184
+ status: "CONFIRMED" | "WAITLISTED";
1185
+ }, {
1186
+ status: "CONFIRMED" | "WAITLISTED";
1187
+ }>;
1091
1188
  declare const bookingSchema: z.ZodObject<{
1092
1189
  status: z.ZodEnum<[
1093
1190
  "CONFIRMED",
@@ -1392,14 +1489,14 @@ declare const givingAvailabilitySchema: z.ZodObject<{
1392
1489
  */
1393
1490
  monthly: z.ZodDefault<z.ZodBoolean>;
1394
1491
  }, "strip", z.ZodTypeAny, {
1395
- currency: string | null;
1396
- available: boolean;
1397
1492
  card: {
1398
1493
  provider: "square";
1399
1494
  applicationId: string;
1400
1495
  locationId: string;
1401
1496
  environment: "production" | "sandbox";
1402
1497
  } | null;
1498
+ currency: string | null;
1499
+ available: boolean;
1403
1500
  monthly: boolean;
1404
1501
  }, {
1405
1502
  currency: string | null;
@@ -1448,21 +1545,21 @@ declare const cardDonationInput: z.ZodObject<z.objectUtil.extendShape<Omit<{
1448
1545
  */
1449
1546
  verificationToken: z.ZodOptional<z.ZodString>;
1450
1547
  }>, "strict", z.ZodTypeAny, {
1451
- amountCents: number;
1452
1548
  sourceId: string;
1549
+ amountCents: number;
1453
1550
  name?: string | undefined;
1454
1551
  email?: string | undefined;
1552
+ verificationToken?: string | undefined;
1455
1553
  currency?: string | undefined;
1456
1554
  dedication?: string | undefined;
1457
- verificationToken?: string | undefined;
1458
1555
  }, {
1459
- amountCents: number;
1460
1556
  sourceId: string;
1557
+ amountCents: number;
1461
1558
  name?: string | undefined;
1462
1559
  email?: string | undefined;
1560
+ verificationToken?: string | undefined;
1463
1561
  currency?: string | undefined;
1464
1562
  dedication?: string | undefined;
1465
- verificationToken?: string | undefined;
1466
1563
  }>;
1467
1564
  export type CardDonationInput = z.infer<typeof cardDonationInput>;
1468
1565
  declare const cardDonationSchema: z.ZodObject<{
@@ -1504,19 +1601,19 @@ declare const monthlyDonationInput: z.ZodObject<z.objectUtil.extendShape<Omit<{
1504
1601
  }>, "strict", z.ZodTypeAny, {
1505
1602
  name: string;
1506
1603
  email: string;
1507
- amountCents: number;
1508
1604
  sourceId: string;
1605
+ amountCents: number;
1606
+ verificationToken?: string | undefined;
1509
1607
  currency?: string | undefined;
1510
1608
  dedication?: string | undefined;
1511
- verificationToken?: string | undefined;
1512
1609
  }, {
1513
1610
  name: string;
1514
1611
  email: string;
1515
- amountCents: number;
1516
1612
  sourceId: string;
1613
+ amountCents: number;
1614
+ verificationToken?: string | undefined;
1517
1615
  currency?: string | undefined;
1518
1616
  dedication?: string | undefined;
1519
- verificationToken?: string | undefined;
1520
1617
  }>;
1521
1618
  export type MonthlyDonationInput = z.infer<typeof monthlyDonationInput>;
1522
1619
  declare const monthlyStartedSchema: z.ZodObject<{
@@ -2130,14 +2227,40 @@ export declare function createClient({ baseUrl, tenant, fetch: given, revalidate
2130
2227
  * error, and a site that treated it as one would tell somebody their booking failed when
2131
2228
  * they are in fact next in line. **Check `status`.**
2132
2229
  *
2133
- * The `token` it returns is the person's only authority over the booking — they have no
2134
- * account — and it also reaches them by email.
2230
+ * The person's link to their booking reaches them by email, and only by email: the answer
2231
+ * carries no token (since 0.4.0). An address that had already booked the date is answered
2232
+ * as a newcomer would be — `status` is what a new booking gets now — and is sent an email
2233
+ * saying how things really stand, so this cannot be used to ask who has booked.
2234
+ *
2235
+ * A date whose event's `pricing` is DONATION takes `card` — the card box's token, the box
2236
+ * started with what `giving()` answers as `card` — and `amountCents`, at least the event's
2237
+ * `priceCents` for each place. The card is held, the place taken, and only then is the money
2238
+ * taken: a full date throws (`conflict`, 409) with nothing taken, never waitlisting; a
2239
+ * refused card throws `declined` (402) whose message is for the person. The confirmation
2240
+ * email is their receipt.
2135
2241
  */
2136
2242
  register(sessionId: string, who: {
2137
2243
  name: string;
2138
2244
  email: string;
2139
2245
  seats?: number;
2246
+ card?: {
2247
+ sourceId: string;
2248
+ verificationToken?: string;
2249
+ };
2250
+ amountCents?: number;
2140
2251
  }, { visitor }?: VisitorOptions): Promise<Taken>;
2252
+ /**
2253
+ * Signs somebody up once for every date of an event whose `signUp` is ALL_DATES — the
2254
+ * dates it has and any added later; booking one of its dates with `register` is refused.
2255
+ *
2256
+ * The same rules as `register`: WAITLISTED when it is full, **check `status`**; an address
2257
+ * already signed up is answered as a newcomer would be and emailed how things stand. The
2258
+ * email carries the person's own page, which is where they leave.
2259
+ */
2260
+ signUp(eventSlug: string, who: {
2261
+ name: string;
2262
+ email: string;
2263
+ }, { visitor }?: VisitorOptions): Promise<SignedUp>;
2141
2264
  /** One booking, by the token from its link. */
2142
2265
  booking(token: string): Promise<Booking>;
2143
2266
  /** Gives the place back. Whoever is next and fits is confirmed and written to at once. */
@@ -2196,17 +2319,15 @@ declare const takenSchema: z.ZodObject<{
2196
2319
  "WAITLISTED"
2197
2320
  ]>;
2198
2321
  seats: z.ZodNumber;
2199
- token: z.ZodString;
2200
2322
  }, "strip", z.ZodTypeAny, {
2201
2323
  status: "CONFIRMED" | "WAITLISTED";
2202
2324
  seats: number;
2203
- token: string;
2204
2325
  }, {
2205
2326
  status: "CONFIRMED" | "WAITLISTED";
2206
2327
  seats: number;
2207
- token: string;
2208
2328
  }>;
2209
2329
  export type Taken = z.infer<typeof takenSchema>;
2330
+ export type SignedUp = z.infer<typeof signedUpSchema>;
2210
2331
  /**
2211
2332
  * One session as `schema.org/Event`, ready for a `<script type="application/ld+json">`.
2212
2333
  *
package/dist/index.js CHANGED
@@ -43,30 +43,38 @@ var nodeSchema = z.lazy(
43
43
  ])
44
44
  );
45
45
  var MAX_DEPTH = 100;
46
- function exceedsDepth(value) {
47
- if (typeof value !== "object" || value === null) return false;
46
+ var MAX_NODES = 5e4;
47
+ function outOfBounds(value) {
48
+ if (typeof value !== "object" || value === null) return null;
48
49
  const root = value.content;
49
50
  const stack = [{ list: root, depth: 1 }];
51
+ let count = 0;
50
52
  while (stack.length > 0) {
51
53
  const item = stack.pop();
52
54
  if (item === void 0 || !Array.isArray(item.list)) continue;
53
- if (item.depth > MAX_DEPTH) return true;
55
+ if (item.depth > MAX_DEPTH) return `document nesting exceeds ${MAX_DEPTH} levels`;
56
+ count += item.list.length;
57
+ if (count > MAX_NODES) return `document has more than ${MAX_NODES} nodes and marks`;
54
58
  for (const child of item.list) {
55
59
  if (typeof child === "object" && child !== null) {
60
+ const marks = child.marks;
61
+ if (Array.isArray(marks)) {
62
+ count += marks.length;
63
+ if (count > MAX_NODES) return `document has more than ${MAX_NODES} nodes and marks`;
64
+ }
56
65
  stack.push({ list: child.content, depth: item.depth + 1 });
57
66
  }
58
67
  }
59
68
  }
60
- return false;
69
+ return null;
61
70
  }
62
71
  var docShape = z.object({
63
72
  type: z.literal("doc"),
64
73
  content: z.array(nodeSchema)
65
74
  });
66
75
  var docSchema = z.unknown().superRefine((value, ctx) => {
67
- if (exceedsDepth(value)) {
68
- ctx.addIssue({ code: z.ZodIssueCode.custom, message: `document nesting exceeds ${MAX_DEPTH} levels` });
69
- }
76
+ const refused = outOfBounds(value);
77
+ if (refused !== null) ctx.addIssue({ code: z.ZodIssueCode.custom, message: refused });
70
78
  }).pipe(docShape);
71
79
  var objectBody = { required_error: "A JSON object body is required", invalid_type_error: "The body must be a JSON object" };
72
80
  var EVENT_CATEGORIES = ["MEDITATION", "RETREAT", "DHAMMA_CLASS", "CEREMONY", "OTHER"];
@@ -138,6 +146,12 @@ z.object({
138
146
  }, objectBody).strict();
139
147
  sessionInput.innerType().partial().extend({ tell: tellSchema.optional() }).strict();
140
148
  z.object({ tell: tellSchema.optional() }, objectBody).strict();
149
+ z.object({ tell: z.boolean() }, objectBody).strict();
150
+ var onlineViaSchema = z.enum(["LINK", "ZOOM"]);
151
+ var signUpModeSchema = z.enum(["EACH_DATE", "ALL_DATES"]);
152
+ var eventPricingSchema = z.enum(["FREE", "DONATION"]);
153
+ var eventCapacitySchema = z.number().int().min(1).max(1e6).nullable();
154
+ z.object({ sessions: z.array(sessionInput).min(1).max(100) }, objectBody).strict();
141
155
  var eventFields = {
142
156
  slug: eventSlugSchema,
143
157
  title: eventTitleSchema,
@@ -147,6 +161,8 @@ var eventFields = {
147
161
  coverAssetId: z.string().min(1).max(64).nullable().optional(),
148
162
  category: eventCategorySchema.optional(),
149
163
  attendance: attendanceModeSchema.optional(),
164
+ /** LINK: each date's own published link. ZOOM: a meeting per date in the monastery's Zoom. */
165
+ onlineVia: onlineViaSchema.optional(),
150
166
  timezone: timezoneSchema,
151
167
  /** Display only — the badge reading "MONTHLY". The dates that exist are the sessions. */
152
168
  recurrenceLabel: text(60).nullable().optional(),
@@ -156,7 +172,12 @@ var eventFields = {
156
172
  priceCents: priceCentsSchema.optional(),
157
173
  priceCurrency: currencySchema.optional(),
158
174
  registration: registrationModeSchema.optional(),
159
- externalRegistrationUrl: z.string().url().max(2e3).nullable().optional()
175
+ externalRegistrationUrl: z.string().url().max(2e3).nullable().optional(),
176
+ signUp: signUpModeSchema.optional(),
177
+ capacity: eventCapacitySchema.optional(),
178
+ pricing: eventPricingSchema.optional(),
179
+ /** Where a DONATION event's amount starts; null starts at the least. */
180
+ suggestedCents: priceCentsSchema.nullable().optional()
160
181
  };
161
182
  var registrationIsReachable = (v) => v.registration !== "EXTERNAL" || (v.externalRegistrationUrl ?? "") !== "";
162
183
  var REGISTRATION_ISSUE = {
@@ -173,6 +194,8 @@ z.object({
173
194
  coverAssetId: z.string().min(1).max(64).nullable().optional(),
174
195
  category: eventCategorySchema.optional(),
175
196
  attendance: attendanceModeSchema.optional(),
197
+ /** LINK: each date's own published link. ZOOM: a meeting per date in the monastery's Zoom. */
198
+ onlineVia: onlineViaSchema.optional(),
176
199
  timezone: timezoneSchema.optional(),
177
200
  recurrenceLabel: text(60).nullable().optional(),
178
201
  teacherName: text(200).nullable().optional(),
@@ -182,6 +205,11 @@ z.object({
182
205
  priceCurrency: currencySchema.optional(),
183
206
  registration: registrationModeSchema.optional(),
184
207
  externalRegistrationUrl: z.string().url().max(2e3).nullable().optional(),
208
+ signUp: signUpModeSchema.optional(),
209
+ capacity: eventCapacitySchema.optional(),
210
+ pricing: eventPricingSchema.optional(),
211
+ /** Where a DONATION event's amount starts; null starts at the least. */
212
+ suggestedCents: priceCentsSchema.nullable().optional(),
185
213
  /** The whole running order at once: a list is a set, not a delta. Omitted leaves it alone. */
186
214
  segments: z.array(segmentInput).max(50).optional(),
187
215
  /**
@@ -325,6 +353,19 @@ var publicEventSummarySchema = z.object({
325
353
  priceCents: z.number().int(),
326
354
  priceCurrency: z.string(),
327
355
  registration: registrationModeSchema,
356
+ /**
357
+ * EACH_DATE: a place is booked a date at a time. ALL_DATES: people sign up once for every date
358
+ * (`signUp` in the SDK), and each date's `capacity` and `seatsLeft` are the event's.
359
+ */
360
+ signUp: z.enum(["EACH_DATE", "ALL_DATES"]).default("EACH_DATE"),
361
+ /**
362
+ * DONATION: booking a date takes a donation by card of at least `priceCents` a place —
363
+ * `register` with `card` and `amountCents`, the card box started with what `giving()`
364
+ * answers as `card`. FREE: nothing is taken, whatever `priceCents` shows.
365
+ */
366
+ pricing: z.enum(["FREE", "DONATION"]).default("FREE"),
367
+ /** Where a DONATION's amount starts; null starts at `priceCents`. */
368
+ suggestedCents: z.number().int().nullable().default(null),
328
369
  /** Where registering happens when `registration` is EXTERNAL. Null otherwise. */
329
370
  registrationUrl: z.string().nullable(),
330
371
  series: publicSeriesRefSchema.nullable(),
@@ -362,8 +403,23 @@ var registerInput = z.object({
362
403
  name: z.string().trim().min(1, "A name is needed").max(200),
363
404
  email: z.string().trim().email("That does not look like an email address").max(320),
364
405
  /** Them plus anyone they are bringing. Capacity counts seats, not bookings. */
365
- seats: z.number().int().min(1).max(20).optional()
406
+ seats: z.number().int().min(1).max(20).optional(),
407
+ /**
408
+ * For a DONATION event: the card box's one-use token, held for the booking and taken only
409
+ * once the place is (never stored), with the bank's confirmation where it asked for one.
410
+ */
411
+ card: z.object({
412
+ sourceId: z.string().min(1).max(2e3).regex(/^\S+$/, "That is not a card box's token"),
413
+ verificationToken: z.string().min(1).max(4e3).regex(/^\S+$/, "That is not a verification token").optional()
414
+ }).strict().optional(),
415
+ /** What they give, in minor units: at least the event's `priceCents` for each place. */
416
+ amountCents: z.number().int().min(1).max(1e8).optional()
366
417
  }).strict();
418
+ var signUpInput = z.object({
419
+ name: z.string().trim().min(1, "A name is needed").max(200),
420
+ email: z.string().trim().email("That does not look like an email address").max(320)
421
+ }).strict();
422
+ var signedUpSchema = z.object({ status: z.enum(["CONFIRMED", "WAITLISTED"]) });
367
423
  var bookingSchema = z.object({
368
424
  status: z.enum(["CONFIRMED", "WAITLISTED", "CANCELLED"]),
369
425
  seats: z.number().int(),
@@ -628,8 +684,17 @@ function createClient({ baseUrl = DEFAULT_BASE_URL, tenant, fetch: given, revali
628
684
  * error, and a site that treated it as one would tell somebody their booking failed when
629
685
  * they are in fact next in line. **Check `status`.**
630
686
  *
631
- * The `token` it returns is the person's only authority over the booking — they have no
632
- * account — and it also reaches them by email.
687
+ * The person's link to their booking reaches them by email, and only by email: the answer
688
+ * carries no token (since 0.4.0). An address that had already booked the date is answered
689
+ * as a newcomer would be — `status` is what a new booking gets now — and is sent an email
690
+ * saying how things really stand, so this cannot be used to ask who has booked.
691
+ *
692
+ * A date whose event's `pricing` is DONATION takes `card` — the card box's token, the box
693
+ * started with what `giving()` answers as `card` — and `amountCents`, at least the event's
694
+ * `priceCents` for each place. The card is held, the place taken, and only then is the money
695
+ * taken: a full date throws (`conflict`, 409) with nothing taken, never waitlisting; a
696
+ * refused card throws `declined` (402) whose message is for the person. The confirmation
697
+ * email is their receipt.
633
698
  */
634
699
  async register(sessionId, who, { visitor } = {}) {
635
700
  const input = registerInput.safeParse(who);
@@ -641,6 +706,24 @@ function createClient({ baseUrl = DEFAULT_BASE_URL, tenant, fetch: given, revali
641
706
  if (!parsed.success) throw new MwamError("unexpected_shape", shapeProblem(parsed.error.issues));
642
707
  return parsed.data;
643
708
  },
709
+ /**
710
+ * Signs somebody up once for every date of an event whose `signUp` is ALL_DATES — the
711
+ * dates it has and any added later; booking one of its dates with `register` is refused.
712
+ *
713
+ * The same rules as `register`: WAITLISTED when it is full, **check `status`**; an address
714
+ * already signed up is answered as a newcomer would be and emailed how things stand. The
715
+ * email carries the person's own page, which is where they leave.
716
+ */
717
+ async signUp(eventSlug, who, { visitor } = {}) {
718
+ const input = signUpInput.safeParse(who);
719
+ if (!input.success) throw new MwamError("invalid", shapeProblem(input.error.issues));
720
+ const parsed = signedUpSchema.safeParse(await read(`/events/${encodeURIComponent(eventSlug)}/sign-up`, {}, {
721
+ method: "POST",
722
+ body: JSON.stringify(input.data)
723
+ }, visitor));
724
+ if (!parsed.success) throw new MwamError("unexpected_shape", shapeProblem(parsed.error.issues));
725
+ return parsed.data;
726
+ },
644
727
  /** One booking, by the token from its link. */
645
728
  async booking(token) {
646
729
  const parsed = bookingSchema.safeParse(await read(`/bookings/${encodeURIComponent(token)}`));
@@ -733,8 +816,7 @@ function createClient({ baseUrl = DEFAULT_BASE_URL, tenant, fetch: given, revali
733
816
  var postFormats = z.array(z.enum(POST_BODY_FORMATS)).min(1).optional();
734
817
  var takenSchema = z.object({
735
818
  status: z.enum(["CONFIRMED", "WAITLISTED"]),
736
- seats: z.number().int(),
737
- token: z.string()
819
+ seats: z.number().int()
738
820
  });
739
821
  var shapeProblem = (issues) => {
740
822
  const first = issues[0];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mwam/sdk",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Read a monastery's blog, events, series and galleries from mwam-apps, and book and give through it.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {