@meterbox/react 0.1.23 → 0.1.24

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meterbox/react",
3
- "version": "0.1.23",
3
+ "version": "0.1.24",
4
4
  "description": "Embeddable React components for Meterbox: pricing tables, subscription preview, credit balance and usage charts. Presentational by default, with data fetched by your backend via @meterbox/node.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://meterbox.ai",
@@ -12,7 +12,9 @@
12
12
  * supplied; invokes `onSelect(plan, billingInterval)` when a CTA is
13
13
  * clicked so the tenant can route to their own checkout / contact form —
14
14
  * `billingInterval` ("monthly" or "annual") is whichever the shopper had
15
- * selected, ready to pass straight to `<CheckoutButton billingInterval>`.
15
+ * selected, ready to pass straight to `<CheckoutButton billingInterval>`:
16
+ * "annual" only for a monthly plan's annual prepay; any plan billed another
17
+ * interval (`billing_interval`) gets "monthly", meaning its own interval.
16
18
  *
17
19
  * A monthly/annual toggle renders automatically when at least one plan
18
20
  * has `annual_free_months` set (the same field the tenant configures via
@@ -21,6 +23,13 @@
21
23
  * total divided back into a misleading "$X/mo" figure — a shopper who
22
24
  * commits annually is billed once for the year, not monthly.
23
25
  *
26
+ * A plan billed other than monthly (`billing_interval`: week, quarter,
27
+ * half_year, year) shows its monthly price with how often it's billed under
28
+ * it ("billed every quarter", with "usage billed every month" when its
29
+ * `usage_interval` bills usage more often). When any plan does, the toggle offers each
30
+ * interval the plans use instead (yearly plans and annual prepay together
31
+ * under "Annual") and shows that tab's plans.
32
+ *
24
33
  * With `showUsage` (off by default), a plan with `usage` (the pricing
25
34
  * snapshot and the customer portal's plan list carry it) also shows its
26
35
  * included amounts, what happens past them, and its models' input and output
@@ -364,6 +373,8 @@ function fromSnapshot(p) {
364
373
  promotion: p.promotion || null,
365
374
  stripe_price_monthly_usd: p.price ? p.price.monthly_usd : null,
366
375
  annual_free_months: p.annual_free_months == null ? null : p.annual_free_months,
376
+ billing_interval: p.billing_interval || "month",
377
+ usage_interval: p.usage_interval || null,
367
378
  localized_prices: p.localized_prices || [],
368
379
  usage: p.usage || null,
369
380
  highlight: !!p.highlight,
@@ -434,25 +445,56 @@ function PricingTable({
434
445
  }
435
446
 
436
447
  const hasAnnualOption = list.some((p) => p.annual_free_months != null);
448
+ // How often each plan bills (`billing_interval`; its price is per month
449
+ // either way). With every plan monthly, the toggle is monthly or annual
450
+ // prepay, as before. With plans billed other intervals, it offers each one
451
+ // used (yearly plans together with annual prepay) and shows that tab's plans.
452
+ const intervalOf = (p) => p.billing_interval || "month";
453
+ const TAB_OF = {
454
+ week: "weekly",
455
+ month: "monthly",
456
+ quarter: "quarter",
457
+ half_year: "half_year",
458
+ year: "annual",
459
+ };
460
+ const others = list.some((p) => intervalOf(p) !== "month");
461
+ const tabs = others
462
+ ? ["weekly", "monthly", "quarter", "half_year", "annual"].filter((tab) =>
463
+ list.some(
464
+ (p) =>
465
+ TAB_OF[intervalOf(p)] === tab || (tab === "annual" && p.annual_free_months != null),
466
+ ),
467
+ )
468
+ : hasAnnualOption
469
+ ? ["monthly", "annual"]
470
+ : [];
471
+ const tab = tabs.includes(billingInterval) ? billingInterval : tabs[0];
472
+ const shown = others
473
+ ? list.filter(
474
+ (p) =>
475
+ TAB_OF[intervalOf(p)] === tab ||
476
+ (tab === "annual" && intervalOf(p) === "month" && p.annual_free_months != null),
477
+ )
478
+ : list;
437
479
 
438
480
  return React.createElement(
439
481
  "div",
440
482
  { className: "meterbox-pricing-table", style: { ...styles.wrap, ...vars } },
441
- hasAnnualOption &&
483
+ tabs.length > 1 &&
442
484
  React.createElement(
443
485
  "div",
444
486
  { style: styles.toggle },
445
- ["monthly", "annual"].map((interval) =>
487
+ tabs.map((interval) =>
446
488
  React.createElement(
447
489
  "button",
448
490
  {
449
491
  key: interval,
450
492
  type: "button",
451
493
  style:
452
- billingInterval === interval
494
+ tab === interval
453
495
  ? { ...styles.toggleBtn, ...styles.toggleBtnActive }
454
496
  : styles.toggleBtn,
455
- "aria-pressed": billingInterval === interval,
497
+ "aria-pressed": tab === interval,
456
498
  onClick: () => setBillingInterval(interval),
457
499
  },
458
500
  t(`pricing.${interval}`),
@@ -462,7 +504,7 @@ function PricingTable({
462
504
  React.createElement(
463
505
  "div",
464
506
  { style: styles.grid },
465
- list.map((plan) => {
507
+ shown.map((plan) => {
466
508
  const isCurrent = plan.id === currentPlanId;
467
509
  const isSelected = plan.id === selectedPlanId;
468
510
  const localized = (plan.localized_prices || []).find(
@@ -475,7 +517,15 @@ function PricingTable({
475
517
  // Annual only applies when THIS plan offers it — a plan without
476
518
  // annual_free_months always shows its monthly price, even while the
477
519
  // toggle above is set to "Annual" for its siblings.
478
- const annual = billingInterval === "annual" ? annualPriceUsd(plan) : null;
520
+ const annual =
521
+ tab === "annual" && intervalOf(plan) === "month" ? annualPriceUsd(plan) : null;
522
+ // A plan billed other than monthly says how often, under its monthly price.
523
+ const billedKey = {
524
+ week: "pricing.billed.week",
525
+ quarter: "pricing.billed.quarter",
526
+ half_year: "pricing.billed.half_year",
527
+ year: "pricing.billedAnnually",
528
+ }[intervalOf(plan)];
479
529
  const link = !onSelect && !isCurrent ? ctaLink(plan, customerEmail) : null;
480
530
  // A promotion is on the monthly USD price.
481
531
  const promo =
@@ -513,6 +563,20 @@ function PricingTable({
513
563
  { key: "period", style: styles.perMonth },
514
564
  annual != null ? t("pricing.billedAnnually") : t("pricing.perMonth"),
515
565
  ),
566
+ billedKey &&
567
+ React.createElement(
568
+ "div",
569
+ { key: "billed", style: styles.perMonth },
570
+ // Usage billed more often than the fee says so too.
571
+ [
572
+ t(billedKey),
573
+ plan.usage_interval && plan.usage_interval !== intervalOf(plan)
574
+ ? t(`pricing.usage.${plan.usage_interval}`)
575
+ : null,
576
+ ]
577
+ .filter(Boolean)
578
+ .join(", "),
579
+ ),
516
580
  ];
517
581
  }
518
582
  let action;
@@ -539,7 +603,13 @@ function PricingTable({
539
603
  type: "button",
540
604
  style: isCurrent ? { ...styles.cta, ...styles.ctaCurrent } : styles.cta,
541
605
  disabled: isCurrent,
542
- onClick: () => (onSelect ? onSelect(plan, billingInterval) : undefined),
606
+ onClick: () =>
607
+ onSelect
608
+ ? onSelect(
609
+ plan,
610
+ intervalOf(plan) === "month" && tab === "annual" ? "annual" : "monthly",
611
+ )
612
+ : undefined,
543
613
  "aria-label": t(isCurrent ? "pricing.currentlyOn" : "pricing.choose", {
544
614
  plan: plan.name || plan.id,
545
615
  }),
package/src/i18n.js CHANGED
@@ -77,6 +77,15 @@ const en = {
77
77
  "pricing.custom": "Custom",
78
78
  "pricing.perMonth": "/ month",
79
79
  "pricing.billedAnnually": "billed annually",
80
+ "pricing.weekly": "Weekly",
81
+ "pricing.quarter": "Quarterly",
82
+ "pricing.half_year": "Every 6 months",
83
+ "pricing.billed.week": "billed every week",
84
+ "pricing.billed.quarter": "billed every quarter",
85
+ "pricing.billed.half_year": "billed every 6 months",
86
+ "pricing.usage.month": "usage billed every month",
87
+ "pricing.usage.quarter": "usage billed every quarter",
88
+ "pricing.usage.half_year": "usage billed every 6 months",
80
89
  "pricing.trial": "{days}-day free trial",
81
90
  "pricing.endsAfter": "For {days} days, then choose a plan",
82
91
  "pricing.includes": "Includes {parts} a month",
@@ -85,7 +94,7 @@ const en = {
85
94
  "pricing.apiCalls": "{n} API calls",
86
95
  "pricing.per1M": "Per 1M tokens:",
87
96
  "pricing.past.billed": "Past that, per 1M tokens:",
88
- "pricing.past.blocked": "Usage stops there until next month.",
97
+ "pricing.past.blocked": "Usage stops there until the next billing period.",
89
98
  "pricing.past.upgrade": "Past that, your plan is upgraded automatically.",
90
99
  "pricing.models": "Models: {names}",
91
100
  "pricing.modelRates": "{model}: {input} in, {output} out",
@@ -252,6 +261,15 @@ const es = {
252
261
  "pricing.custom": "Personalizado",
253
262
  "pricing.perMonth": "/ mes",
254
263
  "pricing.billedAnnually": "facturado anualmente",
264
+ "pricing.weekly": "Semanal",
265
+ "pricing.quarter": "Trimestral",
266
+ "pricing.half_year": "Semestral",
267
+ "pricing.billed.week": "facturado cada semana",
268
+ "pricing.billed.quarter": "facturado cada trimestre",
269
+ "pricing.billed.half_year": "facturado cada 6 meses",
270
+ "pricing.usage.month": "uso facturado cada mes",
271
+ "pricing.usage.quarter": "uso facturado cada trimestre",
272
+ "pricing.usage.half_year": "uso facturado cada 6 meses",
255
273
  "pricing.trial": "Prueba gratuita de {days} días",
256
274
  "pricing.endsAfter": "Durante {days} días; luego elige un plan",
257
275
  "pricing.includes": "Incluye {parts} al mes",
@@ -260,7 +278,7 @@ const es = {
260
278
  "pricing.apiCalls": "{n} llamadas a la API",
261
279
  "pricing.per1M": "Por 1M de tokens:",
262
280
  "pricing.past.billed": "Después, por 1M de tokens:",
263
- "pricing.past.blocked": "El uso se detiene ahí hasta el próximo mes.",
281
+ "pricing.past.blocked": "El uso se detiene ahí hasta el próximo periodo de facturación.",
264
282
  "pricing.past.upgrade": "Después, tu plan se mejora automáticamente.",
265
283
  "pricing.models": "Modelos: {names}",
266
284
  "pricing.modelRates": "{model}: {input} entrada, {output} salida",
@@ -428,6 +446,15 @@ const fr = {
428
446
  "pricing.custom": "Sur mesure",
429
447
  "pricing.perMonth": "/ mois",
430
448
  "pricing.billedAnnually": "facturé annuellement",
449
+ "pricing.weekly": "Hebdomadaire",
450
+ "pricing.quarter": "Trimestriel",
451
+ "pricing.half_year": "Semestriel",
452
+ "pricing.billed.week": "facturé chaque semaine",
453
+ "pricing.billed.quarter": "facturé chaque trimestre",
454
+ "pricing.billed.half_year": "facturé tous les 6 mois",
455
+ "pricing.usage.month": "utilisation facturée chaque mois",
456
+ "pricing.usage.quarter": "utilisation facturée chaque trimestre",
457
+ "pricing.usage.half_year": "utilisation facturée tous les 6 mois",
431
458
  "pricing.trial": "Essai gratuit de {days} jours",
432
459
  "pricing.endsAfter": "Pendant {days} jours, puis choisissez une offre",
433
460
  "pricing.includes": "Inclut {parts} par mois",
@@ -436,7 +463,7 @@ const fr = {
436
463
  "pricing.apiCalls": "{n} appels API",
437
464
  "pricing.per1M": "Par million de tokens :",
438
465
  "pricing.past.billed": "Au-delà, par million de tokens :",
439
- "pricing.past.blocked": "L'utilisation s'arrête là jusqu'au mois prochain.",
466
+ "pricing.past.blocked": "L'utilisation s'arrête là jusqu'à la prochaine période de facturation.",
440
467
  "pricing.past.upgrade": "Au-delà, votre forfait passe automatiquement au niveau supérieur.",
441
468
  "pricing.models": "Modèles : {names}",
442
469
  "pricing.modelRates": "{model} : {input} en entrée, {output} en sortie",
@@ -606,6 +633,15 @@ const de = {
606
633
  "pricing.custom": "Individuell",
607
634
  "pricing.perMonth": "/ Monat",
608
635
  "pricing.billedAnnually": "jährlich abgerechnet",
636
+ "pricing.weekly": "Wöchentlich",
637
+ "pricing.quarter": "Vierteljährlich",
638
+ "pricing.half_year": "Halbjährlich",
639
+ "pricing.billed.week": "wöchentlich abgerechnet",
640
+ "pricing.billed.quarter": "vierteljährlich abgerechnet",
641
+ "pricing.billed.half_year": "halbjährlich abgerechnet",
642
+ "pricing.usage.month": "Nutzung monatlich abgerechnet",
643
+ "pricing.usage.quarter": "Nutzung vierteljährlich abgerechnet",
644
+ "pricing.usage.half_year": "Nutzung halbjährlich abgerechnet",
609
645
  "pricing.trial": "{days} Tage kostenlos testen",
610
646
  "pricing.endsAfter": "{days} Tage lang, danach einen Tarif wählen",
611
647
  "pricing.includes": "Enthält {parts} pro Monat",
@@ -614,7 +650,7 @@ const de = {
614
650
  "pricing.apiCalls": "{n} API-Aufrufe",
615
651
  "pricing.per1M": "Pro 1 Mio. Tokens:",
616
652
  "pricing.past.billed": "Darüber hinaus pro 1 Mio. Tokens:",
617
- "pricing.past.blocked": "Die Nutzung stoppt dann bis zum nächsten Monat.",
653
+ "pricing.past.blocked": "Die Nutzung stoppt dann bis zum nächsten Abrechnungszeitraum.",
618
654
  "pricing.past.upgrade": "Darüber hinaus wird Ihr Tarif automatisch hochgestuft.",
619
655
  "pricing.models": "Modelle: {names}",
620
656
  "pricing.modelRates": "{model}: {input} Input, {output} Output",