@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.
@@ -4104,7 +4104,7 @@ var SCHEDULING_DEFAULTS = {
4104
4104
  endHour: 17,
4105
4105
  timezone: "America/Los_Angeles",
4106
4106
  minNoticeHours: 24,
4107
- windowDays: 14,
4107
+ windowDays: 21,
4108
4108
  summaryTemplate: "Introduction call with {{firstName}} {{lastName}}"
4109
4109
  };
4110
4110
  function isValidTimeZone(tz) {
@@ -11129,18 +11129,36 @@ var handleAdminScheduling = async (req, url, env, ctx) => {
11129
11129
  const got = await adminGroup(req, env, ctx, url);
11130
11130
  if (got instanceof Response) return got;
11131
11131
  const { db, group } = got;
11132
+ const stored = group.schedulingJson && typeof group.schedulingJson === "object" && !Array.isArray(group.schedulingJson) ? group.schedulingJson : {};
11132
11133
  if (req.method === "GET") {
11133
- return json({ scheduling: resolveScheduling(group.schedulingJson) });
11134
+ const current = validateScheduling(stored);
11135
+ if (!current.ok) return json({
11136
+ error: "stored scheduling config is invalid; save the form to repair it",
11137
+ errors: current.errors,
11138
+ scheduling: { ...resolveScheduling(void 0), ...stored }
11139
+ }, 409);
11140
+ return json({ scheduling: current.value });
11134
11141
  }
11135
11142
  let body;
11136
11143
  try {
11137
11144
  body = JSON.parse(await req.text());
11145
+ if (!body || typeof body !== "object" || Array.isArray(body)) throw new TypeError("object required");
11138
11146
  } catch {
11139
11147
  return json({ error: "invalid JSON body" }, 400);
11140
11148
  }
11141
- const checked = validateScheduling(body);
11149
+ const checked = validateScheduling({ ...stored, ...body });
11142
11150
  if (!checked.ok) return json({ error: "invalid scheduling config", errors: checked.errors }, 400);
11143
- await db.transact([{ t: "update", ns: "groups", id: String(group.id), attrs: { schedulingJson: checked.value } }]);
11151
+ try {
11152
+ await db.transact([{ t: "update", ns: "groups", id: String(group.id), attrs: { schedulingJson: checked.value } }]);
11153
+ } catch (error) {
11154
+ const code = error.code;
11155
+ console.error("admin_scheduling_write_failed", { code: typeof code === "string" ? code : "unknown" });
11156
+ return json({
11157
+ error: "availability could not be saved; retry",
11158
+ code: "scheduling_write_failed",
11159
+ ...typeof code === "string" ? { cause: code } : {}
11160
+ }, 503);
11161
+ }
11144
11162
  return json({ scheduling: checked.value });
11145
11163
  };
11146
11164
  async function upcomingEvents(env) {