@odla-ai/chapter 0.47.6 → 0.47.8

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.
@@ -1,7 +1,7 @@
1
1
  import * as preact from 'preact';
2
2
  import { ComponentChildren, JSX } from 'preact';
3
- import { d as MemberContentProjection, e as MemberContentPageProjection, b as ChapterCopy, f as ChapterBrand } from '../../copy-context-20WFI5TI.js';
4
- export { C as ChapterCopyProvider, u as useChapterCopy } from '../../copy-context-20WFI5TI.js';
3
+ import { d as MemberContentProjection, e as MemberContentPageProjection, b as ChapterCopy, f as ChapterBrand } from '../../copy-context-Dorxp-WK.js';
4
+ export { C as ChapterCopyProvider, u as useChapterCopy } from '../../copy-context-Dorxp-WK.js';
5
5
  import { FieldType, FieldConditions } from '@odla-ai/crm';
6
6
 
7
7
  /** A bookable slot: a start instant in epoch milliseconds. */
@@ -351,6 +351,8 @@ function joinConfig(group, paymentsReady, tiers = [], conditions = {}) {
351
351
  name: group.name,
352
352
  standardPriceCents: group.standardPriceCents ?? 0,
353
353
  foundingDiscountCents: group.foundingDiscountCents ?? 0,
354
+ currency: group.currency ?? "usd",
355
+ interval: group.interval ?? "year",
354
356
  tiers: [...tiers],
355
357
  // The browser evaluates the same conditions the server enforces.
356
358
  conditions,
@@ -383,6 +385,8 @@ function resolveTiers(group, rows5 = []) {
383
385
  groupId: String(group.id ?? ""),
384
386
  name: "Membership",
385
387
  priceCents: group.standardPriceCents ?? 0,
388
+ currency: group.currency ?? "usd",
389
+ interval: group.interval ?? "year",
386
390
  ...group.stripePriceId ? { stripePriceId: group.stripePriceId } : {},
387
391
  sortOrder: 0,
388
392
  active: true
@@ -395,11 +399,13 @@ function findTier(tiers, tierId) {
395
399
  if (!tierId) return tiers.length === 1 ? tiers[0] : null;
396
400
  return tiers.find((tier) => tier.id === tierId) ?? null;
397
401
  }
398
- function joinConfigTiers(tiers) {
402
+ function joinConfigTiers(tiers, defaults = {}) {
399
403
  return tiers.map((tier) => ({
400
404
  id: tier.id,
401
405
  name: tier.name,
402
406
  priceCents: tier.priceCents,
407
+ currency: tier.currency ?? defaults.currency ?? "usd",
408
+ interval: tier.interval ?? defaults.interval ?? "year",
403
409
  blurb: tier.blurb ?? "",
404
410
  free: tierIsFree(tier)
405
411
  }));
@@ -412,6 +418,8 @@ function rowToTier(row, groupId) {
412
418
  groupId: String(row.groupId ?? groupId),
413
419
  name: String(row.name ?? ""),
414
420
  priceCents: typeof row.priceCents === "number" ? row.priceCents : 0,
421
+ ...typeof row.currency === "string" && row.currency ? { currency: row.currency } : {},
422
+ ...row.interval === "year" || row.interval === "month" ? { interval: row.interval } : {},
415
423
  ...typeof row.stripePriceId === "string" && row.stripePriceId ? { stripePriceId: row.stripePriceId } : {},
416
424
  ...typeof row.blurb === "string" ? { blurb: row.blurb } : {},
417
425
  sortOrder: typeof row.sortOrder === "number" ? row.sortOrder : 0,
@@ -1521,6 +1529,8 @@ function groupAttrs(document) {
1521
1529
  const firstPaid = [...document.tiers].find((tier) => tier.available && tier.priceCents > 0);
1522
1530
  return {
1523
1531
  ...first4 ? { standardPriceCents: first4.priceCents } : {},
1532
+ currency: first4?.currency ?? "usd",
1533
+ interval: first4?.interval ?? "year",
1524
1534
  foundingDiscountCents: 0,
1525
1535
  ...firstPaid?.stripePriceId ? { stripePriceId: firstPaid.stripePriceId } : {},
1526
1536
  ...document.policy ?? {},
@@ -1554,6 +1564,8 @@ async function materializeSignupControl(db, envelope, previous, receivedAt) {
1554
1564
  groupId: document.target.chapterId,
1555
1565
  name: tier.name,
1556
1566
  priceCents: tier.priceCents,
1567
+ currency: tier.currency ?? "usd",
1568
+ interval: tier.interval ?? "year",
1557
1569
  ...tier.stripePriceId ? { stripePriceId: tier.stripePriceId } : {},
1558
1570
  ...tier.blurb ? { blurb: tier.blurb } : {},
1559
1571
  sortOrder: tier.sortOrder,
@@ -1970,7 +1982,7 @@ var handleMember = async (req, url, env, ctx) => {
1970
1982
  const activeControl = chapter.signupControl ? await loadActiveSignupControl(db, chapter.id, env.ODLA_ENV) : null;
1971
1983
  const application = controlledApplication(chapter.application, activeControl?.document);
1972
1984
  return json({
1973
- ...joinConfig(group, paymentsReady, joinConfigTiers(offered), application.conditions),
1985
+ ...joinConfig(group, paymentsReady, joinConfigTiers(offered, { currency: typeof group.currency === "string" ? group.currency : void 0, interval: group.interval === "month" ? "month" : "year" }), application.conditions),
1974
1986
  fieldContract: chapterFlowFieldContract(chapter, "join", application),
1975
1987
  copy: { ...chapter.copy.join, ...activeControl?.document.application?.copy ?? {} },
1976
1988
  ...activeControl ? { signupControl: {
@@ -2327,7 +2339,7 @@ var ROOT_KEYS2 = /* @__PURE__ */ new Set([
2327
2339
  "theme",
2328
2340
  "giftOffers"
2329
2341
  ]);
2330
- var TIER_KEYS2 = /* @__PURE__ */ new Set(["id", "name", "available", "sortOrder", "priceCents", "stripePriceId", "blurb"]);
2342
+ var TIER_KEYS2 = /* @__PURE__ */ new Set(["id", "name", "available", "sortOrder", "priceCents", "currency", "interval", "stripePriceId", "blurb"]);
2331
2343
  var recordOf = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : null;
2332
2344
  function unknownKeys(value, allowed2, path, errors) {
2333
2345
  for (const key of Object.keys(value)) if (!allowed2.has(key)) errors.push(`${path}.${key} is not supported`);
@@ -2371,6 +2383,12 @@ function tiersOf(value, errors) {
2371
2383
  if (item.available === true && Number(item.priceCents) > 0 && !item.stripePriceId) {
2372
2384
  errors.push(`${path}.stripePriceId is required for an available paid tier`);
2373
2385
  }
2386
+ if (item.currency !== void 0 && (typeof item.currency !== "string" || !/^[a-z]{3}$/.test(item.currency))) {
2387
+ errors.push(`${path}.currency must be a lowercase ISO currency code`);
2388
+ }
2389
+ if (item.interval !== void 0 && item.interval !== "year" && item.interval !== "month") {
2390
+ errors.push(`${path}.interval must be year or month`);
2391
+ }
2374
2392
  const blurb = item.blurb === void 0 ? void 0 : text2(item.blurb, `${path}.blurb`, errors, 4e3);
2375
2393
  return [{
2376
2394
  id,
@@ -2378,6 +2396,8 @@ function tiersOf(value, errors) {
2378
2396
  available: item.available === true,
2379
2397
  sortOrder: Number(item.sortOrder) || 0,
2380
2398
  priceCents: Number(item.priceCents) || 0,
2399
+ ...typeof item.currency === "string" ? { currency: item.currency } : {},
2400
+ ...item.interval === "year" || item.interval === "month" ? { interval: item.interval } : {},
2381
2401
  ...typeof item.stripePriceId === "string" ? { stripePriceId: item.stripePriceId } : {},
2382
2402
  ...blurb ? { blurb } : {}
2383
2403
  }];