@odla-ai/chapter 0.33.1 → 0.34.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 +5 -0
- package/dist/index.cjs +93 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +37 -8
- package/dist/index.d.ts +37 -8
- package/dist/index.js +95 -0
- package/dist/index.js.map +1 -1
- package/dist/worker/index.cjs +34 -7
- package/dist/worker/index.cjs.map +1 -1
- package/dist/worker/index.js +34 -7
- package/dist/worker/index.js.map +1 -1
- package/package.json +2 -1
- package/runbooks/greenfield.md +4 -0
package/dist/worker/index.cjs
CHANGED
|
@@ -570,11 +570,16 @@ function groupAttrs(document) {
|
|
|
570
570
|
return {
|
|
571
571
|
...first ? { standardPriceCents: first.priceCents } : {},
|
|
572
572
|
foundingDiscountCents: 0,
|
|
573
|
-
stripePriceId: firstPaid
|
|
573
|
+
...firstPaid?.stripePriceId ? { stripePriceId: firstPaid.stripePriceId } : {},
|
|
574
574
|
...document.policy ?? {},
|
|
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,22 +591,40 @@ 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))
|
|
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
|
-
|
|
599
|
+
const tierRef = byPublicId("tiers", tier.id);
|
|
600
|
+
ops.push({ t: "update", ns: "tiers", id: tierRef, attrs: {
|
|
593
601
|
id: tier.id,
|
|
594
602
|
groupId: document.target.chapterId,
|
|
595
603
|
name: tier.name,
|
|
596
604
|
priceCents: tier.priceCents,
|
|
597
|
-
stripePriceId: tier.stripePriceId
|
|
598
|
-
blurb: tier.blurb
|
|
605
|
+
...tier.stripePriceId ? { stripePriceId: tier.stripePriceId } : {},
|
|
606
|
+
...tier.blurb ? { blurb: tier.blurb } : {},
|
|
599
607
|
sortOrder: tier.sortOrder,
|
|
600
608
|
active: tier.available,
|
|
601
609
|
createdAt: receivedAt
|
|
602
610
|
} });
|
|
611
|
+
const retract = [
|
|
612
|
+
...!tier.stripePriceId ? ["stripePriceId"] : [],
|
|
613
|
+
...!tier.blurb ? ["blurb"] : []
|
|
614
|
+
];
|
|
615
|
+
if (retract.length) ops.push({ t: "retract", ns: "tiers", id: tierRef, attrs: retract });
|
|
616
|
+
}
|
|
617
|
+
const groupRef = byPublicId("groups", document.target.chapterId);
|
|
618
|
+
const attrs = groupAttrs(document);
|
|
619
|
+
ops.push({
|
|
620
|
+
t: "update",
|
|
621
|
+
ns: "groups",
|
|
622
|
+
id: groupRef,
|
|
623
|
+
attrs
|
|
624
|
+
});
|
|
625
|
+
if (!("stripePriceId" in attrs)) {
|
|
626
|
+
ops.push({ t: "retract", ns: "groups", id: groupRef, attrs: ["stripePriceId"] });
|
|
603
627
|
}
|
|
604
|
-
ops.push({ t: "update", ns: "groups", id: document.target.chapterId, attrs: groupAttrs(document) });
|
|
605
628
|
const id = `signup-control:${document.target.environment}:${document.revision}`;
|
|
606
629
|
ops.push({ t: "update", ns: "signupControls", id, attrs: {
|
|
607
630
|
id,
|
|
@@ -1826,7 +1849,11 @@ var handleSignupControl = async (req, url, env, ctx) => {
|
|
|
1826
1849
|
});
|
|
1827
1850
|
}
|
|
1828
1851
|
const receivedAt = Date.now();
|
|
1829
|
-
|
|
1852
|
+
try {
|
|
1853
|
+
await materializeSignupControl(db, { digest, document }, latest, receivedAt);
|
|
1854
|
+
} catch {
|
|
1855
|
+
return reject("materialization_failed", 503);
|
|
1856
|
+
}
|
|
1830
1857
|
return json({
|
|
1831
1858
|
ok: true,
|
|
1832
1859
|
target: { chapterId: ctx.chapter.id, environment: env.ODLA_ENV },
|