@meterbox/react 0.1.24 → 0.1.26

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.24",
3
+ "version": "0.1.26",
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",
@@ -295,6 +295,62 @@ function FeatureInfo({ label, children }) {
295
295
  );
296
296
  }
297
297
 
298
+ /**
299
+ * How a custom dimension is priced, in the reader's language (the
300
+ * snapshot's `dimensions`: charge-models.js on the server): per 1,000
301
+ * units, a percentage of each transaction, per block, or each event's own price.
302
+ */
303
+ function dimensionPrice(i18n, d) {
304
+ const { t, number, money } = i18n;
305
+ const usd = (n) => money(n, "USD");
306
+ const unit = d.unit || d.label;
307
+ if (d.charge_model === "percentage") {
308
+ const p = d.percentage;
309
+ const rate = (r) => `${number(r)}%`;
310
+ const rates = p.tiers
311
+ .map((tier, i) => {
312
+ const r = tier.flat_usd
313
+ ? `${rate(tier.rate_pct)} + ${usd(tier.flat_usd)}`
314
+ : rate(tier.rate_pct);
315
+ const shown = i === 0 ? r : t("pricing.dim.then", { rate: r });
316
+ return tier.up_to == null
317
+ ? shown
318
+ : t("pricing.dim.upTo", { rate: shown, amount: usd(tier.up_to) });
319
+ })
320
+ .join(", ");
321
+ const fee = p.fixed_fee_usd ? ` + ${usd(p.fixed_fee_usd)}` : "";
322
+ return [
323
+ t("pricing.dim.perTransaction", { rates: `${rates}${fee}` }),
324
+ p.min_usd != null ? t("pricing.dim.atLeast", { amount: usd(p.min_usd) }) : null,
325
+ p.max_usd != null ? t("pricing.dim.atMost", { amount: usd(p.max_usd) }) : null,
326
+ p.free_transactions ? t("pricing.dim.freeFirst", { n: number(p.free_transactions) }) : null,
327
+ p.free_amount ? t("pricing.dim.noRateFirst", { amount: usd(p.free_amount) }) : null,
328
+ ]
329
+ .filter(Boolean)
330
+ .join(", ");
331
+ }
332
+ if (d.charge_model === "package") {
333
+ const p = d.package;
334
+ const price = t("pricing.dim.package", {
335
+ price: usd(p.price_usd),
336
+ size: number(p.size),
337
+ unit,
338
+ });
339
+ return p.free_units
340
+ ? `${price}, ${t("pricing.dim.freeFirst", { n: number(p.free_units) })}`
341
+ : price;
342
+ }
343
+ if (d.charge_model === "event_price") return t("pricing.dim.eventPrice", { unit });
344
+ const priced = (d.tiers || []).filter((tier) => tier.per_1k > 0);
345
+ if (!priced.length) return t("pricing.dim.free");
346
+ const lowest = Math.min(...priced.map((tier) => tier.per_1k));
347
+ const key =
348
+ priced.length > 1 || priced.length < d.tiers.length
349
+ ? "pricing.dim.fromPerThousand"
350
+ : "pricing.dim.perThousand";
351
+ return t(key, { price: usd(lowest), unit });
352
+ }
353
+
298
354
  /** Included amounts, what happens past them, and the models' rates. */
