@odla-ai/chapter 0.57.0 → 0.58.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.
@@ -4044,7 +4044,7 @@ var SCHEDULING_DEFAULTS = {
4044
4044
  endHour: 17,
4045
4045
  timezone: "America/Los_Angeles",
4046
4046
  minNoticeHours: 24,
4047
- windowDays: 14,
4047
+ windowDays: 21,
4048
4048
  summaryTemplate: "Introduction call with {{firstName}} {{lastName}}"
4049
4049
  };
4050
4050
  function isValidTimeZone(tz) {
@@ -11069,18 +11069,36 @@ var handleAdminScheduling = async (req, url, env, ctx) => {
11069
11069
  const got = await adminGroup(req, env, ctx, url);
11070
11070
  if (got instanceof Response) return got;
11071
11071
  const { db, group } = got;
11072
+ const stored = group.schedulingJson && typeof group.schedulingJson === "object" && !Array.isArray(group.schedulingJson) ? group.schedulingJson : {};
11072
11073
  if (req.method === "GET") {
11073
- return json({ scheduling: resolveScheduling(group.schedulingJson) });
11074
+ const current = validateScheduling(stored);
11075
+ if (!current.ok) return json({
11076
+ error: "stored scheduling config is invalid; save the form to repair it",
11077
+ errors: current.errors,
11078
+ scheduling: { ...resolveScheduling(void 0), ...stored }
11079
+ }, 409);
11080
+ return json({ scheduling: current.value });
11074
11081
  }
11075
11082
  let body;
11076
11083
  try {
11077
11084
  body = JSON.parse(await req.text());
11085
+ if (!body || typeof body !== "object" || Array.isArray(body)) throw new TypeError("object required");
11078
11086
  } catch {
11079
11087
  return json({ error: "invalid JSON body" }, 400);
11080
11088
  }
11081
- const checked = validateScheduling(body);
11089
+ const checked = validateScheduling({ ...stored, ...body });
11082
11090
  if (!checked.ok) return json({ error: "invalid scheduling config", errors: checked.errors }, 400);
11083
- await db.transact([{ t: "update", ns: "groups", id: String(group.id), attrs: { schedulingJson: checked.value } }]);
11091
+ try {
11092
+ await db.transact([{ t: "update", ns: "groups", id: String(group.id), attrs: { schedulingJson: checked.value } }]);
11093
+ } catch (error) {
11094
+ const code = error.code;
11095
+ console.error("admin_scheduling_write_failed", { code: typeof code === "string" ? code : "unknown" });
11096
+ return json({
11097
+ error: "availability could not be saved; retry",
11098
+ code: "scheduling_write_failed",
11099
+ ...typeof code === "string" ? { cause: code } : {}
11100
+ }, 503);
11101
+ }
11084
11102
  return json({ scheduling: checked.value });
11085
11103
  };
11086
11104
  async function upcomingEvents(env) {