@meterbox/react 0.1.24 → 0.1.25
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 +1 -1
- package/src/PricingTable.js +79 -6
- package/src/i18n.js +64 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meterbox/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.25",
|
|
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",
|
package/src/PricingTable.js
CHANGED
|
@@ -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
|
-
?
|
|
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
|
@@ -30,6 +30,9 @@ const en = {
|
|
|
30
30
|
"account.plan": "Plan",
|
|
31
31
|
"account.status": "Status",
|
|
32
32
|
"account.periodEnds": "Current period ends",
|
|
33
|
+
"account.usageSoFar": "Usage so far",
|
|
34
|
+
"account.nextInvoiceAt": "Next invoice at",
|
|
35
|
+
"account.usagePaused": "Usage is paused until your latest invoice is paid.",
|
|
33
36
|
"account.endsOn": "Ends on",
|
|
34
37
|
"status.active": "active",
|
|
35
38
|
"status.trialing": "trialing",
|
|
@@ -76,6 +79,19 @@ const en = {
|
|
|
76
79
|
"pricing.choosePlan": "Choose plan",
|
|
77
80
|
"pricing.custom": "Custom",
|
|
78
81
|
"pricing.perMonth": "/ month",
|
|
82
|
+
"pricing.dim.line": "{model}, {label}: {price}",
|
|
83
|
+
"pricing.dim.perThousand": "{price} per 1,000 {unit}",
|
|
84
|
+
"pricing.dim.fromPerThousand": "from {price} per 1,000 {unit}",
|
|
85
|
+
"pricing.dim.free": "free",
|
|
86
|
+
"pricing.dim.perTransaction": "{rates} per transaction",
|
|
87
|
+
"pricing.dim.upTo": "{rate} up to {amount}",
|
|
88
|
+
"pricing.dim.then": "then {rate}",
|
|
89
|
+
"pricing.dim.atLeast": "at least {amount}",
|
|
90
|
+
"pricing.dim.atMost": "at most {amount}",
|
|
91
|
+
"pricing.dim.freeFirst": "first {n} free",
|
|
92
|
+
"pricing.dim.noRateFirst": "no rate on the first {amount}",
|
|
93
|
+
"pricing.dim.package": "{price} per {size} {unit}",
|
|
94
|
+
"pricing.dim.eventPrice": "each {unit} at its own price",
|
|
79
95
|
"pricing.billedAnnually": "billed annually",
|
|
80
96
|
"pricing.weekly": "Weekly",
|
|
81
97
|
"pricing.quarter": "Quarterly",
|
|
@@ -214,6 +230,9 @@ const es = {
|
|
|
214
230
|
"account.plan": "Plan",
|
|
215
231
|
"account.status": "Estado",
|
|
216
232
|
"account.periodEnds": "El período actual termina",
|
|
233
|
+
"account.usageSoFar": "Uso hasta ahora",
|
|
234
|
+
"account.nextInvoiceAt": "Próxima factura al llegar a",
|
|
235
|
+
"account.usagePaused": "El uso está pausado hasta que se pague tu última factura.",
|
|
217
236
|
"account.endsOn": "Termina el",
|
|
218
237
|
"status.active": "activa",
|
|
219
238
|
"status.trialing": "en prueba",
|
|
@@ -260,6 +279,19 @@ const es = {
|
|
|
260
279
|
"pricing.choosePlan": "Elegir plan",
|
|
261
280
|
"pricing.custom": "Personalizado",
|
|
262
281
|
"pricing.perMonth": "/ mes",
|
|
282
|
+
"pricing.dim.line": "{model}, {label}: {price}",
|
|
283
|
+
"pricing.dim.perThousand": "{price} por cada 1.000 {unit}",
|
|
284
|
+
"pricing.dim.fromPerThousand": "desde {price} por cada 1.000 {unit}",
|
|
285
|
+
"pricing.dim.free": "gratis",
|
|
286
|
+
"pricing.dim.perTransaction": "{rates} por transacción",
|
|
287
|
+
"pricing.dim.upTo": "{rate} hasta {amount}",
|
|
288
|
+
"pricing.dim.then": "luego {rate}",
|
|
289
|
+
"pricing.dim.atLeast": "mínimo {amount}",
|
|
290
|
+
"pricing.dim.atMost": "máximo {amount}",
|
|
291
|
+
"pricing.dim.freeFirst": "los primeros {n} gratis",
|
|
292
|
+
"pricing.dim.noRateFirst": "sin tasa en los primeros {amount}",
|
|
293
|
+
"pricing.dim.package": "{price} por cada {size} {unit}",
|
|
294
|
+
"pricing.dim.eventPrice": "cada {unit} a su propio precio",
|
|
263
295
|
"pricing.billedAnnually": "facturado anualmente",
|
|
264
296
|
"pricing.weekly": "Semanal",
|
|
265
297
|
"pricing.quarter": "Trimestral",
|
|
@@ -399,6 +431,9 @@ const fr = {
|
|
|
399
431
|
"account.plan": "Forfait",
|
|
400
432
|
"account.status": "Statut",
|
|
401
433
|
"account.periodEnds": "Fin de la période en cours",
|
|
434
|
+
"account.usageSoFar": "Utilisation à ce jour",
|
|
435
|
+
"account.nextInvoiceAt": "Prochaine facture à",
|
|
436
|
+
"account.usagePaused": "L'utilisation est suspendue jusqu'au paiement de votre dernière facture.",
|
|
402
437
|
"account.endsOn": "Se termine le",
|
|
403
438
|
"status.active": "actif",
|
|
404
439
|
"status.trialing": "en essai",
|
|
@@ -445,6 +480,19 @@ const fr = {
|
|
|
445
480
|
"pricing.choosePlan": "Choisir ce forfait",
|
|
446
481
|
"pricing.custom": "Sur mesure",
|
|
447
482
|
"pricing.perMonth": "/ mois",
|
|
483
|
+
"pricing.dim.line": "{model}, {label} : {price}",
|
|
484
|
+
"pricing.dim.perThousand": "{price} les 1 000 {unit}",
|
|
485
|
+
"pricing.dim.fromPerThousand": "à partir de {price} les 1 000 {unit}",
|
|
486
|
+
"pricing.dim.free": "gratuit",
|
|
487
|
+
"pricing.dim.perTransaction": "{rates} par transaction",
|
|
488
|
+
"pricing.dim.upTo": "{rate} jusqu'à {amount}",
|
|
489
|
+
"pricing.dim.then": "puis {rate}",
|
|
490
|
+
"pricing.dim.atLeast": "au moins {amount}",
|
|
491
|
+
"pricing.dim.atMost": "au plus {amount}",
|
|
492
|
+
"pricing.dim.freeFirst": "les {n} premiers gratuits",
|
|
493
|
+
"pricing.dim.noRateFirst": "aucun taux sur les premiers {amount}",
|
|
494
|
+
"pricing.dim.package": "{price} les {size} {unit}",
|
|
495
|
+
"pricing.dim.eventPrice": "chaque {unit} à son propre prix",
|
|
448
496
|
"pricing.billedAnnually": "facturé annuellement",
|
|
449
497
|
"pricing.weekly": "Hebdomadaire",
|
|
450
498
|
"pricing.quarter": "Trimestriel",
|
|
@@ -585,6 +633,9 @@ const de = {
|
|
|
585
633
|
"account.plan": "Tarif",
|
|
586
634
|
"account.status": "Status",
|
|
587
635
|
"account.periodEnds": "Aktueller Zeitraum endet",
|
|
636
|
+
"account.usageSoFar": "Nutzung bisher",
|
|
637
|
+
"account.nextInvoiceAt": "Nächste Rechnung bei",
|
|
638
|
+
"account.usagePaused": "Die Nutzung ist bis zur Zahlung Ihrer letzten Rechnung pausiert.",
|
|
588
639
|
"account.endsOn": "Endet am",
|
|
589
640
|
"status.active": "aktiv",
|
|
590
641
|
"status.trialing": "Testphase",
|
|
@@ -632,6 +683,19 @@ const de = {
|
|
|
632
683
|
"pricing.choosePlan": "Tarif wählen",
|
|
633
684
|
"pricing.custom": "Individuell",
|
|
634
685
|
"pricing.perMonth": "/ Monat",
|
|
686
|
+
"pricing.dim.line": "{model}, {label}: {price}",
|
|
687
|
+
"pricing.dim.perThousand": "{price} pro 1.000 {unit}",
|
|
688
|
+
"pricing.dim.fromPerThousand": "ab {price} pro 1.000 {unit}",
|
|
689
|
+
"pricing.dim.free": "kostenlos",
|
|
690
|
+
"pricing.dim.perTransaction": "{rates} pro Transaktion",
|
|
691
|
+
"pricing.dim.upTo": "{rate} bis {amount}",
|
|
692
|
+
"pricing.dim.then": "danach {rate}",
|
|
693
|
+
"pricing.dim.atLeast": "mindestens {amount}",
|
|
694
|
+
"pricing.dim.atMost": "höchstens {amount}",
|
|
695
|
+
"pricing.dim.freeFirst": "die ersten {n} kostenlos",
|
|
696
|
+
"pricing.dim.noRateFirst": "kein Satz auf die ersten {amount}",
|
|
697
|
+
"pricing.dim.package": "{price} pro {size} {unit}",
|
|
698
|
+
"pricing.dim.eventPrice": "pro {unit} zum jeweiligen Preis",
|
|
635
699
|
"pricing.billedAnnually": "jährlich abgerechnet",
|
|
636
700
|
"pricing.weekly": "Wöchentlich",
|
|
637
701
|
"pricing.quarter": "Vierteljährlich",
|