@ordinatio/scheduling-api 0.1.0 → 0.3.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/dist/index.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  BookingPageConfigSchema,
3
3
  BookingPageThemeSchema,
4
+ BrandSchema,
4
5
  CancelRecurringScopeSchema,
5
6
  CancelRecurringSeriesSchema,
6
7
  CreateAppointmentCategorySchema,
@@ -11,6 +12,7 @@ import {
11
12
  CreateNotificationTemplateSchema,
12
13
  CreatePackagePurchaseSchema,
13
14
  CreateRecurringSeriesSchema,
15
+ CreateRoutingFormSchema,
14
16
  CreateServicePackageSchema,
15
17
  CreateWebhookEndpointSchema,
16
18
  DEFAULT_CANCELLATION_POLICY,
@@ -19,9 +21,13 @@ import {
19
21
  NotificationChannelSchema,
20
22
  NotificationTriggerSchema,
21
23
  OrgCancellationPolicySchema,
24
+ PrivacyEraseSchema,
25
+ PrivacySubjectSchema,
22
26
  RecurringFrequencySchema,
27
+ RouteClientSchema,
23
28
  SLOT_GRANULARITY_DEFAULT,
24
29
  SLOT_GRANULARITY_OPTIONS,
30
+ TestRoutingFormSchema,
25
31
  UpdateAppointmentCategorySchema,
26
32
  UpdateAppointmentTypeSchema,
27
33
  UpdateBookingPageSchema,
@@ -29,8 +35,12 @@ import {
29
35
  UpdateCouponCodeSchema,
30
36
  UpdateNotificationTemplateSchema,
31
37
  UpdatePackagePurchaseSchema,
38
+ UpdateRoutingFormSchema,
32
39
  UpdateServicePackageSchema
33
- } from "./chunk-IAQBLF5F.mjs";
40
+ } from "./chunk-MQO3VRMU.mjs";
41
+
42
+ // src/create-api.ts
43
+ import * as engine from "@ordinatio/scheduling";
34
44
 
35
45
  // src/cors.ts
36
46
  function defaultCorsHeaders() {
@@ -253,6 +263,85 @@ function withWebhooks(inner, host) {
253
263
  };
254
264
  }
255
265
 
266
+ // src/waitlist/announce-offer.ts
267
+ import { enqueueWebhookEvent, tryOfferFreedSlot } from "@ordinatio/scheduling";
268
+ async function offerAndAnnounce(host, settings, db, slot) {
269
+ const offer = await tryOfferFreedSlot(db, { ...slot, offerMinutes: settings.offerMinutes });
270
+ if (!offer) return false;
271
+ const details = {
272
+ organizationId: slot.organizationId,
273
+ token: offer.token,
274
+ clientName: offer.entry.clientName,
275
+ clientEmail: offer.entry.clientEmail,
276
+ clientPhone: offer.entry.clientPhone,
277
+ typeName: offer.typeName,
278
+ calendarName: offer.calendarName,
279
+ startTime: offer.startTime,
280
+ timezone: offer.timezone,
281
+ expiresAt: offer.expiresAt
282
+ };
283
+ if (settings.notify) {
284
+ try {
285
+ await settings.notify(details);
286
+ } catch (error) {
287
+ console.error("[waitlist] the host could not send the offer; it stays open until it expires:", error);
288
+ }
289
+ }
290
+ if (host.webhooks) {
291
+ try {
292
+ await enqueueWebhookEvent(db, {
293
+ organizationId: slot.organizationId,
294
+ type: "waitlist.offered",
295
+ // Each offering has its own id, so offering the same slot to the same person again still reaches subscribers.
296
+ eventId: `waitlist_offer_${offer.entry.id}_${offer.startTime.getTime()}_${offer.expiresAt.getTime()}`,
297
+ data: {
298
+ offer: {
299
+ entryId: offer.entry.id,
300
+ token: offer.token,
301
+ clientName: details.clientName,
302
+ clientEmail: details.clientEmail,
303
+ clientPhone: details.clientPhone,
304
+ typeName: details.typeName,
305
+ calendarName: details.calendarName,
306
+ calendarId: offer.calendarId,
307
+ startTime: offer.startTime.toISOString(),
308
+ expiresAt: offer.expiresAt.toISOString()
309
+ }
310
+ }
311
+ });
312
+ } catch (error) {
313
+ console.error("[waitlist] could not queue the waitlist.offered webhook:", error);
314
+ }
315
+ }
316
+ return true;
317
+ }
318
+
319
+ // src/waitlist/waitlist-events.ts
320
+ var FREED_BY = /* @__PURE__ */ new Set(["appointment.cancelled", "appointment.rejected", "appointment.updated"]);
321
+ function withWaitlist(inner, host) {
322
+ return {
323
+ async emit(organizationId, type, data) {
324
+ const appointmentId = data.appointmentId;
325
+ if (host.waitlist && FREED_BY.has(type) && typeof appointmentId === "string") {
326
+ try {
327
+ const db = await host.tenantDb(organizationId, "waitlist");
328
+ const appointment = db ? await db.appointment.findUnique({
329
+ where: { id: appointmentId },
330
+ select: { calendarId: true, startTime: true, rescheduledFrom: true, status: true, calendar: { select: { organizationId: true } } }
331
+ }) : null;
332
+ if (db && appointment && (appointment.calendar.organizationId ?? organizationId) === organizationId) {
333
+ const freed = type === "appointment.updated" ? appointment.rescheduledFrom : appointment.status === "CANCELLED" ? appointment.startTime : null;
334
+ if (freed) await offerAndAnnounce(host, host.waitlist, db, { organizationId, calendarId: appointment.calendarId, startTime: freed });
335
+ }
336
+ } catch (error) {
337
+ console.error("[scheduling-api] could not offer a freed slot to the waitlist:", error);
338
+ }
339
+ }
340
+ await inner.emit(organizationId, type, data);
341
+ }
342
+ };
343
+ }
344
+
256
345
  // src/handlers/manage-cancel.ts
257
346
  import { schedError as schedError3 } from "@ordinatio/scheduling";
258
347
 
@@ -381,7 +470,7 @@ async function cancelViaToken(host, db, organizationId, appointment) {
381
470
  const baseUrl = host.appUrl();
382
471
  if (baseUrl) {
383
472
  try {
384
- await queueStaffNotification(db, appointment.id, "CANCELLATION", baseUrl);
473
+ await queueStaffNotification(db, appointment.id, "CANCELLATION", baseUrl, { brand: Boolean(host.brand) });
385
474
  } catch (staffError) {
386
475
  const diagnostic = schedError2("SCHED_607", { error: staffError, appointmentId: appointment.id });
387
476
  console.error("[DELETE /manage]", diagnostic.ref, staffError instanceof Error ? staffError.message : staffError);
@@ -546,19 +635,19 @@ async function rescheduleViaToken(host, db, organizationId, appointment, newTime
546
635
  );
547
636
  const baseUrl = host.appUrl() ?? void 0;
548
637
  if (baseUrl) {
549
- await queueImmediateNotification(db, appointment.id, "RESCHEDULE", baseUrl);
638
+ await queueImmediateNotification(db, appointment.id, "RESCHEDULE", baseUrl, { brand: Boolean(host.brand) });
550
639
  } else {
551
640
  console.warn("[manage] no appUrl \u2014 RESCHEDULE notification skipped");
552
641
  }
553
642
  try {
554
- await scheduleNotifications(db, appointment.id, baseUrl, { excludeTriggers: ["CONFIRMATION"] });
643
+ await scheduleNotifications(db, appointment.id, baseUrl, { excludeTriggers: ["CONFIRMATION"], brand: Boolean(host.brand) });
555
644
  } catch (error) {
556
645
  const diagnostic = schedError5("SCHED_604", { error, appointmentId: appointment.id });
557
646
  console.error("[PATCH /manage] scheduleNotifications failed (non-blocking):", diagnostic.ref, error instanceof Error ? error.message : error);
558
647
  }
559
648
  if (baseUrl) {
560
649
  try {
561
- await queueStaffNotification2(db, appointment.id, "RESCHEDULE", baseUrl);
650
+ await queueStaffNotification2(db, appointment.id, "RESCHEDULE", baseUrl, { brand: Boolean(host.brand) });
562
651
  } catch (staffError) {
563
652
  const diagnostic = schedError5("SCHED_607", { error: staffError, appointmentId: appointment.id });
564
653
  console.error("[PATCH /manage]", diagnostic.ref, staffError instanceof Error ? staffError.message : staffError);
@@ -945,7 +1034,7 @@ async function cancelByStaff(request, { host, params }) {
945
1034
  const baseUrl = host.appUrl();
946
1035
  if (baseUrl) {
947
1036
  try {
948
- await queueStaffNotification3(db, id, "CANCELLATION", baseUrl);
1037
+ await queueStaffNotification3(db, id, "CANCELLATION", baseUrl, { brand: Boolean(host.brand) });
949
1038
  } catch (error) {
950
1039
  await host.activity.log(db, {
951
1040
  action: "scheduling.staff_notification_failed",
@@ -1260,7 +1349,7 @@ async function cancelFromCalendarSync(request, { host, params }) {
1260
1349
  await host.workerCommands.queue(source === "google" ? "delete-from-outlook" : "delete-from-google", { appointmentId: id });
1261
1350
  const baseUrl = host.appUrl();
1262
1351
  if (baseUrl) {
1263
- await queueImmediateNotification2(db, id, "CANCELLATION", baseUrl).catch(
1352
+ await queueImmediateNotification2(db, id, "CANCELLATION", baseUrl, { brand: Boolean(host.brand) }).catch(
1264
1353
  (err) => console.warn("[cancel-sync] Failed to queue cancellation notification:", id, err instanceof Error ? err.message : err)
1265
1354
  );
1266
1355
  }
@@ -1366,7 +1455,7 @@ async function approveOrReject(request, { host, params }) {
1366
1455
  await cancelPendingNotifications(db, id);
1367
1456
  const baseUrl = host.appUrl();
1368
1457
  if (!baseUrl) throw new Error("NEXT_PUBLIC_APP_URL is required");
1369
- await scheduleNotifications2(db, id, baseUrl);
1458
+ await scheduleNotifications2(db, id, baseUrl, { brand: Boolean(host.brand) });
1370
1459
  await host.availabilityCache.invalidate(appointment.calendarId);
1371
1460
  await host.events.emit(organizationId, "appointment.confirmed", { appointmentId: id });
1372
1461
  await host.activity.log(db, {
@@ -1429,14 +1518,14 @@ async function rescheduleByStaff(request, { host, params }) {
1429
1518
  });
1430
1519
  const baseUrl = host.appUrl();
1431
1520
  if (!baseUrl) throw new Error("NEXT_PUBLIC_APP_URL is required");
1432
- await queueImmediateNotification3(db, id, "RESCHEDULE", baseUrl);
1521
+ await queueImmediateNotification3(db, id, "RESCHEDULE", baseUrl, { brand: Boolean(host.brand) });
1433
1522
  try {
1434
- await scheduleNotifications3(db, id, baseUrl, { excludeTriggers: ["CONFIRMATION"] });
1523
+ await scheduleNotifications3(db, id, baseUrl, { excludeTriggers: ["CONFIRMATION"], brand: Boolean(host.brand) });
1435
1524
  } catch (error) {
1436
1525
  console.warn("[reschedule] scheduleNotifications failed:", error instanceof Error ? error.message : error);
1437
1526
  }
1438
1527
  try {
1439
- await queueStaffNotification4(db, id, "RESCHEDULE", baseUrl);
1528
+ await queueStaffNotification4(db, id, "RESCHEDULE", baseUrl, { brand: Boolean(host.brand) });
1440
1529
  } catch (error) {
1441
1530
  await host.activity.log(db, {
1442
1531
  action: "scheduling.staff_notification_failed",
@@ -1702,10 +1791,10 @@ async function listNotifications(request, { host, params }) {
1702
1791
  noRateLimit: true
1703
1792
  });
1704
1793
  if (staff instanceof Response) return staff;
1705
- const { db } = staff;
1794
+ const { db, organizationId } = staff;
1706
1795
  const { id } = params;
1707
1796
  if (!await staff.canSeeAppointment(id)) return NOT_FOUND3();
1708
- const appointment = await db.appointment.findUnique({ where: { id }, select: { id: true } });
1797
+ const appointment = await verifyAppointmentOwnership(db, id, organizationId);
1709
1798
  if (!appointment) return NOT_FOUND3();
1710
1799
  const notifications = await db.scheduledNotification.findMany({
1711
1800
  where: { appointmentId: id },
@@ -3337,7 +3426,7 @@ async function listGroupSessions(request, { host }) {
3337
3426
  }
3338
3427
  const calendarId = params.get("calendarId") || void 0;
3339
3428
  const visibleCalendarIds = await staff.visibleCalendarIds();
3340
- const { sessions, hasMore } = await getGroupSessions(staff.db, { startDate, endDate, calendarId, visibleCalendarIds });
3429
+ const { sessions, hasMore } = await getGroupSessions(staff.db, { startDate, endDate, calendarId, visibleCalendarIds, organizationId: staff.organizationId });
3341
3430
  return Response.json({ sessions, total: sessions.length, hasMore });
3342
3431
  } catch (error) {
3343
3432
  const err = schedError18("SCHED_311", { error });
@@ -3419,7 +3508,7 @@ async function runSeriesSideEffects(host, db, organizationId, seriesId, client)
3419
3508
  const sendConfirmation = async (url, appointmentId) => {
3420
3509
  for (let tryNumber = 1; tryNumber <= 2; tryNumber += 1) {
3421
3510
  try {
3422
- await scheduleNotifications4(db, appointmentId, url);
3511
+ await scheduleNotifications4(db, appointmentId, url, { brand: Boolean(host.brand) });
3423
3512
  return;
3424
3513
  } catch (error) {
3425
3514
  if (tryNumber === 2) record("Client confirmation", error);
@@ -3431,10 +3520,9 @@ async function runSeriesSideEffects(host, db, organizationId, seriesId, client)
3431
3520
  if (visit === confirmationVisit) {
3432
3521
  await sendConfirmation(baseUrl, visit.id);
3433
3522
  } else {
3434
- await attempt(
3435
- "Client notices",
3436
- () => scheduleNotifications4(db, visit.id, baseUrl, { excludeTriggers: ["CONFIRMATION"] })
3437
- );
3523
+ await attempt("Client notices", async () => {
3524
+ await scheduleNotifications4(db, visit.id, baseUrl, { excludeTriggers: ["CONFIRMATION"], brand: Boolean(host.brand) });
3525
+ });
3438
3526
  }
3439
3527
  }
3440
3528
  await attempt(
@@ -3453,7 +3541,7 @@ async function runSeriesSideEffects(host, db, organizationId, seriesId, client)
3453
3541
  await Promise.all(visits.slice(from, from + VISITS_PER_GROUP).map(handleVisit));
3454
3542
  }
3455
3543
  if (baseUrl && confirmationVisit) {
3456
- await attempt("Staff alert", () => queueStaffNotification5(db, confirmationVisit.id, "CONFIRMATION", baseUrl));
3544
+ await attempt("Staff alert", () => queueStaffNotification5(db, confirmationVisit.id, "CONFIRMATION", baseUrl, { brand: Boolean(host.brand) }));
3457
3545
  }
3458
3546
  await attempt("Availability cache", () => host.availabilityCache.invalidate(first.calendarId));
3459
3547
  await attempt(
@@ -3683,7 +3771,7 @@ async function runSeriesCancelSideEffects(host, db, organizationId, seriesId, se
3683
3771
  }
3684
3772
  const baseUrl = host.appUrl()?.trim();
3685
3773
  if (baseUrl) {
3686
- await attempt("Staff notice", () => queueStaffNotification6(db, occurrences[0].id, "CANCELLATION", baseUrl));
3774
+ await attempt("Staff notice", () => queueStaffNotification6(db, occurrences[0].id, "CANCELLATION", baseUrl, { brand: Boolean(host.brand) }));
3687
3775
  } else {
3688
3776
  record("Staff notice", "skipped because the application address is not set");
3689
3777
  }
@@ -3870,7 +3958,7 @@ async function getAnalytics(request, { host }) {
3870
3958
  }
3871
3959
  }
3872
3960
  const visibleCalendarIds = await staff.visibleCalendarIds();
3873
- const analytics = await getBookingAnalytics(staff.db, { days, calendarId, visibleCalendarIds });
3961
+ const analytics = await getBookingAnalytics(staff.db, { days, calendarId, visibleCalendarIds, organizationId: staff.organizationId });
3874
3962
  return Response.json(analytics);
3875
3963
  } catch (error) {
3876
3964
  const ref = getErrorRef(error);
@@ -3888,6 +3976,36 @@ function escapeHtml(text) {
3888
3976
  return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
3889
3977
  }
3890
3978
 
3979
+ // src/brand/brand-http.ts
3980
+ import { getBrand, SchedulingValidationError as SchedulingValidationError4 } from "@ordinatio/scheduling";
3981
+ var NOT_ENABLED = { error: "Branding is not enabled on this server" };
3982
+ function brandErrorResponse(error, fallback, cors) {
3983
+ const send = (payload, status) => cors ? corsJson(cors, payload, { status }) : Response.json(payload, { status });
3984
+ if (error instanceof SchedulingValidationError4) {
3985
+ const details = error.context.errors;
3986
+ return send({ error: error.message, code: error.code, ref: getErrorRef(error), ...details ? { details } : {} }, 400);
3987
+ }
3988
+ console.error("[brand]", error);
3989
+ return send({ error: fallback }, 500);
3990
+ }
3991
+ async function requireBrandAdmin(host, request, options) {
3992
+ const staff = await requireAdminStaff(host, request, options);
3993
+ if (staff instanceof Response) return staff;
3994
+ if (!host.brand) return Response.json(NOT_ENABLED, { status: 501 });
3995
+ return staff;
3996
+ }
3997
+ async function businessName(host, db, organizationId) {
3998
+ if (host.brand) {
3999
+ try {
4000
+ const brand = await getBrand(db, organizationId);
4001
+ if (brand) return brand.displayName;
4002
+ } catch (error) {
4003
+ console.error("[brand] could not read the brand for a message:", error);
4004
+ }
4005
+ }
4006
+ return host.appName() || null;
4007
+ }
4008
+
3891
4009
  // src/handlers/appointment-messages.ts
3892
4010
  var NOT_FOUND4 = () => Response.json({ error: "Appointment not found" }, { status: 404 });
3893
4011
  function failure2(label, error, fallback) {
@@ -3928,7 +4046,7 @@ async function sendFollowup(request, { host, params }) {
3928
4046
  { status: 400 }
3929
4047
  );
3930
4048
  }
3931
- const staffName = appointment.calendar.staffName || host.appName() || "Your provider";
4049
+ const staffName = appointment.calendar.staffName || await businessName(host, db, organizationId) || "Your provider";
3932
4050
  const serviceName = appointment.type.name;
3933
4051
  await db.scheduledNotification.deleteMany({
3934
4052
  where: { appointmentId: id, trigger: "FOLLOWUP_MANUAL", status: "PENDING" }
@@ -3999,6 +4117,7 @@ async function sendReminder(request, { host, params }) {
3999
4117
  month: "long",
4000
4118
  day: "numeric"
4001
4119
  }) + " at " + time;
4120
+ const providerName = appointment.calendar.staffName || await businessName(host, db, organizationId);
4002
4121
  await db.scheduledNotification.deleteMany({
4003
4122
  where: { appointmentId: id, trigger: "REMINDER_MANUAL", status: "PENDING" }
4004
4123
  });
@@ -4009,7 +4128,7 @@ async function sendReminder(request, { host, params }) {
4009
4128
  channel: "SMS",
4010
4129
  trigger: "REMINDER_MANUAL",
4011
4130
  recipient: appointment.clientPhone,
4012
- body: `Reminder: Your ${appointment.type.name} with ${appointment.calendar.staffName || host.appName() || "your provider"} is on ${dateTime}.`,
4131
+ body: `Reminder: Your ${appointment.type.name} with ${providerName || "your provider"} is on ${dateTime}.`,
4013
4132
  scheduledFor: /* @__PURE__ */ new Date()
4014
4133
  }
4015
4134
  });
@@ -4030,7 +4149,7 @@ Date: ${dateTime}
4030
4149
 
4031
4150
  We look forward to seeing you!
4032
4151
 
4033
- \u2014 ${escapeHtml(appointment.calendar.staffName || host.appName() || "Your provider")}`,
4152
+ \u2014 ${escapeHtml(providerName || "Your provider")}`,
4034
4153
  scheduledFor: /* @__PURE__ */ new Date()
4035
4154
  }
4036
4155
  });
@@ -4474,7 +4593,7 @@ async function getLocationRecents(request, { host, params }) {
4474
4593
  }
4475
4594
 
4476
4595
  // src/handlers/admin-availability-rules.ts
4477
- import { listAvailabilityRules, SchedulingValidationError as SchedulingValidationError4, setWeeklyAvailability } from "@ordinatio/scheduling";
4596
+ import { listAvailabilityRules, SchedulingValidationError as SchedulingValidationError5, setWeeklyAvailability } from "@ordinatio/scheduling";
4478
4597
 
4479
4598
  // src/availability/admin-calendar.ts
4480
4599
  async function verifyCalendar(db, calendarId, organizationId) {
@@ -4568,7 +4687,7 @@ async function setWeeklyRules(request, { host, params }) {
4568
4687
  return Response.json(created);
4569
4688
  } catch (error) {
4570
4689
  const msg = getErrorMessage(error, "Failed to update availability");
4571
- if (error instanceof SchedulingValidationError4) {
4690
+ if (error instanceof SchedulingValidationError5) {
4572
4691
  console.error("[PUT /admin/availability]", error.ref, error.code, error.context);
4573
4692
  return Response.json({ error: msg, ref: error.ref }, { status: 400 });
4574
4693
  }
@@ -4582,7 +4701,7 @@ import {
4582
4701
  addTimeBlock,
4583
4702
  removeDateOverride,
4584
4703
  SchedulingNotFoundError as SchedulingNotFoundError5,
4585
- SchedulingValidationError as SchedulingValidationError5
4704
+ SchedulingValidationError as SchedulingValidationError6
4586
4705
  } from "@ordinatio/scheduling";
4587
4706
 
4588
4707
  // src/availability/override-helpers.ts
@@ -4667,7 +4786,7 @@ async function addOverride(request, { host, params }) {
4667
4786
  return Response.json({ ...override, ...overlapWarning && { warning: overlapWarning } }, { status: 201 });
4668
4787
  } catch (error) {
4669
4788
  const msg = getErrorMessage(error, "Failed to add override");
4670
- if (error instanceof SchedulingValidationError5) {
4789
+ if (error instanceof SchedulingValidationError6) {
4671
4790
  console.error("[POST /admin/availability]", error.ref, error.code, error.context);
4672
4791
  return Response.json({ error: msg, ref: error.ref }, { status: 400 });
4673
4792
  }
@@ -4778,7 +4897,7 @@ async function createTemplate(request, { host }) {
4778
4897
  }
4779
4898
 
4780
4899
  // src/handlers/admin-template-update.ts
4781
- import { deleteNotificationTemplate, SchedulingNotFoundError as SchedulingNotFoundError6, SchedulingValidationError as SchedulingValidationError6, updateNotificationTemplate } from "@ordinatio/scheduling";
4900
+ import { deleteNotificationTemplate, SchedulingNotFoundError as SchedulingNotFoundError6, SchedulingValidationError as SchedulingValidationError7, updateNotificationTemplate } from "@ordinatio/scheduling";
4782
4901
  async function updateTemplate(request, { host, params }) {
4783
4902
  try {
4784
4903
  const staff = await requireAdminStaff(host, request, { action: "admin-templates-update", tier: "UPDATE" });
@@ -4824,7 +4943,7 @@ async function updateTemplate(request, { host, params }) {
4824
4943
  return Response.json(updated);
4825
4944
  } catch (error) {
4826
4945
  const msg = getErrorMessage(error, "Failed to update template");
4827
- if (error instanceof SchedulingValidationError6) {
4946
+ if (error instanceof SchedulingValidationError7) {
4828
4947
  console.error("[PUT /admin/templates]", error.ref, error.code, error.context);
4829
4948
  return Response.json({ error: msg, ref: error.ref }, { status: 400 });
4830
4949
  }
@@ -4952,7 +5071,7 @@ async function createType(request, { host }) {
4952
5071
  }
4953
5072
 
4954
5073
  // src/handlers/admin-type-update.ts
4955
- import { SchedulingValidationError as SchedulingValidationError7, updateAppointmentType } from "@ordinatio/scheduling";
5074
+ import { SchedulingValidationError as SchedulingValidationError8, updateAppointmentType } from "@ordinatio/scheduling";
4956
5075
 
4957
5076
  // src/handlers/type-ownership.ts
4958
5077
  async function getOwnedAppointmentType(db, id, organizationId) {
@@ -5050,7 +5169,7 @@ async function updateType(request, { host, params }) {
5050
5169
  return Response.json({ error: getErrorMessage(error, "Validation error") }, { status: schedErrorStatus(code) });
5051
5170
  }
5052
5171
  const message = isSchedulingServiceError(error) ? error.description || error.message : getErrorMessage(error, "Failed to update appointment type");
5053
- if (error instanceof SchedulingValidationError7) return Response.json({ error: message }, { status: 400 });
5172
+ if (error instanceof SchedulingValidationError8) return Response.json({ error: message }, { status: 400 });
5054
5173
  return Response.json({ error: message }, { status: 500 });
5055
5174
  }
5056
5175
  }
@@ -5330,7 +5449,7 @@ async function getAppointmentIcal(request, { host }) {
5330
5449
  const description = [appointment.type.description ?? "", `Manage your appointment: ${manageUrl}`].filter(Boolean).join("\n");
5331
5450
  const calendar = ical({ name: appointment.calendar.name });
5332
5451
  calendar.createEvent({
5333
- id: `${appointment.id}@system1701`,
5452
+ id: `${appointment.id}@${host.icalUidDomain() || "ordinatio-scheduling"}`,
5334
5453
  start: appointment.startTime,
5335
5454
  end: appointment.endTime,
5336
5455
  timezone: appointment.timezone,
@@ -5362,7 +5481,7 @@ import {
5362
5481
  } from "@ordinatio/scheduling";
5363
5482
 
5364
5483
  // src/webhooks/require-webhooks.ts
5365
- import { SchedulingNotFoundError as SchedulingNotFoundError7, SchedulingValidationError as SchedulingValidationError8 } from "@ordinatio/scheduling";
5484
+ import { SchedulingNotFoundError as SchedulingNotFoundError7, SchedulingValidationError as SchedulingValidationError9 } from "@ordinatio/scheduling";
5366
5485
  async function requireWebhooksAdmin(host, request, options) {
5367
5486
  const staff = await requireAdminStaff(host, request, options);
5368
5487
  if (staff instanceof Response) return staff;
@@ -5370,7 +5489,7 @@ async function requireWebhooksAdmin(host, request, options) {
5370
5489
  return { staff, settings: host.webhooks };
5371
5490
  }
5372
5491
  function webhookErrorResponse(error, fallback) {
5373
- if (error instanceof SchedulingValidationError8) {
5492
+ if (error instanceof SchedulingValidationError9) {
5374
5493
  return Response.json({ error: error.message, ref: getErrorRef(error) }, { status: 400 });
5375
5494
  }
5376
5495
  if (error instanceof SchedulingNotFoundError7) {
@@ -5508,33 +5627,142 @@ async function deliverWebhooks(request, { host }) {
5508
5627
  }
5509
5628
  }
5510
5629
 
5511
- // src/handlers/appointments-book.ts
5512
- import { bookAppointment } from "@ordinatio/scheduling";
5513
-
5514
- // src/booking/booking-schema.ts
5630
+ // src/handlers/waitlist-join.ts
5631
+ import { joinWaitlist, leaveWaitlist } from "@ordinatio/scheduling";
5515
5632
  import { z as z7 } from "zod";
5516
- var BookingSchema = z7.object({
5517
- calendarId: z7.string().min(1).optional(),
5518
- preferredCalendarId: z7.string().min(1).optional(),
5633
+
5634
+ // src/waitlist/waitlist-http.ts
5635
+ import { SchedulingNotFoundError as SchedulingNotFoundError9, SchedulingValidationError as SchedulingValidationError10 } from "@ordinatio/scheduling";
5636
+ var NOT_ENABLED2 = { error: "The waitlist is not enabled on this server" };
5637
+ var STATUS_BY_CODE = {
5638
+ SCHED_1100: 404,
5639
+ SCHED_1103: 409,
5640
+ SCHED_1104: 409,
5641
+ SCHED_1106: 404,
5642
+ SCHED_1107: 410,
5643
+ SCHED_1108: 409
5644
+ };
5645
+ async function resolveWaitlistDb(host, orgSlug) {
5646
+ if (!orgSlug) return { db: await host.publicDb(), organizationId: null };
5647
+ return host.organizations.resolve({ orgSlug, logPrefix: "[waitlist]" });
5648
+ }
5649
+ function waitlistErrorResponse(cors, error, fallback) {
5650
+ if (error instanceof SchedulingValidationError10 || error instanceof SchedulingNotFoundError9) {
5651
+ const status = STATUS_BY_CODE[error.code] ?? (error instanceof SchedulingNotFoundError9 ? 404 : 400);
5652
+ return corsJson(cors, { error: error.message, code: error.code, ref: getErrorRef(error) }, { status });
5653
+ }
5654
+ console.error("[waitlist]", error);
5655
+ return corsJson(cors, { error: fallback }, { status: 500 });
5656
+ }
5657
+ async function requireWaitlistAdmin(host, request, options) {
5658
+ const staff = await requireAdminStaff(host, request, options);
5659
+ if (staff instanceof Response) return staff;
5660
+ if (!host.waitlist) return Response.json(NOT_ENABLED2, { status: 501 });
5661
+ return { staff, settings: host.waitlist };
5662
+ }
5663
+
5664
+ // src/handlers/waitlist-join.ts
5665
+ var JoinWaitlistSchema = z7.object({
5666
+ orgSlug: z7.string().min(1).max(100).optional(),
5519
5667
  typeId: z7.string().min(1),
5520
- startTime: z7.string().datetime({ message: "Invalid date/time format" }),
5521
- timezone: z7.string().max(50).optional(),
5668
+ calendarId: z7.string().min(1).optional(),
5669
+ day: z7.string().regex(/^\d{4}-\d{2}-\d{2}$/, "Day must be YYYY-MM-DD"),
5670
+ slotStart: z7.string().datetime({ message: "Invalid date/time format" }).optional(),
5522
5671
  clientName: z7.string().trim().min(1, "Name is required").max(200),
5523
5672
  clientEmail: z7.string().email("Invalid email").max(254),
5524
- clientPhone: z7.string().max(30).optional(),
5673
+ clientPhone: z7.string().max(30).optional()
5674
+ });
5675
+ async function joinWaitlistRoute(request, { host }) {
5676
+ const cors = host.cors(request);
5677
+ if (!host.waitlist) return corsJson(cors, NOT_ENABLED2, { status: 501 });
5678
+ try {
5679
+ const limited = await host.rateLimit(`waitlist-join:${clientAddress(request)}`, "PUBLIC_BOOKING");
5680
+ if (limited) return limited;
5681
+ const parsed = JoinWaitlistSchema.safeParse(await request.json().catch(() => null));
5682
+ if (!parsed.success) {
5683
+ const details = parsed.error.issues.map((issue) => ({ field: issue.path.join("."), message: issue.message }));
5684
+ return corsJson(cors, { error: "Validation failed", details }, { status: 400 });
5685
+ }
5686
+ const body = parsed.data;
5687
+ const context = await resolveWaitlistDb(host, body.orgSlug);
5688
+ if (!context) return corsJson(cors, { error: "Appointment type not found" }, { status: 404 });
5689
+ let organizationId = context.organizationId;
5690
+ if (!organizationId) {
5691
+ const type = await context.db.appointmentType.findUnique({ where: { id: body.typeId }, select: { organizationId: true } });
5692
+ organizationId = type?.organizationId ?? null;
5693
+ }
5694
+ if (!organizationId) return corsJson(cors, { error: "Appointment type not found" }, { status: 404 });
5695
+ const { entry, token } = await joinWaitlist(context.db, {
5696
+ organizationId,
5697
+ typeId: body.typeId,
5698
+ calendarId: body.calendarId,
5699
+ day: body.day,
5700
+ slotStart: body.slotStart ? new Date(body.slotStart) : void 0,
5701
+ clientName: body.clientName,
5702
+ clientEmail: body.clientEmail,
5703
+ clientPhone: body.clientPhone
5704
+ });
5705
+ return corsJson(cors, { entry, token }, { status: 201, headers: { "Cache-Control": "no-store" } });
5706
+ } catch (error) {
5707
+ return waitlistErrorResponse(cors, error, "Failed to join the waitlist");
5708
+ }
5709
+ }
5710
+ async function leaveWaitlistRoute(request, { host }) {
5711
+ const cors = host.cors(request);
5712
+ if (!host.waitlist) return corsJson(cors, NOT_ENABLED2, { status: 501 });
5713
+ try {
5714
+ const limited = await host.rateLimit(`waitlist-leave:${clientAddress(request)}`, "GENERAL");
5715
+ if (limited) return limited;
5716
+ const url = new URL(request.url);
5717
+ const token = url.searchParams.get("token");
5718
+ if (!token) return corsJson(cors, { error: "token is required" }, { status: 400 });
5719
+ const context = await resolveWaitlistDb(host, url.searchParams.get("orgSlug"));
5720
+ if (!context) return corsJson(cors, { error: "No waitlist entry for this link", code: "SCHED_1106" }, { status: 404 });
5721
+ const freed = await leaveWaitlist(context.db, token);
5722
+ if (freed) await offerAndAnnounce(host, host.waitlist, context.db, freed);
5723
+ return corsJson(cors, { success: true });
5724
+ } catch (error) {
5725
+ return waitlistErrorResponse(cors, error, "Failed to leave the waitlist");
5726
+ }
5727
+ }
5728
+
5729
+ // src/handlers/waitlist-offer.ts
5730
+ import {
5731
+ beginWaitlistAccept,
5732
+ completeWaitlistAccept,
5733
+ getWaitlistOffer,
5734
+ releaseWaitlistAccept,
5735
+ settleBookedAccept
5736
+ } from "@ordinatio/scheduling";
5737
+ import { z as z9 } from "zod";
5738
+
5739
+ // src/handlers/appointments-book.ts
5740
+ import { bookAppointment } from "@ordinatio/scheduling";
5741
+
5742
+ // src/booking/booking-schema.ts
5743
+ import { z as z8 } from "zod";
5744
+ var BookingSchema = z8.object({
5745
+ calendarId: z8.string().min(1).optional(),
5746
+ preferredCalendarId: z8.string().min(1).optional(),
5747
+ typeId: z8.string().min(1),
5748
+ startTime: z8.string().datetime({ message: "Invalid date/time format" }),
5749
+ timezone: z8.string().max(50).optional(),
5750
+ clientName: z8.string().trim().min(1, "Name is required").max(200),
5751
+ clientEmail: z8.string().email("Invalid email").max(254),
5752
+ clientPhone: z8.string().max(30).optional(),
5525
5753
  // Untrusted: the host's client resolver decides whether to honor it.
5526
- clientId: z7.string().optional(),
5527
- notes: z7.string().max(1e3).optional(),
5754
+ clientId: z8.string().optional(),
5755
+ notes: z8.string().max(1e3).optional(),
5528
5756
  // Only the primitive types a form field produces; z.unknown() would accept anything.
5529
- intakeResponses: z7.record(
5530
- z7.string(),
5531
- z7.union([z7.string().max(1e3), z7.number(), z7.boolean(), z7.null()])
5757
+ intakeResponses: z8.record(
5758
+ z8.string(),
5759
+ z8.union([z8.string().max(1e3), z8.number(), z8.boolean(), z8.null()])
5532
5760
  ).optional(),
5533
- paymentId: z7.string().optional(),
5534
- couponCode: z7.string().min(1).max(50).transform((value) => value.trim().toUpperCase()).optional(),
5535
- packagePurchaseId: z7.string().optional(),
5761
+ paymentId: z8.string().optional(),
5762
+ couponCode: z8.string().min(1).max(50).transform((value) => value.trim().toUpperCase()).optional(),
5763
+ packagePurchaseId: z8.string().optional(),
5536
5764
  // Names the organization, so the calendar and type lookups can run against its own database.
5537
- orgSlug: z7.string().min(1).max(100).optional()
5765
+ orgSlug: z8.string().min(1).max(100).optional()
5538
5766
  });
5539
5767
 
5540
5768
  // src/booking/finalize-booking.ts
@@ -5630,7 +5858,7 @@ async function finalizeBooking(host, cors, db, organizationId, body, appointment
5630
5858
  const baseUrl = host.appUrl();
5631
5859
  if (!baseUrl) throw new Error("The host must supply appUrl() to book appointments");
5632
5860
  try {
5633
- await scheduleNotifications5(db, appointment.id, baseUrl);
5861
+ await scheduleNotifications5(db, appointment.id, baseUrl, { brand: Boolean(host.brand) });
5634
5862
  } catch (error) {
5635
5863
  await logActivity(
5636
5864
  "scheduling.notification_schedule_failed",
@@ -5639,7 +5867,7 @@ async function finalizeBooking(host, cors, db, organizationId, body, appointment
5639
5867
  );
5640
5868
  }
5641
5869
  try {
5642
- await queueStaffNotification7(db, appointment.id, "CONFIRMATION", baseUrl);
5870
+ await queueStaffNotification7(db, appointment.id, "CONFIRMATION", baseUrl, { brand: Boolean(host.brand) });
5643
5871
  } catch (error) {
5644
5872
  await logActivity(
5645
5873
  "scheduling.staff_notification_failed",
@@ -6000,8 +6228,466 @@ async function bookAppointmentRoute(request, { host }) {
6000
6228
  }
6001
6229
  }
6002
6230
 
6231
+ // src/handlers/waitlist-offer.ts
6232
+ async function getWaitlistOfferRoute(request, { host }) {
6233
+ const cors = host.cors(request);
6234
+ if (!host.waitlist) return corsJson(cors, NOT_ENABLED2, { status: 501 });
6235
+ try {
6236
+ const limited = await host.rateLimit(`waitlist-offer:${clientAddress(request)}`, "AVAILABILITY");
6237
+ if (limited) return limited;
6238
+ const url = new URL(request.url);
6239
+ const token = url.searchParams.get("token");
6240
+ if (!token) return corsJson(cors, { error: "token is required" }, { status: 400 });
6241
+ const context = await resolveWaitlistDb(host, url.searchParams.get("orgSlug"));
6242
+ if (!context) return corsJson(cors, { error: "No open offer for this link", code: "SCHED_1106" }, { status: 404 });
6243
+ const offer = await getWaitlistOffer(context.db, token);
6244
+ return corsJson(cors, {
6245
+ typeName: offer.typeName,
6246
+ calendarName: offer.calendarName,
6247
+ startTime: offer.startTime,
6248
+ timezone: offer.timezone,
6249
+ expiresAt: offer.expiresAt,
6250
+ clientName: offer.clientName
6251
+ });
6252
+ } catch (error) {
6253
+ return waitlistErrorResponse(cors, error, "Failed to read the offer");
6254
+ }
6255
+ }
6256
+ var AcceptSchema = z9.object({ token: z9.string().min(1).max(200), orgSlug: z9.string().min(1).max(100).optional() });
6257
+ async function acceptWaitlistOfferRoute(request, context) {
6258
+ const { host } = context;
6259
+ const cors = host.cors(request);
6260
+ const settings = host.waitlist;
6261
+ if (!settings) return corsJson(cors, NOT_ENABLED2, { status: 501 });
6262
+ let entryId = null;
6263
+ let db = null;
6264
+ let booked = false;
6265
+ try {
6266
+ const limited = await host.rateLimit(`waitlist-accept:${clientAddress(request)}`, "GENERAL");
6267
+ if (limited) return limited;
6268
+ const parsed = AcceptSchema.safeParse(await request.json().catch(() => null));
6269
+ if (!parsed.success) return corsJson(cors, { error: "token is required" }, { status: 400 });
6270
+ db = await resolveWaitlistDb(host, parsed.data.orgSlug);
6271
+ if (!db) return corsJson(cors, { error: "No open offer for this link", code: "SCHED_1106" }, { status: 404 });
6272
+ const offer = await beginWaitlistAccept(db.db, parsed.data.token);
6273
+ entryId = offer.entryId;
6274
+ const headers = new Headers(request.headers);
6275
+ headers.set("content-type", "application/json");
6276
+ const response = await bookAppointmentRoute(
6277
+ new Request(request.url, {
6278
+ method: "POST",
6279
+ headers,
6280
+ body: JSON.stringify({
6281
+ calendarId: offer.calendarId,
6282
+ typeId: offer.typeId,
6283
+ startTime: offer.startTime.toISOString(),
6284
+ timezone: offer.timezone,
6285
+ clientName: offer.clientName,
6286
+ clientEmail: offer.clientEmail,
6287
+ ...offer.clientPhone ? { clientPhone: offer.clientPhone } : {},
6288
+ ...parsed.data.orgSlug ? { orgSlug: parsed.data.orgSlug } : {}
6289
+ })
6290
+ }),
6291
+ context
6292
+ );
6293
+ if (response.status === 201) {
6294
+ booked = true;
6295
+ const appointment = await response.clone().json().catch(() => null);
6296
+ try {
6297
+ await completeWaitlistAccept(db.db, entryId, appointment?.id ?? "");
6298
+ } catch (completeError) {
6299
+ console.error("[waitlist] the booking was saved but its waitlist entry could not be marked booked:", completeError);
6300
+ }
6301
+ return response;
6302
+ }
6303
+ const saved = await settleBookedAccept(db.db, entryId);
6304
+ if (saved) return corsJson(cors, saved, { status: 201 });
6305
+ await endFailedAccept(host, settings, db.db, entryId, releaseFor(response.status));
6306
+ return response;
6307
+ } catch (error) {
6308
+ if (entryId && db && !booked) {
6309
+ try {
6310
+ const saved = await settleBookedAccept(db.db, entryId);
6311
+ if (saved) return corsJson(cors, saved, { status: 201 });
6312
+ await endFailedAccept(host, settings, db.db, entryId, "KEEP_OFFER");
6313
+ } catch (releaseError) {
6314
+ console.error("[waitlist] could not settle or release an accept:", releaseError);
6315
+ }
6316
+ }
6317
+ return waitlistErrorResponse(cors, error, "Failed to accept the offer");
6318
+ }
6319
+ }
6320
+ function releaseFor(status) {
6321
+ if (status === 409) return "BACK_IN_LINE";
6322
+ if (status === 429 || status >= 500) return "KEEP_OFFER";
6323
+ return "DROP";
6324
+ }
6325
+ async function endFailedAccept(host, settings, db, entryId, outcome) {
6326
+ const freed = await releaseWaitlistAccept(db, entryId, outcome);
6327
+ if (freed) await offerAndAnnounce(host, settings, db, freed);
6328
+ }
6329
+
6330
+ // src/handlers/admin-waitlist.ts
6331
+ import { listWaitlist, removeWaitlistEntry } from "@ordinatio/scheduling";
6332
+ var STATUSES2 = /* @__PURE__ */ new Set(["WAITING", "OFFERED", "ACCEPTING", "BOOKED", "EXPIRED"]);
6333
+ async function listWaitlistEntries(request, { host }) {
6334
+ try {
6335
+ const guard = await requireWaitlistAdmin(host, request, { action: "admin-waitlist-list", tier: "GENERAL" });
6336
+ if (guard instanceof Response) return guard;
6337
+ const status = new URL(request.url).searchParams.get("status");
6338
+ if (status && !STATUSES2.has(status)) {
6339
+ return Response.json({ error: `status must be one of ${[...STATUSES2].join(", ")}` }, { status: 400 });
6340
+ }
6341
+ const { limit, offset } = parsePagination(request);
6342
+ const { entries, total } = await listWaitlist(guard.staff.db, {
6343
+ organizationId: guard.staff.organizationId,
6344
+ status: status ?? void 0,
6345
+ limit,
6346
+ offset
6347
+ });
6348
+ return Response.json({ entries, total, hasMore: offset + entries.length < total });
6349
+ } catch (error) {
6350
+ return webhookErrorResponse(error, "Failed to list the waitlist");
6351
+ }
6352
+ }
6353
+ async function removeWaitlistEntryRoute(request, { host, params }) {
6354
+ try {
6355
+ const guard = await requireWaitlistAdmin(host, request, { action: "admin-waitlist-remove", tier: "DELETE" });
6356
+ if (guard instanceof Response) return guard;
6357
+ const { db, organizationId } = guard.staff;
6358
+ const freed = await removeWaitlistEntry(db, organizationId, params.id);
6359
+ await host.activity.log(db, {
6360
+ action: "scheduling.waitlist_entry_removed",
6361
+ description: "removed someone from the waitlist",
6362
+ metadata: { entryId: params.id }
6363
+ });
6364
+ if (freed) await offerAndAnnounce(host, guard.settings, db, freed);
6365
+ return Response.json({ success: true });
6366
+ } catch (error) {
6367
+ return webhookErrorResponse(error, "Failed to remove the waitlist entry");
6368
+ }
6369
+ }
6370
+
6371
+ // src/handlers/internal-waitlist-sweep.ts
6372
+ import { expireWaitlistOffers } from "@ordinatio/scheduling";
6373
+ async function sweepWaitlist(request, { host }) {
6374
+ if (!await host.internalAccess.isAuthorized(request)) return Response.json({ error: "Unauthorized" }, { status: 401 });
6375
+ if (!host.waitlist) return Response.json(NOT_ENABLED2, { status: 501 });
6376
+ const limited = await host.rateLimit(`${request.headers.get("x-forwarded-for") ?? "worker"}:waitlist-sweep`, "INTERNAL");
6377
+ if (limited) return limited;
6378
+ try {
6379
+ const db = await host.publicDb();
6380
+ const { lapsed, released, booked } = await expireWaitlistOffers(db);
6381
+ let reoffered = 0;
6382
+ for (const slot of lapsed) {
6383
+ if (await offerAndAnnounce(host, host.waitlist, db, slot)) reoffered++;
6384
+ }
6385
+ return Response.json({ lapsed: lapsed.length, released, booked, reoffered });
6386
+ } catch (error) {
6387
+ console.error("[scheduling-api] waitlist sweep failed:", error);
6388
+ return Response.json({ error: "Waitlist sweep failed" }, { status: 500 });
6389
+ }
6390
+ }
6391
+
6392
+ // src/handlers/routing-forms-public.ts
6393
+ import { getPublicRoutingForm, routeClient } from "@ordinatio/scheduling";
6394
+
6395
+ // src/routing/routing-http.ts
6396
+ import { SchedulingNotFoundError as SchedulingNotFoundError10, SchedulingValidationError as SchedulingValidationError11 } from "@ordinatio/scheduling";
6397
+ var NOT_ENABLED3 = { error: "Routing forms are not enabled on this server" };
6398
+ var STATUS_BY_CODE2 = { SCHED_1201: 404, SCHED_1202: 409, SCHED_1204: 409 };
6399
+ function routingErrorResponse(error, fallback, cors) {
6400
+ const send = (payload, status) => cors ? corsJson(cors, payload, { status }) : Response.json(payload, { status });
6401
+ if (error instanceof SchedulingValidationError11 || error instanceof SchedulingNotFoundError10) {
6402
+ const details = error.context.errors;
6403
+ const status = STATUS_BY_CODE2[error.code] ?? 400;
6404
+ return send({ error: error.message, code: error.code, ref: getErrorRef(error), ...details ? { details } : {} }, status);
6405
+ }
6406
+ console.error("[routing-forms]", error);
6407
+ return send({ error: fallback }, 500);
6408
+ }
6409
+ async function requireRoutingAdmin(host, request, options) {
6410
+ const staff = await requireAdminStaff(host, request, options);
6411
+ if (staff instanceof Response) return staff;
6412
+ if (!host.routingForms) return Response.json(NOT_ENABLED3, { status: 501 });
6413
+ return staff;
6414
+ }
6415
+
6416
+ // src/handlers/routing-forms-public.ts
6417
+ async function resolveOrganization(host, orgSlug) {
6418
+ if (!orgSlug) return { db: await host.publicDb(), organizationId: null };
6419
+ return host.organizations.resolve({ orgSlug, logPrefix: "[routing-forms]" });
6420
+ }
6421
+ async function getRoutingFormRoute(request, { host }) {
6422
+ const cors = host.cors(request);
6423
+ if (!host.routingForms) return corsJson(cors, NOT_ENABLED3, { status: 501 });
6424
+ try {
6425
+ const limited = await host.rateLimit(`routing-form:${clientAddress(request)}`, "AVAILABILITY");
6426
+ if (limited) return limited;
6427
+ const url = new URL(request.url);
6428
+ const slug = url.searchParams.get("slug");
6429
+ if (!slug) return corsJson(cors, { error: "slug is required" }, { status: 400 });
6430
+ const context = await resolveOrganization(host, url.searchParams.get("orgSlug"));
6431
+ if (!context) return corsJson(cors, { error: "Routing form not found", code: "SCHED_1201" }, { status: 404 });
6432
+ return corsJson(cors, await getPublicRoutingForm(context.db, { organizationId: context.organizationId, slug }));
6433
+ } catch (error) {
6434
+ return routingErrorResponse(error, "Failed to read the form", cors);
6435
+ }
6436
+ }
6437
+ async function routeClientRoute(request, { host }) {
6438
+ const cors = host.cors(request);
6439
+ if (!host.routingForms) return corsJson(cors, NOT_ENABLED3, { status: 501 });
6440
+ try {
6441
+ const limited = await host.rateLimit(`routing-route:${clientAddress(request)}`, "AVAILABILITY");
6442
+ if (limited) return limited;
6443
+ const parsed = RouteClientSchema.safeParse(await request.json().catch(() => null));
6444
+ if (!parsed.success) {
6445
+ const details = parsed.error.issues.map((issue) => ({ field: issue.path.join("."), message: issue.message }));
6446
+ return corsJson(cors, { error: "Validation failed", details }, { status: 400 });
6447
+ }
6448
+ const context = await resolveOrganization(host, parsed.data.orgSlug);
6449
+ if (!context) return corsJson(cors, { error: "Routing form not found", code: "SCHED_1201" }, { status: 404 });
6450
+ const outcome = await routeClient(context.db, { organizationId: context.organizationId, slug: parsed.data.slug, answers: parsed.data.answers });
6451
+ return corsJson(cors, outcome);
6452
+ } catch (error) {
6453
+ return routingErrorResponse(error, "Failed to route the answers", cors);
6454
+ }
6455
+ }
6456
+
6457
+ // src/handlers/admin-routing-forms.ts
6458
+ import { createRoutingForm, listRoutingForms } from "@ordinatio/scheduling";
6459
+ async function listRoutingFormsRoute(request, { host }) {
6460
+ try {
6461
+ const staff = await requireRoutingAdmin(host, request, { action: "admin-routing-forms-list", tier: "GENERAL" });
6462
+ if (staff instanceof Response) return staff;
6463
+ return Response.json({ forms: await listRoutingForms(staff.db, staff.organizationId) });
6464
+ } catch (error) {
6465
+ return routingErrorResponse(error, "Failed to list the forms");
6466
+ }
6467
+ }
6468
+ async function createRoutingFormRoute(request, { host }) {
6469
+ try {
6470
+ const staff = await requireRoutingAdmin(host, request, { action: "admin-routing-forms-create", tier: "CREATE" });
6471
+ if (staff instanceof Response) return staff;
6472
+ const validation = await parseBody(request, CreateRoutingFormSchema);
6473
+ if (!validation.success) return validation.response;
6474
+ const form = await createRoutingForm(staff.db, staff.organizationId, validation.data);
6475
+ await host.activity.log(staff.db, {
6476
+ action: "scheduling.routing_form_created",
6477
+ description: `created routing form "${form.name}"`,
6478
+ metadata: { formId: form.id, slug: form.slug }
6479
+ });
6480
+ return Response.json({ form }, { status: 201 });
6481
+ } catch (error) {
6482
+ return routingErrorResponse(error, "Failed to save the form");
6483
+ }
6484
+ }
6485
+
6486
+ // src/handlers/brand-public.ts
6487
+ import { getPublicBrand } from "@ordinatio/scheduling";
6488
+ async function getBrandRoute(request, { host }) {
6489
+ const cors = host.cors(request);
6490
+ if (!host.brand) return corsJson(cors, NOT_ENABLED, { status: 501 });
6491
+ try {
6492
+ const limited = await host.rateLimit(`brand:${clientAddress(request)}`, "AVAILABILITY");
6493
+ if (limited) return limited;
6494
+ const orgSlug = new URL(request.url).searchParams.get("orgSlug");
6495
+ const context = orgSlug ? await host.organizations.resolve({ orgSlug, logPrefix: "[brand]" }) : { db: await host.publicDb(), organizationId: null };
6496
+ const brand = context ? await getPublicBrand(context.db, context.organizationId) : null;
6497
+ if (!brand) return corsJson(cors, { error: "No brand set" }, { status: 404 });
6498
+ return corsJson(cors, { brand }, { headers: WIDGET_CACHE_HEADERS });
6499
+ } catch (error) {
6500
+ return brandErrorResponse(error, "Failed to read the brand", cors);
6501
+ }
6502
+ }
6503
+
6504
+ // src/handlers/admin-brand.ts
6505
+ import { deleteBrand, getBrand as getBrand2, saveBrand } from "@ordinatio/scheduling";
6506
+ async function getBrandAdminRoute(request, { host }) {
6507
+ try {
6508
+ const staff = await requireBrandAdmin(host, request, { action: "admin-brand-get", tier: "GENERAL" });
6509
+ if (staff instanceof Response) return staff;
6510
+ return Response.json({ brand: await getBrand2(staff.db, staff.organizationId) });
6511
+ } catch (error) {
6512
+ return brandErrorResponse(error, "Failed to read the brand");
6513
+ }
6514
+ }
6515
+ async function saveBrandRoute(request, { host }) {
6516
+ try {
6517
+ const staff = await requireBrandAdmin(host, request, { action: "admin-brand-save", tier: "UPDATE" });
6518
+ if (staff instanceof Response) return staff;
6519
+ const validation = await parseBody(request, BrandSchema);
6520
+ if (!validation.success) return validation.response;
6521
+ const verifier = host.brand?.isSendingDomainVerified;
6522
+ const brand = await saveBrand(staff.db, staff.organizationId, validation.data, {
6523
+ isSendingDomainVerified: verifier ? async (domain) => Boolean(await verifier.call(host.brand, domain, staff.organizationId)) : void 0
6524
+ });
6525
+ await host.activity.log(staff.db, {
6526
+ action: "scheduling.brand_saved",
6527
+ description: "changed the brand",
6528
+ metadata: { displayName: brand.displayName, sendsFromOwnDomain: Boolean(brand.fromEmail) }
6529
+ });
6530
+ return Response.json({ brand });
6531
+ } catch (error) {
6532
+ return brandErrorResponse(error, "Failed to save the brand");
6533
+ }
6534
+ }
6535
+ async function deleteBrandRoute(request, { host }) {
6536
+ try {
6537
+ const staff = await requireBrandAdmin(host, request, { action: "admin-brand-delete", tier: "DELETE" });
6538
+ if (staff instanceof Response) return staff;
6539
+ const removed = await deleteBrand(staff.db, staff.organizationId);
6540
+ if (removed) await host.activity.log(staff.db, { action: "scheduling.brand_removed", description: "removed the brand", metadata: {} });
6541
+ return Response.json({ removed });
6542
+ } catch (error) {
6543
+ return brandErrorResponse(error, "Failed to remove the brand");
6544
+ }
6545
+ }
6546
+
6547
+ // src/handlers/admin-privacy.ts
6548
+ import { eraseSubject, exportSubject, listPrivacyRequests, previewErase } from "@ordinatio/scheduling";
6549
+
6550
+ // src/privacy/privacy-http.ts
6551
+ import { SchedulingValidationError as SchedulingValidationError12 } from "@ordinatio/scheduling";
6552
+ var NOT_ENABLED4 = { error: "Data export and erasure are not enabled on this server" };
6553
+ var STATUS_BY_CODE3 = { SCHED_1300: 400, SCHED_1301: 409 };
6554
+ function privacyErrorResponse(error, fallback) {
6555
+ if (error instanceof SchedulingValidationError12) {
6556
+ return Response.json(
6557
+ { error: error.message, code: error.code, ref: getErrorRef(error), details: error.context },
6558
+ { status: STATUS_BY_CODE3[error.code] ?? 400 }
6559
+ );
6560
+ }
6561
+ console.error("[privacy]", error);
6562
+ return Response.json({ error: fallback }, { status: 500 });
6563
+ }
6564
+ async function requirePrivacyAdmin(host, request, options) {
6565
+ const staff = await requireAdminStaff(host, request, options);
6566
+ if (staff instanceof Response) return staff;
6567
+ if (!host.privacy) return Response.json(NOT_ENABLED4, { status: 501 });
6568
+ return staff;
6569
+ }
6570
+
6571
+ // src/handlers/admin-privacy.ts
6572
+ async function logQuietly(host, db, entry) {
6573
+ try {
6574
+ await host.activity.log(db, entry);
6575
+ } catch (error) {
6576
+ console.error("[privacy] could not write the activity entry:", error);
6577
+ }
6578
+ }
6579
+ async function exportPrivacyRoute(request, { host }) {
6580
+ try {
6581
+ const staff = await requirePrivacyAdmin(host, request, { action: "admin-privacy-export", tier: "CREATE" });
6582
+ if (staff instanceof Response) return staff;
6583
+ const validation = await parseBody(request, PrivacySubjectSchema);
6584
+ if (!validation.success) return validation.response;
6585
+ const result = await exportSubject(staff.db, { organizationId: staff.organizationId, requestedBy: staff.userId, ...validation.data });
6586
+ await logQuietly(host, staff.db, {
6587
+ action: "scheduling.privacy_export",
6588
+ description: "exported the data held about one person",
6589
+ metadata: { counts: result.counts }
6590
+ });
6591
+ const stamp = result.exportedAt.slice(0, 10);
6592
+ return new Response(JSON.stringify(result, null, 2), {
6593
+ status: 200,
6594
+ headers: {
6595
+ "content-type": "application/json; charset=utf-8",
6596
+ "content-disposition": `attachment; filename="scheduling-data-export-${stamp}.json"`,
6597
+ "cache-control": "no-store"
6598
+ }
6599
+ });
6600
+ } catch (error) {
6601
+ return privacyErrorResponse(error, "Failed to export the data");
6602
+ }
6603
+ }
6604
+ async function erasePrivacyRoute(request, { host }) {
6605
+ try {
6606
+ const staff = await requirePrivacyAdmin(host, request, { action: "admin-privacy-erase", tier: "DELETE" });
6607
+ if (staff instanceof Response) return staff;
6608
+ const validation = await parseBody(request, PrivacyEraseSchema);
6609
+ if (!validation.success) return validation.response;
6610
+ const { confirm, ...subject } = validation.data;
6611
+ if (confirm !== true) {
6612
+ const preview = await previewErase(staff.db, { organizationId: staff.organizationId, ...subject });
6613
+ return Response.json({ erased: false, preview }, { headers: { "cache-control": "no-store" } });
6614
+ }
6615
+ const { counts } = await eraseSubject(staff.db, { organizationId: staff.organizationId, requestedBy: staff.userId, ...subject });
6616
+ await logQuietly(host, staff.db, {
6617
+ action: "scheduling.privacy_erase",
6618
+ description: "erased the data held about one person",
6619
+ metadata: { counts }
6620
+ });
6621
+ return Response.json({ erased: true, counts }, { headers: { "cache-control": "no-store" } });
6622
+ } catch (error) {
6623
+ return privacyErrorResponse(error, "Failed to erase the data");
6624
+ }
6625
+ }
6626
+ async function listPrivacyRequestsRoute(request, { host }) {
6627
+ try {
6628
+ const staff = await requirePrivacyAdmin(host, request, { action: "admin-privacy-requests", tier: "GENERAL" });
6629
+ if (staff instanceof Response) return staff;
6630
+ const { limit, offset } = parsePagination(request);
6631
+ const { requests, total } = await listPrivacyRequests(staff.db, { organizationId: staff.organizationId, limit, offset });
6632
+ return Response.json({ requests, total, hasMore: offset + requests.length < total });
6633
+ } catch (error) {
6634
+ return privacyErrorResponse(error, "Failed to list the requests");
6635
+ }
6636
+ }
6637
+
6638
+ // src/handlers/admin-routing-form-detail.ts
6639
+ import { deleteRoutingForm, getRoutingForm, testRoutingForm, updateRoutingForm } from "@ordinatio/scheduling";
6640
+ async function getRoutingFormAdminRoute(request, { host, params }) {
6641
+ try {
6642
+ const staff = await requireRoutingAdmin(host, request, { action: "admin-routing-forms-get", tier: "GENERAL" });
6643
+ if (staff instanceof Response) return staff;
6644
+ return Response.json({ form: await getRoutingForm(staff.db, staff.organizationId, params.id) });
6645
+ } catch (error) {
6646
+ return routingErrorResponse(error, "Failed to read the form");
6647
+ }
6648
+ }
6649
+ async function updateRoutingFormRoute(request, { host, params }) {
6650
+ try {
6651
+ const staff = await requireRoutingAdmin(host, request, { action: "admin-routing-forms-update", tier: "UPDATE" });
6652
+ if (staff instanceof Response) return staff;
6653
+ const validation = await parseBody(request, UpdateRoutingFormSchema);
6654
+ if (!validation.success) return validation.response;
6655
+ const form = await updateRoutingForm(staff.db, staff.organizationId, params.id, validation.data);
6656
+ await host.activity.log(staff.db, {
6657
+ action: "scheduling.routing_form_updated",
6658
+ description: `changed routing form "${form.name}"`,
6659
+ metadata: { formId: form.id, fields: Object.keys(validation.data) }
6660
+ });
6661
+ return Response.json({ form });
6662
+ } catch (error) {
6663
+ return routingErrorResponse(error, "Failed to save the form");
6664
+ }
6665
+ }
6666
+ async function deleteRoutingFormRoute(request, { host, params }) {
6667
+ try {
6668
+ const staff = await requireRoutingAdmin(host, request, { action: "admin-routing-forms-delete", tier: "DELETE" });
6669
+ if (staff instanceof Response) return staff;
6670
+ await deleteRoutingForm(staff.db, staff.organizationId, params.id);
6671
+ await host.activity.log(staff.db, { action: "scheduling.routing_form_deleted", description: "removed a routing form", metadata: { formId: params.id } });
6672
+ return Response.json({ success: true });
6673
+ } catch (error) {
6674
+ return routingErrorResponse(error, "Failed to remove the form");
6675
+ }
6676
+ }
6677
+ async function testRoutingFormRoute(request, { host, params }) {
6678
+ try {
6679
+ const staff = await requireRoutingAdmin(host, request, { action: "admin-routing-forms-test", tier: "GENERAL" });
6680
+ if (staff instanceof Response) return staff;
6681
+ const validation = await parseBody(request, TestRoutingFormSchema);
6682
+ if (!validation.success) return validation.response;
6683
+ return Response.json(await testRoutingForm(staff.db, { organizationId: staff.organizationId, id: params.id, answers: validation.data.answers }));
6684
+ } catch (error) {
6685
+ return routingErrorResponse(error, "Failed to test the form");
6686
+ }
6687
+ }
6688
+
6003
6689
  // src/handlers/appointments-list.ts
6004
- import { schedError as schedError28 } from "@ordinatio/scheduling";
6690
+ import { schedError as schedError28, withOrganization } from "@ordinatio/scheduling";
6005
6691
  var DEFAULT_LIMIT2 = 50;
6006
6692
  var MAX_LIMIT2 = 500;
6007
6693
  async function listAppointments(request, { host }) {
@@ -6024,7 +6710,7 @@ async function listAppointments(request, { host }) {
6024
6710
  MAX_LIMIT2
6025
6711
  );
6026
6712
  const visibility = await staff.visibleCalendars();
6027
- const where = {
6713
+ const where = withOrganization({
6028
6714
  ...visibility ? { calendar: visibility } : {},
6029
6715
  ...calendarId ? { calendarId } : {},
6030
6716
  ...clientId ? { clientId } : {},
@@ -6035,7 +6721,7 @@ async function listAppointments(request, { host }) {
6035
6721
  ...endDate ? { lte: new Date(endDate) } : {}
6036
6722
  }
6037
6723
  } : {}
6038
- };
6724
+ }, staff.organizationId);
6039
6725
  const [rows, total] = await Promise.all([
6040
6726
  staff.db.appointment.findMany({
6041
6727
  where,
@@ -6379,12 +7065,12 @@ async function getAppointmentTypes(request, { host }) {
6379
7065
  }
6380
7066
 
6381
7067
  // src/handlers/coupons-validate.ts
6382
- import { z as z8 } from "zod";
7068
+ import { z as z10 } from "zod";
6383
7069
  import { schedError as schedError30 } from "@ordinatio/scheduling";
6384
- var Schema4 = z8.object({
6385
- code: z8.string().min(1).max(50).transform((v) => v.trim().toUpperCase()),
6386
- calendarId: z8.string().min(1),
6387
- price: z8.number().positive()
7070
+ var Schema4 = z10.object({
7071
+ code: z10.string().min(1).max(50).transform((v) => v.trim().toUpperCase()),
7072
+ calendarId: z10.string().min(1),
7073
+ price: z10.number().positive()
6388
7074
  });
6389
7075
  function calculateDiscount(price, discountType, discountValue) {
6390
7076
  if (discountType === "PERCENTAGE") {
@@ -6715,6 +7401,13 @@ var ROUTES = [
6715
7401
  { method: "GET", path: "/availability", public: true, handler: getAvailability },
6716
7402
  { method: "GET", path: "/availability/team", public: true, handler: getTeamAvailability },
6717
7403
  { method: "POST", path: "/appointments", public: true, handler: bookAppointmentRoute },
7404
+ { method: "GET", path: "/routing-forms", public: true, handler: getRoutingFormRoute },
7405
+ { method: "POST", path: "/routing-forms/route", public: true, handler: routeClientRoute },
7406
+ { method: "GET", path: "/brand", public: true, handler: getBrandRoute },
7407
+ { method: "POST", path: "/waitlist", public: true, handler: joinWaitlistRoute },
7408
+ { method: "DELETE", path: "/waitlist", public: true, handler: leaveWaitlistRoute },
7409
+ { method: "GET", path: "/waitlist/offer", public: true, handler: getWaitlistOfferRoute },
7410
+ { method: "POST", path: "/waitlist/offer/accept", public: true, handler: acceptWaitlistOfferRoute },
6718
7411
  { method: "GET", path: "/appointments", public: false, handler: listAppointments },
6719
7412
  { method: "GET", path: "/appointments/capacity", public: true, handler: getCapacity },
6720
7413
  { method: "GET", path: "/appointments/ical", public: false, handler: getAppointmentIcal },
@@ -6756,6 +7449,21 @@ var ROUTES = [
6756
7449
  { method: "GET", path: "/admin/webhooks/[id]/deliveries", public: false, handler: listWebhookEndpointDeliveries },
6757
7450
  { method: "POST", path: "/admin/webhook-deliveries/[id]/retry", public: false, handler: retryWebhook },
6758
7451
  { method: "POST", path: "/internal/webhooks/deliver", public: false, handler: deliverWebhooks },
7452
+ { method: "GET", path: "/admin/routing-forms", public: false, handler: listRoutingFormsRoute },
7453
+ { method: "POST", path: "/admin/routing-forms", public: false, handler: createRoutingFormRoute },
7454
+ { method: "GET", path: "/admin/routing-forms/[id]", public: false, handler: getRoutingFormAdminRoute },
7455
+ { method: "PUT", path: "/admin/routing-forms/[id]", public: false, handler: updateRoutingFormRoute },
7456
+ { method: "DELETE", path: "/admin/routing-forms/[id]", public: false, handler: deleteRoutingFormRoute },
7457
+ { method: "POST", path: "/admin/routing-forms/[id]/test", public: false, handler: testRoutingFormRoute },
7458
+ { method: "GET", path: "/admin/brand", public: false, handler: getBrandAdminRoute },
7459
+ { method: "PUT", path: "/admin/brand", public: false, handler: saveBrandRoute },
7460
+ { method: "DELETE", path: "/admin/brand", public: false, handler: deleteBrandRoute },
7461
+ { method: "POST", path: "/admin/privacy/export", public: false, handler: exportPrivacyRoute },
7462
+ { method: "POST", path: "/admin/privacy/erase", public: false, handler: erasePrivacyRoute },
7463
+ { method: "GET", path: "/admin/privacy/requests", public: false, handler: listPrivacyRequestsRoute },
7464
+ { method: "GET", path: "/admin/waitlist", public: false, handler: listWaitlistEntries },
7465
+ { method: "DELETE", path: "/admin/waitlist/[id]", public: false, handler: removeWaitlistEntryRoute },
7466
+ { method: "POST", path: "/internal/waitlist/sweep", public: false, handler: sweepWaitlist },
6759
7467
  { method: "GET", path: "/analytics", public: false, handler: getAnalytics },
6760
7468
  { method: "GET", path: "/admin/types", public: false, handler: listTypes },
6761
7469
  { method: "POST", path: "/admin/types", public: false, handler: createType },
@@ -6825,7 +7533,13 @@ function matchPath(pattern, path) {
6825
7533
  function notFound() {
6826
7534
  return Response.json({ error: "Not found" }, { status: 404 });
6827
7535
  }
7536
+ function requireOrganizationScoping() {
7537
+ if (typeof engine.withOrganization !== "function") {
7538
+ throw new Error("@ordinatio/scheduling-api 0.3 needs @ordinatio/scheduling 0.5.0 or newer: this engine does not limit results to an organization. Update @ordinatio/scheduling.");
7539
+ }
7540
+ }
6828
7541
  function createSchedulingApi(config) {
7542
+ requireOrganizationScoping();
6829
7543
  const routes = config.routes ?? ROUTES;
6830
7544
  const basePath = (config.basePath ?? "/api/scheduling").replace(/\/+$/, "");
6831
7545
  const host = {
@@ -6834,6 +7548,11 @@ function createSchedulingApi(config) {
6834
7548
  tenantDb: config.host.tenantDb?.bind(config.host) ?? (() => config.host.publicDb()),
6835
7549
  events: { emit: async () => void 0 },
6836
7550
  webhooks: config.host.webhooks ?? null,
7551
+ waitlist: config.host.waitlist ?? null,
7552
+ routingForms: config.host.routingForms ?? null,
7553
+ privacy: config.host.privacy ?? null,
7554
+ brand: config.host.brand ?? null,
7555
+ icalUidDomain: config.host.icalUidDomain?.bind(config.host) ?? (() => null),
6837
7556
  calendarSync: config.host.calendarSync ?? { upsertEvent: async () => ({}), removeEvent: async () => void 0 },
6838
7557
  activity: config.host.activity ?? { log: async () => void 0, isOpen: async () => false, resolve: async () => void 0 },
6839
7558
  appUrl: config.host.appUrl?.bind(config.host) ?? (() => null),
@@ -6859,7 +7578,7 @@ function createSchedulingApi(config) {
6859
7578
  jsonNull: config.host.jsonNull?.bind(config.host) ?? (() => null),
6860
7579
  cors: config.host.cors?.bind(config.host) ?? defaultCorsHeaders
6861
7580
  };
6862
- host.events = withWebhooks(config.host.events ?? { emit: async () => void 0 }, host);
7581
+ host.events = withWebhooks(withWaitlist(config.host.events ?? { emit: async () => void 0 }, host), host);
6863
7582
  async function handle(request) {
6864
7583
  const { pathname } = new URL(request.url);
6865
7584
  if (pathname !== basePath && !pathname.startsWith(`${basePath}/`)) return notFound();
@@ -7013,6 +7732,7 @@ export {
7013
7732
  BalanceRequestInProgressError,
7014
7733
  BookingPageConfigSchema,
7015
7734
  BookingPageThemeSchema,
7735
+ BrandSchema,
7016
7736
  CancelRecurringScopeSchema,
7017
7737
  CancelRecurringSeriesSchema,
7018
7738
  CreateAppointmentCategorySchema,
@@ -7023,6 +7743,7 @@ export {
7023
7743
  CreateNotificationTemplateSchema,
7024
7744
  CreatePackagePurchaseSchema,
7025
7745
  CreateRecurringSeriesSchema,
7746
+ CreateRoutingFormSchema,
7026
7747
  CreateServicePackageSchema,
7027
7748
  CreateWebhookEndpointSchema,
7028
7749
  DEFAULT_CANCELLATION_POLICY,
@@ -7031,13 +7752,17 @@ export {
7031
7752
  NotificationChannelSchema,
7032
7753
  NotificationTriggerSchema,
7033
7754
  OrgCancellationPolicySchema,
7755
+ PrivacyEraseSchema,
7756
+ PrivacySubjectSchema,
7034
7757
  RETRYABLE_REFUND_STATUSES,
7035
7758
  RecurringFrequencySchema,
7036
7759
  RefundOutcomePersistenceError,
7760
+ RouteClientSchema,
7037
7761
  SLOT_GRANULARITY_DEFAULT,
7038
7762
  SLOT_GRANULARITY_OPTIONS,
7039
7763
  TERMINAL_SUCCESS_STATUSES,
7040
7764
  TOKEN_TTL_DAYS,
7765
+ TestRoutingFormSchema,
7041
7766
  UnverifiedPaymentError,
7042
7767
  UpdateAppointmentCategorySchema,
7043
7768
  UpdateAppointmentTypeSchema,
@@ -7046,6 +7771,7 @@ export {
7046
7771
  UpdateCouponCodeSchema,
7047
7772
  UpdateNotificationTemplateSchema,
7048
7773
  UpdatePackagePurchaseSchema,
7774
+ UpdateRoutingFormSchema,
7049
7775
  UpdateServicePackageSchema,
7050
7776
  attemptLegRefund,
7051
7777
  createBalanceIntent,