@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.
@@ -12,6 +12,8 @@ interface ChapterTierConfig {
12
12
  id: string;
13
13
  name: string;
14
14
  priceCents: number;
15
+ currency?: string;
16
+ interval?: "year" | "month";
15
17
  stripePriceId?: string;
16
18
  blurb?: string;
17
19
  /** Defaults to declaration order when omitted. */
package/dist/index.cjs CHANGED
@@ -18,8 +18,8 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
20
  // src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
23
  ADMISSION_GRANTS_PATH: () => ADMISSION_GRANTS_PATH,
24
24
  ADMISSION_GRANTS_SCHEMA_VERSION: () => ADMISSION_GRANTS_SCHEMA_VERSION,
25
25
  BUILDER_LIBRARY_ADMIN_PATH: () => BUILDER_LIBRARY_ADMIN_PATH,
@@ -210,7 +210,7 @@ __export(index_exports, {
210
210
  verifyStripeSignature: () => import_stripe.verifyStripeSignature,
211
211
  webhookMutationId: () => webhookMutationId
212
212
  });
213
- module.exports = __toCommonJS(index_exports);
213
+ module.exports = __toCommonJS(src_exports);
214
214
 
215
215
  // src/config.ts
216
216
  var import_crm2 = require("@odla-ai/crm");
@@ -374,6 +374,8 @@ function joinConfig(group, paymentsReady2, tiers2 = [], conditions = {}) {
374
374
  name: group.name,
375
375
  standardPriceCents: group.standardPriceCents ?? 0,
376
376
  foundingDiscountCents: group.foundingDiscountCents ?? 0,
377
+ currency: group.currency ?? "usd",
378
+ interval: group.interval ?? "year",
377
379
  tiers: [...tiers2],
378
380
  // The browser evaluates the same conditions the server enforces.
379
381
  conditions,
@@ -930,6 +932,8 @@ var groups = {
930
932
  name: attr5("string"),
931
933
  standardPriceCents: attr5("number"),
932
934
  foundingDiscountCents: attr5("number"),
935
+ currency: attr5("string", { optional: true }),
936
+ interval: attr5("string", { optional: true }),
933
937
  stripePriceId: attr5("string", { optional: true }),
934
938
  stripePublishableKey: attr5("string", { optional: true }),
935
939
  notificationEmail: attr5("string"),
@@ -953,6 +957,8 @@ var tiers = {
953
957
  groupId: attr5("string", { indexed: true }),
954
958
  name: attr5("string"),
955
959
  priceCents: attr5("number"),
960
+ currency: attr5("string", { optional: true }),
961
+ interval: attr5("string", { optional: true }),
956
962
  stripePriceId: attr5("string", { optional: true }),
957
963
  blurb: attr5("string", { optional: true }),
958
964
  sortOrder: attr5("number", { indexed: true }),
@@ -1170,6 +1176,8 @@ function buildGroupSeed(config) {
1170
1176
  name: config.name,
1171
1177
  standardPriceCents: prices?.standardCents ?? 0,
1172
1178
  foundingDiscountCents: prices?.foundingDiscountCents ?? 0,
1179
+ currency: prices?.currency ?? "usd",
1180
+ interval: prices?.interval ?? "year",
1173
1181
  notificationEmail: emails?.notificationEmail ?? "",
1174
1182
  replyTo: emails?.replyTo ?? emails?.notificationEmail ?? "",
1175
1183
  disclaimerText: policy.disclaimerText ?? "",
@@ -2910,6 +2918,8 @@ function buildTierSeeds(groupId, configured = [], now = 0) {
2910
2918
  groupId,
2911
2919
  name: tier.name,
2912
2920
  priceCents: tier.priceCents,
2921
+ ...tier.currency ? { currency: tier.currency } : {},
2922
+ ...tier.interval ? { interval: tier.interval } : {},
2913
2923
  ...tier.stripePriceId ? { stripePriceId: tier.stripePriceId } : {},
2914
2924
  ...tier.blurb ? { blurb: tier.blurb } : {},
2915
2925
  sortOrder: tier.sortOrder ?? index2,
@@ -2935,6 +2945,8 @@ function resolveTiers(group, rows3 = []) {
2935
2945
  groupId: String(group.id ?? ""),
2936
2946
  name: "Membership",
2937
2947
  priceCents: group.standardPriceCents ?? 0,
2948
+ currency: group.currency ?? "usd",
2949
+ interval: group.interval ?? "year",
2938
2950
  ...group.stripePriceId ? { stripePriceId: group.stripePriceId } : {},
2939
2951
  sortOrder: 0,
2940
2952
  active: true
@@ -2947,11 +2959,13 @@ function findTier(tiers2, tierId) {
2947
2959
  if (!tierId) return tiers2.length === 1 ? tiers2[0] : null;
2948
2960
  return tiers2.find((tier) => tier.id === tierId) ?? null;
2949
2961
  }
2950
- function joinConfigTiers(tiers2) {
2962
+ function joinConfigTiers(tiers2, defaults = {}) {
2951
2963
  return tiers2.map((tier) => ({
2952
2964
  id: tier.id,
2953
2965
  name: tier.name,
2954
2966
  priceCents: tier.priceCents,
2967
+ currency: tier.currency ?? defaults.currency ?? "usd",
2968
+ interval: tier.interval ?? defaults.interval ?? "year",
2955
2969
  blurb: tier.blurb ?? "",
2956
2970
  free: tierIsFree(tier)
2957
2971
  }));
@@ -4962,6 +4976,8 @@ function rowToTier(row, groupId) {
4962
4976
  groupId: String(row.groupId ?? groupId),
4963
4977
  name: String(row.name ?? ""),
4964
4978
  priceCents: typeof row.priceCents === "number" ? row.priceCents : 0,
4979
+ ...typeof row.currency === "string" && row.currency ? { currency: row.currency } : {},
4980
+ ...row.interval === "year" || row.interval === "month" ? { interval: row.interval } : {},
4965
4981
  ...typeof row.stripePriceId === "string" && row.stripePriceId ? { stripePriceId: row.stripePriceId } : {},
4966
4982
  ...typeof row.blurb === "string" ? { blurb: row.blurb } : {},
4967
4983
  sortOrder: typeof row.sortOrder === "number" ? row.sortOrder : 0,
@@ -5178,7 +5194,7 @@ var ROOT_KEYS4 = /* @__PURE__ */ new Set([
5178
5194
  "theme",
5179
5195
  "giftOffers"
5180
5196
  ]);
5181
- var TIER_KEYS2 = /* @__PURE__ */ new Set(["id", "name", "available", "sortOrder", "priceCents", "stripePriceId", "blurb"]);
5197
+ var TIER_KEYS2 = /* @__PURE__ */ new Set(["id", "name", "available", "sortOrder", "priceCents", "currency", "interval", "stripePriceId", "blurb"]);
5182
5198
  var recordOf = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : null;
5183
5199
  function unknownKeys3(value, allowed2, path, errors) {
5184
5200
  for (const key of Object.keys(value)) if (!allowed2.has(key)) errors.push(`${path}.${key} is not supported`);
@@ -5222,6 +5238,12 @@ function tiersOf(value, errors) {
5222
5238
  if (item.available === true && Number(item.priceCents) > 0 && !item.stripePriceId) {
5223
5239
  errors.push(`${path}.stripePriceId is required for an available paid tier`);
5224
5240
  }
5241
+ if (item.currency !== void 0 && (typeof item.currency !== "string" || !/^[a-z]{3}$/.test(item.currency))) {
5242
+ errors.push(`${path}.currency must be a lowercase ISO currency code`);
5243
+ }
5244
+ if (item.interval !== void 0 && item.interval !== "year" && item.interval !== "month") {
5245
+ errors.push(`${path}.interval must be year or month`);
5246
+ }
5225
5247
  const blurb = item.blurb === void 0 ? void 0 : text5(item.blurb, `${path}.blurb`, errors, 4e3);
5226
5248
  return [{
5227
5249
  id: id6,
@@ -5229,6 +5251,8 @@ function tiersOf(value, errors) {
5229
5251
  available: item.available === true,
5230
5252
  sortOrder: Number(item.sortOrder) || 0,
5231
5253
  priceCents: Number(item.priceCents) || 0,
5254
+ ...typeof item.currency === "string" ? { currency: item.currency } : {},
5255
+ ...item.interval === "year" || item.interval === "month" ? { interval: item.interval } : {},
5232
5256
  ...typeof item.stripePriceId === "string" ? { stripePriceId: item.stripePriceId } : {},
5233
5257
  ...blurb ? { blurb } : {}
5234
5258
  }];