@odla-ai/chapter 0.33.1 → 0.33.2

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.
@@ -575,6 +575,11 @@ function groupAttrs(document) {
575
575
  ...document.scheduling ? { schedulingJson: document.scheduling } : {}
576
576
  };
577
577
  }
578
+ var byPublicId = (ns, value) => ({
579
+ ns,
580
+ attr: "id",
581
+ value
582
+ });
578
583
  async function materializeSignupControl(db, envelope, previous, receivedAt) {
579
584
  const { document, digest } = envelope;
580
585
  const currentRows = (await db.query({ tiers: { $: {
@@ -586,10 +591,12 @@ async function materializeSignupControl(db, envelope, previous, receivedAt) {
586
591
  if (previous?.active) ops.push({ t: "update", ns: "signupControls", id: previous.id, attrs: { active: false } });
587
592
  for (const row of currentRows) {
588
593
  const id2 = String(row.id ?? "");
589
- if (id2 && !incoming.has(id2)) ops.push({ t: "update", ns: "tiers", id: id2, attrs: { active: false } });
594
+ if (id2 && !incoming.has(id2)) {
595
+ ops.push({ t: "update", ns: "tiers", id: byPublicId("tiers", id2), attrs: { active: false } });
596
+ }
590
597
  }
591
598
  for (const tier of document.tiers) {
592
- ops.push({ t: "update", ns: "tiers", id: tier.id, attrs: {
599
+ ops.push({ t: "update", ns: "tiers", id: byPublicId("tiers", tier.id), attrs: {
593
600
  id: tier.id,
594
601
  groupId: document.target.chapterId,
595
602
  name: tier.name,
@@ -601,7 +608,12 @@ async function materializeSignupControl(db, envelope, previous, receivedAt) {
601
608
  createdAt: receivedAt
602
609
  } });
603
610
  }
604
- ops.push({ t: "update", ns: "groups", id: document.target.chapterId, attrs: groupAttrs(document) });
611
+ ops.push({
612
+ t: "update",
613
+ ns: "groups",
614
+ id: byPublicId("groups", document.target.chapterId),
615
+ attrs: groupAttrs(document)
616
+ });
605
617
  const id = `signup-control:${document.target.environment}:${document.revision}`;
606
618
  ops.push({ t: "update", ns: "signupControls", id, attrs: {
607
619
  id,
@@ -1826,7 +1838,11 @@ var handleSignupControl = async (req, url, env, ctx) => {
1826
1838
  });
1827
1839
  }
1828
1840
  const receivedAt = Date.now();
1829
- await materializeSignupControl(db, { digest, document }, latest, receivedAt);
1841
+ try {
1842
+ await materializeSignupControl(db, { digest, document }, latest, receivedAt);
1843
+ } catch {
1844
+ return reject("materialization_failed", 503);
1845
+ }
1830
1846
  return json({
1831
1847
  ok: true,
1832
1848
  target: { chapterId: ctx.chapter.id, environment: env.ODLA_ENV },