@meterbox/react 0.1.19 → 0.1.21

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/README.md CHANGED
@@ -80,7 +80,7 @@ what happens past them (billed, stopped until next month, or an upgrade), and
80
80
  every model's input and output rates per 1M tokens, tier ladders included.
81
81
 
82
82
  A plan lists its included credits first ("1,500 Bits a month", in the tenant's credit unit), then
83
- its `bullet_details`, which `GET /v1/plans`, the pricing snapshot and the customer portal's plans
83
+ its `bullet_details`, which `GET /v1/plans`, the pricing snapshot, and the customer portal's plans
84
84
  all carry: each feature by its name on the plan, else by its label with its description behind an
85
85
  info icon, by its description when it has no label, and by its id only when it has neither. Without them, it
86
86
  lists its `bullets`, else its `features` (`[{ id, name }]`) by name, else by id. A
@@ -106,10 +106,10 @@ resolved URL for your own calls.
106
106
  ### Branding: `<BrandingProvider branding>`
107
107
 
108
108
  Every component styles itself from `--mbx-*` CSS variables (`--mbx-accent`,
109
- `--mbx-text`, `--mbx-card`, `--mbx-border`, `--mbx-font`, `--mbx-radius` and the
109
+ `--mbx-text`, `--mbx-card`, `--mbx-border`, `--mbx-font`, `--mbx-radius`, and the
110
110
  button variables), with Meterbox's defaults as fallbacks. Wrap them in
111
111
  `<BrandingProvider branding={branding}>` to apply your branding from
112
- Settings → Branding (`GET /v1/settings/branding`): logo, colors, font and
112
+ Settings → Branding (`GET /v1/settings/branding`): logo, colors, font, and
113
113
  button style. `<PricingTable publishableKey>` applies it from the
114
114
  pricing snapshot by itself, and any component's surroundings can set the
115
115
  variables in CSS. `useBranding()` reads the values (e.g. the logo), and
@@ -120,14 +120,14 @@ match.
120
120
 
121
121
  Wrap the components in `<LocaleProvider locale="fr">` to show them in your
122
122
  customer's language (the ones the customer portal uses: the pricing table,
123
- plan change and preview, credits, invoices and billing details): English (the default), Spanish (`es`), French (`fr`) and
123
+ plan change and preview, credits, invoices, and billing details): English (the default), Spanish (`es`), French (`fr`), and
124
124
  German (`de`) are built in, picked by the locale's language (`fr-CA` uses
125
125
  French). Dates and amounts are formatted for the locale. `messages` overrides
126
126
  any string by its key (`{ "cancel.button": "End my plan" }`), or translates
127
127
  them all for another language; anything it leaves out stays in English. The
128
128
  keys and English text are in [`src/i18n.js`](./src/i18n.js). Plan names,
129
- features and offers are shown as you entered them. `useI18n()` gives your own
130
- elements the same `t(key, vars)`, `date(iso)` and `money(amount, currency)`.
129
+ features, and offers are shown as you entered them. `useI18n()` gives your own
130
+ elements the same `t(key, vars)`, `date(iso)`, and `money(amount, currency)`.
131
131
 
132
132
  ### `<BillingDetailsButton customerId customerToken returnUrl? label? onSession? onError? />`
133
133
 
@@ -135,7 +135,7 @@ Sends the customer to Stripe's own Billing Portal to update their payment
135
135
  method and billing details (address, tax IDs, email, name, phone) and see
136
136
  their invoices, so payment details never pass through your app or Meterbox.
137
137
  POSTs to `/v1/customer-portal/:id/billing-details` and redirects; Stripe
138
- sends them back to `returnUrl` (default: the current page). Cancelling and
138
+ sends them back to `returnUrl` (default: the current page). Canceling and
139
139
  plan changes aren't offered there: they stay in Meterbox's own flows. It
140
140
  works once the customer has a Stripe account and the tenant has enabled
141
141
  `checkout_via_meterbox`, which `GET /v1/customer-portal/:id/me` reports as
@@ -167,7 +167,7 @@ gets each body it fetches itself.
167
167
  ### `<PlanChangeCard preview? scheduledChange? allowSchedule? | customerId customerToken planId planVersion? fetch? onConfirm? onCancelScheduled? onChanged? />`
168
168
 
169
169
  Composes `<SubscriptionPreview>` with the actions it doesn't have: actually