299
355
  function PlanUsage({ usage }) {
300
356
  const i18n = useI18n();
@@ -308,18 +364,20 @@ function PlanUsage({ usage }) {
308
364
  .filter(([n]) => n > 0)
309
365
  .map(([n, key]) => t(key, { n: number(n, { notation: "compact" }) }));
310
366
  const billed = overage === "billed";
367
+ // Models with token rates to list (a model priced only by its dimensions has none).
368
+ const tokenPriced = models.filter((m) =>
369
+ [...m.input_tiers, ...m.output_tiers].some((tier) => tier.per_1k > 0),
370
+ );
371
+ let pastLine = t(`pricing.past.${overage}`, null, "");
372
+ if (billed && parts.length === 0) pastLine = tokenPriced.length ? t("pricing.per1M") : "";
311
373
  return React.createElement(
312
374
  "div",
313
375
  { className: "meterbox-plan-usage", style: styles.usage },
314
376
  parts.length > 0 &&
315
377
  React.createElement("div", null, t("pricing.includes", { parts: parts.join(", ") })),
316
- React.createElement(
317
- "div",
318
- { style: { opacity: 0.75 } },
319
- billed && parts.length === 0 ? t("pricing.per1M") : t(`pricing.past.${overage}`, null, ""),
320
- ),
378
+ React.createElement("div", { style: { opacity: 0.75 } }, pastLine),
321
379
  billed
322
- ? models.map((m) =>
380
+ ? tokenPriced.map((m) =>
323
381
  React.createElement(
324
382
  "div",
325
383
  { key: m.id },
@@ -343,6 +401,21 @@ function PlanUsage({ usage }) {
343
401
  null,
344
402
  t("pricing.apiCallRates", { ladder: ladderText(i18n, callTiers, 1) }),
345
403
  ),
404
+ // Each model's custom dimensions: a percentage, per block, per event, …
405
+ billed &&
406
+ models.flatMap((m) =>
407
+ (m.dimensions || []).map((d) =>
408
+ React.createElement(
409
+ "div",
410
+ { key: `${m.id}:${d.name}` },
411
+ t("pricing.dim.line", {
412
+ model: m.name,
413
+ label: d.label,
414
+ price: dimensionPrice(i18n, d),
415
+ }),
416
+ ),
417
+ ),
418
+ ),
346
419
  );
347
420
  }
348
421
 
package/src/i18n.js CHANGED
@@ -22,6 +22,7 @@ const en = {
22
22
  "portal.account": "Account",
23
23
  "portal.plans": "Plans",
24
24
  "portal.credits": "Credits",
25
+ "portal.limits": "Spending limits",
25
26
 
26
27
  "account.loading": "Loading account…",
27
28
  "account.error": "Could not load account.",
@@ -30,7 +31,33 @@ const en = {
30
31
  "account.plan": "Plan",
31
32
  "account.status": "Status",
32
33
  "account.periodEnds": "Current period ends",
34
+ "account.usageSoFar": "Usage so far",
35
+ "account.nextInvoiceAt": "Next invoice at",
36
+ "account.usagePaused": "Usage is paused until your latest invoice is paid.",
33
37
  "account.endsOn": "Ends on",
38
+
39
+ "limits.loading": "Loading spending limits…",
40
+ "limits.error": "Could not load spending limits.",
41
+ "limits.spent": "Spent this billing period",
42
+ "limits.providerLimit": "Limit set by your provider",
43
+ "limits.about":
44
+ "Set the most you want to spend each billing period. Usage that would go over a limit is stopped until the next period or until you raise the limit.",
45
+ "limits.of": "{spent} of {limit}",
46
+ "limits.total": "In total",
47
+ "limits.model": "Model: {name}",
48
+ "limits.outcome": "Outcome: {name}",
49
+ "limits.totalField": "Limit in total (USD)",
50
+ "limits.none": "No limit",
51
+ "limits.item": "Limit on",
52
+ "limits.amount": "Amount (USD)",
53
+ "limits.add": "Add a limit",
54
+ "limits.remove": "Remove",
55
+ "limits.warnAt": "Warn me at these percentages of a limit (for example 50, 80)",
56
+ "limits.save": "Save limits",
57
+ "limits.saving": "Saving…",
58
+ "limits.saved": "Limits saved.",
59
+ "limits.clear": "Remove all limits",
60
+ "limits.badWarn": "Use up to 5 whole numbers from 1 to 99, lowest first.",
34
61
  "status.active": "active",
35
62
  "status.trialing": "trialing",
36
63
  "status.past_due": "past due",
@@ -76,6 +103,19 @@ const en = {
76
103
  "pricing.choosePlan": "Choose plan",
77
104
  "pricing.custom": "Custom",
78
105
  "pricing.perMonth": "/ month",
106
+ "pricing.dim.line": "{model}, {label}: {price}",
107
+ "pricing.dim.perThousand": "{price} per 1,000 {unit}",
108
+ "pricing.dim.fromPerThousand": "from {price} per 1,000 {unit}",
109
+ "pricing.dim.free": "free",
110
+ "pricing.dim.perTransaction": "{rates} per transaction",
111
+ "pricing.dim.upTo": "{rate} up to {amount}",
112
+ "pricing.dim.then": "then {rate}",
113
+ "pricing.dim.atLeast": "at least {amount}",
114
+ "pricing.dim.atMost": "at most {amount}",
115
+ "pricing.dim.freeFirst": "first {n} free",
116
+ "pricing.dim.noRateFirst": "no rate on the first {amount}",
117
+ "pricing.dim.package": "{price} per {size} {unit}",
118
+ "pricing.dim.eventPrice": "each {unit} at its own price",
79
119
  "pricing.billedAnnually": "billed annually",
80
120
  "pricing.weekly": "Weekly",
81
121
  "pricing.quarter": "Quarterly",
@@ -206,6 +246,7 @@ const es = {
206
246
  "portal.account": "Cuenta",
207
247
  "portal.plans": "Planes",
208
248
  "portal.credits": "Créditos",
249
+ "portal.limits": "Límites de gasto",
209
250
 
210
251
  "account.loading": "Cargando la cuenta…",
211
252
  "account.error": "No se pudo cargar la cuenta.",
@@ -214,7 +255,33 @@ const es = {
214
255
  "account.plan": "Plan",
215
256
  "account.status": "Estado",
216
257
  "account.periodEnds": "El período actual termina",
258
+ "account.usageSoFar": "Uso hasta ahora",
259
+ "account.nextInvoiceAt": "Próxima factura al llegar a",
260
+ "account.usagePaused": "El uso está pausado hasta que se pague tu última factura.",
217
261
  "account.endsOn": "Termina el",
262
+
263
+ "limits.loading": "Cargando los límites de gasto…",
264
+ "limits.error": "No se pudieron cargar los límites de gasto.",
265
+ "limits.spent": "Gastado en este período de facturación",
266
+ "limits.providerLimit": "Límite fijado por tu proveedor",
267
+ "limits.about":
268
+ "Fija lo máximo que quieres gastar en cada período de facturación. El uso que superaría un límite se detiene hasta el próximo período o hasta que subas el límite.",
269
+ "limits.of": "{spent} de {limit}",
270
+ "limits.total": "En total",
271
+ "limits.model": "Modelo: {name}",
272
+ "limits.outcome": "Resultado: {name}",
273
+ "limits.totalField": "Límite total (USD)",
274
+ "limits.none": "Sin límite",
275
+ "limits.item": "Límite para",
276
+ "limits.amount": "Importe (USD)",
277
+ "limits.add": "Añadir un límite",
278
+ "limits.remove": "Quitar",
279
+ "limits.warnAt": "Avísame al llegar a estos porcentajes de un límite (por ejemplo 50, 80)",
280
+ "limits.save": "Guardar límites",
281
+ "limits.saving": "Guardando…",
282
+ "limits.saved": "Límites guardados.",
283
+ "limits.clear": "Quitar todos los límites",
284
+ "limits.badWarn": "Usa hasta 5 números enteros del 1 al 99, de menor a mayor.",
218
285
  "status.active": "activa",
219
286
  "status.trialing": "en prueba",
220
287
  "status.past_due": "pago atrasado",
@@ -260,6 +327,19 @@ const es = {
260
327
  "pricing.choosePlan": "Elegir plan",
261
328
  "pricing.custom": "Personalizado",
262
329
  "pricing.perMonth": "/ mes",
330
+ "pricing.dim.line": "{model}, {label}: {price}",
331
+ "pricing.dim.perThousand": "{price} por cada 1.000 {unit}",
332
+ "pricing.dim.fromPerThousand": "desde {price} por cada 1.000 {unit}",
333
+ "pricing.dim.free": "gratis",
334
+ "pricing.dim.perTransaction": "{rates} por transacción",
335
+ "pricing.dim.upTo": "{rate} hasta {amount}",
336
+ "pricing.dim.then": "luego {rate}",
337
+ "pricing.dim.atLeast": "mínimo {amount}",
338
+ "pricing.dim.atMost": "máximo {amount}",
339
+ "pricing.dim.freeFirst": "los primeros {n} gratis",
340
+ "pricing.dim.noRateFirst": "sin tasa en los primeros {amount}",
341
+ "pricing.dim.package": "{price} por cada {size} {unit}",
342
+ "pricing.dim.eventPrice": "cada {unit} a su propio precio",
263
343
  "pricing.billedAnnually": "facturado anualmente",
264
344
  "pricing.weekly": "Semanal",
265
345
  "pricing.quarter": "Trimestral",
@@ -391,6 +471,7 @@ const fr = {
391
471
  "portal.account": "Compte",
392
472
  "portal.plans": "Forfaits",
393
473
  "portal.credits": "Crédits",
474
+ "portal.limits": "Limites de dépenses",
394
475
 
395
476
  "account.loading": "Chargement du compte…",
396
477
  "account.error": "Impossible de charger le compte.",
@@ -399,7 +480,33 @@ const fr = {
399
480
  "account.plan": "Forfait",
400
481
  "account.status": "Statut",
401
482
  "account.periodEnds": "Fin de la période en cours",
483
+ "account.usageSoFar": "Utilisation à ce jour",
484
+ "account.nextInvoiceAt": "Prochaine facture à",
485
+ "account.usagePaused": "L'utilisation est suspendue jusqu'au paiement de votre dernière facture.",
402
486
  "account.endsOn": "Se termine le",
487
+
488
+ "limits.loading": "Chargement des limites de dépenses…",
489
+ "limits.error": "Impossible de charger les limites de dépenses.",
490
+ "limits.spent": "Dépensé sur cette période de facturation",
491
+ "limits.providerLimit": "Limite fixée par votre fournisseur",
492
+ "limits.about":
493
+ "Fixez le maximum que vous voulez dépenser à chaque période de facturation. L'utilisation qui dépasserait une limite est arrêtée jusqu'à la période suivante ou jusqu'à ce que vous augmentiez la limite.",
494
+ "limits.of": "{spent} sur {limit}",
495
+ "limits.total": "Au total",
496
+ "limits.model": "Modèle : {name}",
497
+ "limits.outcome": "Résultat : {name}",
498
+ "limits.totalField": "Limite totale (USD)",
499
+ "limits.none": "Aucune limite",
500
+ "limits.item": "Limite sur",
501
+ "limits.amount": "Montant (USD)",
502
+ "limits.add": "Ajouter une limite",
503
+ "limits.remove": "Retirer",
504
+ "limits.warnAt": "Me prévenir à ces pourcentages d'une limite (par exemple 50, 80)",
505
+ "limits.save": "Enregistrer les limites",
506
+ "limits.saving": "Enregistrement…",
507
+ "limits.saved": "Limites enregistrées.",
508
+ "limits.clear": "Retirer toutes les limites",
509
+ "limits.badWarn": "Indiquez jusqu'à 5 nombres entiers de 1 à 99, du plus petit au plus grand.",
403
510
  "status.active": "actif",
404
511
  "status.trialing": "en essai",
405
512
  "status.past_due": "paiement en retard",
@@ -445,6 +552,19 @@ const fr = {
445
552
  "pricing.choosePlan": "Choisir ce forfait",
446
553
  "pricing.custom": "Sur mesure",
447
554
  "pricing.perMonth": "/ mois",
555
+ "pricing.dim.line": "{model}, {label} : {price}",
556
+ "pricing.dim.perThousand": "{price} les 1 000 {unit}",
557
+ "pricing.dim.fromPerThousand": "à partir de {price} les 1 000 {unit}",
558
+ "pricing.dim.free": "gratuit",
559
+ "pricing.dim.perTransaction": "{rates} par transaction",
560
+ "pricing.dim.upTo": "{rate} jusqu'à {amount}",
561
+ "pricing.dim.then": "puis {rate}",
562
+ "pricing.dim.atLeast": "au moins {amount}",
563
+ "pricing.dim.atMost": "au plus {amount}",
564
+ "pricing.dim.freeFirst": "les {n} premiers gratuits",
565
+ "pricing.dim.noRateFirst": "aucun taux sur les premiers {amount}",
566
+ "pricing.dim.package": "{price} les {size} {unit}",
567
+ "pricing.dim.eventPrice": "chaque {unit} à son propre prix",
448
568
  "pricing.billedAnnually": "facturé annuellement",
449
569
  "pricing.weekly": "Hebdomadaire",
450
570
  "pricing.quarter": "Trimestriel",
@@ -577,6 +697,7 @@ const de = {
577
697
  "portal.account": "Konto",
578
698
  "portal.plans": "Tarife",
579
699
  "portal.credits": "Guthaben",
700
+ "portal.limits": "Ausgabenlimits",
580
701
 
581
702
  "account.loading": "Konto wird geladen…",
582
703
  "account.error": "Das Konto konnte nicht geladen werden.",
@@ -585,7 +706,33 @@ const de = {
585
706
  "account.plan": "Tarif",
586
707
  "account.status": "Status",
587
708
  "account.periodEnds": "Aktueller Zeitraum endet",
709
+ "account.usageSoFar": "Nutzung bisher",
710
+ "account.nextInvoiceAt": "Nächste Rechnung bei",
711
+ "account.usagePaused": "Die Nutzung ist bis zur Zahlung Ihrer letzten Rechnung pausiert.",
588
712
  "account.endsOn": "Endet am",
713
+
714
+ "limits.loading": "Ausgabenlimits werden geladen…",
715
+ "limits.error": "Die Ausgabenlimits konnten nicht geladen werden.",
716
+ "limits.spent": "In diesem Abrechnungszeitraum ausgegeben",
717
+ "limits.providerLimit": "Von Ihrem Anbieter festgelegtes Limit",
718
+ "limits.about":
719
+ "Legen Sie fest, wie viel Sie pro Abrechnungszeitraum höchstens ausgeben möchten. Nutzung, die ein Limit überschreiten würde, wird bis zum nächsten Zeitraum gestoppt oder bis Sie das Limit erhöhen.",
720
+ "limits.of": "{spent} von {limit}",
721
+ "limits.total": "Insgesamt",
722
+ "limits.model": "Modell: {name}",
723
+ "limits.outcome": "Ergebnis: {name}",
724
+ "limits.totalField": "Gesamtlimit (USD)",
725
+ "limits.none": "Kein Limit",
726
+ "limits.item": "Limit für",
727
+ "limits.amount": "Betrag (USD)",
728
+ "limits.add": "Limit hinzufügen",
729
+ "limits.remove": "Entfernen",
730
+ "limits.warnAt": "Mich bei diesen Prozentsätzen eines Limits warnen (zum Beispiel 50, 80)",
731
+ "limits.save": "Limits speichern",
732
+ "limits.saving": "Wird gespeichert…",
733
+ "limits.saved": "Limits gespeichert.",
734
+ "limits.clear": "Alle Limits entfernen",
735
+ "limits.badWarn": "Verwenden Sie bis zu 5 ganze Zahlen von 1 bis 99, aufsteigend.",
589
736
  "status.active": "aktiv",
590
737
  "status.trialing": "Testphase",
591
738
  "status.past_due": "Zahlung überfällig",
@@ -632,6 +779,19 @@ const de = {
632
779
  "pricing.choosePlan": "Tarif wählen",
633
780
  "pricing.custom": "Individuell",
634
781
  "pricing.perMonth": "/ Monat",
782
+ "pricing.dim.line": "{model}, {label}: {price}",
783
+ "pricing.dim.perThousand": "{price} pro 1.000 {unit}",
784
+ "pricing.dim.fromPerThousand": "ab {price} pro 1.000 {unit}",
785
+ "pricing.dim.free": "kostenlos",
786
+ "pricing.dim.perTransaction": "{rates} pro Transaktion",
787
+ "pricing.dim.upTo": "{rate} bis {amount}",
788
+ "pricing.dim.then": "danach {rate}",
789
+ "pricing.dim.atLeast": "mindestens {amount}",
790
+ "pricing.dim.atMost": "höchstens {amount}",
791
+ "pricing.dim.freeFirst": "die ersten {n} kostenlos",
792
+ "pricing.dim.noRateFirst": "kein Satz auf die ersten {amount}",
793
+ "pricing.dim.package": "{price} pro {size} {unit}",
794
+ "pricing.dim.eventPrice": "pro {unit} zum jeweiligen Preis",
635
795
  "pricing.billedAnnually": "jährlich abgerechnet",
636
796
  "pricing.weekly": "Wöchentlich",
637
797
  "pricing.quarter": "Vierteljährlich",