170
- applying or scheduling the change, and cancelling a pending scheduled one.
170
+ applying or scheduling the change, and canceling a pending scheduled one.
171
171
  Change now and Schedule each ask first (which plan, when, and what's billed
172
172
  for it and when, as the preview says) and act only on "Yes, change it".
173
173
  Two modes:
@@ -214,9 +214,9 @@ Inline SVG line + area chart of credit balance over time, fed by
214
214
 
215
215
  ### `<InvoiceHistory invoices? | customerId customerToken />`
216
216
 
217
- The invoices the customer received, newest first: date, number, status and
217
+ The invoices the customer received, newest first: date, number, status, and
218
218
  amount, with a link to download each Stripe invoice's PDF and to its hosted
219
- page (labelled "Pay" while it's due). Self-fetches
219
+ page (labeled "Pay" while it's due). Self-fetches
220
220
  `GET /v1/customer-portal/:id/invoices` with the customer token.
221
221
 
222
222
  ### `<UsageChart series valueKey? height? label? />`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meterbox/react",
3
- "version": "0.1.19",
3
+ "version": "0.1.21",
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",
@@ -21,7 +21,7 @@
21
21
  "access": "public"
22
22
  },
23
23
  "dependencies": {
24
- "@meterbox/node": "0.1.5"
24
+ "@meterbox/node": "0.1.6"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "react": ">=17",
@@ -196,11 +196,15 @@ function CreditGrantsTable({
196
196
  React.createElement(
197
197
  "td",
198
198
  { style: styles.td },
199
- g.reason || g.source || g.type || "—",
199
+ g.reason || g.source || g.type || t("credits.unnamed"),
200
200
  ),
201
201
  React.createElement("td", { style: styles.td }, money(g.amount_usd)),
202
202
  React.createElement("td", { style: styles.td }, money(remaining(g))),
203
- React.createElement("td", { style: styles.td }, date(g.expires_at)),
203
+ React.createElement(
204
+ "td",
205
+ { style: styles.td },
206
+ g.expires_at ? date(g.expires_at) : t("credits.neverExpires"),
207
+ ),
204
208
  React.createElement(
205
209
  "td",
206
210
  { style: styles.td },
@@ -65,12 +65,12 @@ const STATUS_STYLE = {
65
65
  };
66
66
 
67
67
  function dollars(n) {
68
- if (n == null) return "—";
68
+ if (n == null) return "Not available";
69
69
  return `$${Number(n).toLocaleString(undefined, { maximumFractionDigits: 2 })}`;
70
70
  }
71
71
 
72
72
  function fmtDate(iso) {
73
- if (!iso) return "—";
73
+ if (!iso) return "Unknown";
74
74
  const d = new Date(iso);
75
75
  if (Number.isNaN(d.getTime())) return iso;
76
76
  return d.toISOString().slice(0, 10);
package/src/UsageChart.js CHANGED
@@ -38,7 +38,7 @@ const VALUE_LABELS = {
38
38
  };
39
39
 
40
40
  function formatValue(valueKey, n) {
41
- if (n == null) return "—";
41
+ if (n == null) return "No data";
42
42
  if (valueKey === "amount_usd") {
43
43
  return `$${Number(n).toLocaleString(undefined, { maximumFractionDigits: 2 })}`;
44
44
  }
package/src/i18n.js CHANGED
@@ -35,8 +35,8 @@ const en = {
35
35
  "status.trialing": "trialing",
36
36
  "status.past_due": "past due",
37
37
  "status.incomplete": "incomplete",
38
- "status.cancelling": "cancelling",
39
- "status.cancelled": "cancelled",
38
+ "status.cancelling": "canceling",
39
+ "status.cancelled": "canceled",
40
40
 
41
41
  "plans.loading": "Loading plans…",
42
42
  "plans.error": "Could not load plans.",
@@ -45,8 +45,8 @@ const en = {
45
45
  "plans.noFixedPrice": "{plan} has no fixed price. Get in touch to move to it.",
46
46
 
47
47
  "cancel.button": "Cancel subscription",
48
- "cancel.why": "Why are you cancelling?",
49
- "cancel.reasonLabel": "Reason for cancelling",
48
+ "cancel.why": "Why are you canceling?",
49
+ "cancel.reasonLabel": "Reason for canceling",
50
50
  "cancel.reason.too_expensive": "It's too expensive",
51
51
  "cancel.reason.missing_features": "It's missing features I need",
52
52
  "cancel.reason.switched_to_competitor": "I'm switching to another product",
@@ -105,7 +105,7 @@ const en = {
105
105
  "planChange.changed": "Plan changed.",
106
106
  "planChange.changedTo": "Plan changed to {plan}.",
107
107
  "planChange.failed": "Plan change failed.",
108
- "planChange.scheduledCancelled": "Scheduled change cancelled.",
108
+ "planChange.scheduledCancelled": "Scheduled change canceled.",
109
109
  "planChange.cancelFailed": "Cancel failed.",
110
110
  "planChange.pending": "Scheduled change to {plan} on {date}.",
111
111
  "planChange.cancel": "Cancel",
@@ -157,6 +157,10 @@ const en = {
157
157
  "credits.amount": "Amount",
158
158
  "credits.remaining": "Remaining",
159
159
  "credits.expires": "Expires",
160
+ "credits.neverExpires": "Never",
161
+ "credits.unnamed": "Credit",
162
+ "value.none": "Not available",
163
+ "value.noDate": "No date",
160
164
  "credits.status": "Status",
161
165
  "credits.utilLoading": "Loading utilization…",
162
166
  "credits.utilError": "Could not load utilization.",
@@ -329,6 +333,10 @@ const es = {
329
333
  "credits.amount": "Importe",
330
334
  "credits.remaining": "Restante",
331
335
  "credits.expires": "Vence",
336
+ "credits.neverExpires": "Nunca",
337
+ "credits.unnamed": "Crédito",
338
+ "value.none": "No disponible",
339
+ "value.noDate": "Sin fecha",
332
340
  "credits.status": "Estado",
333
341
  "credits.utilLoading": "Cargando el uso…",
334
342
  "credits.utilError": "No se pudo cargar el uso.",
@@ -502,6 +510,10 @@ const fr = {
502
510
  "credits.amount": "Montant",
503
511
  "credits.remaining": "Restant",
504
512
  "credits.expires": "Expire",
513
+ "credits.neverExpires": "Jamais",
514
+ "credits.unnamed": "Crédit",
515
+ "value.none": "Non disponible",
516
+ "value.noDate": "Aucune date",
505
517
  "credits.status": "Statut",
506
518
  "credits.utilLoading": "Chargement de l'utilisation…",
507
519
  "credits.utilError": "Impossible de charger l'utilisation.",
@@ -674,6 +686,10 @@ const de = {
674
686
  "credits.amount": "Betrag",
675
687
  "credits.remaining": "Verbleibend",
676
688
  "credits.expires": "Läuft ab",
689
+ "credits.neverExpires": "Nie",
690
+ "credits.unnamed": "Guthaben",
691
+ "value.none": "Nicht verfügbar",
692
+ "value.noDate": "Kein Datum",
677
693
  "credits.status": "Status",
678
694
  "credits.utilLoading": "Nutzung wird geladen…",
679
695
  "credits.utilError": "Die Nutzung konnte nicht geladen werden.",
@@ -742,9 +758,9 @@ function createI18n(locale, messages) {
742
758
  }
743
759
 
744
760
  // `amount` in the currency's major unit, whole amounts without decimals;
745
- // "—" when there's none.
761
+ // "Not available" (translated) when there's none.
746
762
  function money(amount, currency = "USD", options = {}) {
747
- if (amount == null) return "—";
763
+ if (amount == null) return t("value.none");
748
764
  const n = Number(amount);
749
765
  const whole = n % 1 === 0 ? { minimumFractionDigits: 0, maximumFractionDigits: 0 } : {};
750
766
  try {
@@ -757,7 +773,7 @@ function createI18n(locale, messages) {
757
773
  // The calendar date of an ISO timestamp, as written in `locale` (UTC, so a
758
774
  // date never shifts a day with the viewer's time zone).
759
775
  function date(iso) {
760
- if (!iso) return "—";
776
+ if (!iso) return t("value.noDate");
761
777
  const d = new Date(iso);
762
778
  if (Number.isNaN(d.getTime())) return String(iso);
763
779
  return new Intl.DateTimeFormat(tag, { dateStyle: "medium", timeZone: "UTC" }).format(d);