@meterbox/react 0.1.10 → 0.1.11

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
@@ -76,9 +76,9 @@ and output rates per 1M tokens, tier ladders included.
76
76
 
77
77
  A plan lists its included credits first ("1,500 Bits a month", in the tenant's credit unit), then
78
78
  its `bullet_details`, which `GET /v1/plans`, the pricing snapshot and the customer portal's plans
79
- all carry: the tenant's own pricing-page bullets, else each feature by its name with its
80
- description under it, by its description when it has no name, and by its id only when it has
81
- neither. Without them, it lists its `bullets`, its `display_features` or its feature ids. A
79
+ all carry: each feature by its name on the plan, else by its label with its description under it,
80
+ by its description when it has no label, and by its id only when it has neither. Without them, it
81
+ lists its `bullets`, else its `features` (`[{ id, name }]`) by name, else by id. A
82
82
  pricing-page plan with a public promotion shows its promotional price, the regular one struck
83
83
  through, and the code to use ("Save 50% with code LAUNCH50 for 3 months").
84
84
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meterbox/react",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
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",
@@ -45,6 +45,18 @@ const styles = {
45
45
  },
46
46
  };
47
47
 
48
+ // A plan's features by id, each as it reads: its name on the plan, else its
49
+ // id in words (`{ id, name }`; ids alone in older records).
50
+ function featuresOf(plan) {
51
+ const list = Array.isArray(plan.features) ? plan.features : [];
52
+ return new Map(
53
+ list.map((f) => {
54
+ const id = typeof f === "string" ? f : f.id;
55
+ return [id, (typeof f === "string" ? null : f.name) || id.replace(/_/g, " ")];
56
+ }),
57
+ );
58
+ }
59
+
48
60
  function PlanComparison({ from, to, onSwitch }) {
49
61
  if (!from || !to) {
50
62
  return React.createElement(
@@ -53,10 +65,11 @@ function PlanComparison({ from, to, onSwitch }) {
53
65
  "Pick a plan to compare.",
54
66
  );
55
67
  }
56
- const fromFeatures = new Set(Array.isArray(from.features) ? from.features : []);
57
- const toFeatures = new Set(Array.isArray(to.features) ? to.features : []);
58
- const added = [...toFeatures].filter((f) => !fromFeatures.has(f));
59
- const removed = [...fromFeatures].filter((f) => !toFeatures.has(f));
68
+ const fromFeatures = featuresOf(from);
69
+ const toFeatures = featuresOf(to);
70
+ const text = (id) => toFeatures.get(id) || fromFeatures.get(id);
71
+ const added = [...toFeatures.keys()].filter((f) => !fromFeatures.has(f));
72
+ const removed = [...fromFeatures.keys()].filter((f) => !toFeatures.has(f));
60
73
 
61
74
  function FeatureList(features, extras) {
62
75
  return React.createElement(
@@ -66,17 +79,13 @@ function PlanComparison({ from, to, onSwitch }) {
66
79
  React.createElement(
67
80
  "li",
68
81
  { key: f, style: extras?.removed?.has(f) ? styles.removed : null },
69
- `• ${f.replace(/_/g, " ")}`,
82
+ `• ${text(f)}`,
70
83
  ),
71
84
  ),
72
85
  added.length > 0 &&
73
86
  extras?.showAdded &&
74
87
  added.map((f) =>
75
- React.createElement(
76
- "li",
77
- { key: `added-${f}`, style: styles.added },
78
- `+ ${f.replace(/_/g, " ")}`,
79
- ),
88
+ React.createElement("li", { key: `added-${f}`, style: styles.added }, `+ ${text(f)}`),
80
89
  ),
81
90
  );
82
91
  }
@@ -89,7 +98,7 @@ function PlanComparison({ from, to, onSwitch }) {
89
98
  { style: styles.col },
90
99
  React.createElement("h4", { style: styles.heading }, "Current"),
91
100
  React.createElement("h3", { style: styles.planName }, from.name || from.id),
92
- FeatureList(Array.from(fromFeatures), { removed: new Set(removed) }),
101
+ FeatureList(Array.from(fromFeatures.keys()), { removed: new Set(removed) }),
93
102
  ),
94
103
  React.createElement(
95
104
  "div",
@@ -97,7 +106,7 @@ function PlanComparison({ from, to, onSwitch }) {
97
106
  React.createElement("h4", { style: styles.heading }, "Switching to"),
98
107
  React.createElement("h3", { style: styles.planName }, to.name || to.id),
99
108
  FeatureList(
100
- Array.from(toFeatures).filter((f) => !added.includes(f)),
109
+ Array.from(toFeatures.keys()).filter((f) => !added.includes(f)),
101
110
  { showAdded: true },
102
111
  ),
103
112
  onSwitch &&
@@ -36,11 +36,11 @@
36
36
  * {CUSTOMER_EMAIL} in it).
37
37
  *
38
38
  * A plan's list is its `bullet_details` (the API's plans, the snapshot and the
39
- * customer portal's plan list all carry it: the tenant's own bullets, else
40
- * each feature by its label with its description under it, by its
41
- * description when it has no label, by its id when it has neither), else
42
- * its `bullets`, else its `display_features`, else its feature ids; its
43
- * included credits come first ("1,500 Bits a month"). A snapshot plan's
39
+ * customer portal's plan list all carry it: each feature by its name on the
40
+ * plan, else its label with its description under it, by its description
41
+ * when it has no label, by its id when it has neither), else its `bullets`,
42
+ * else its features (`{ id, name }`) by name, else by id; its included
43
+ * credits come first ("1,500 Bits a month"). A snapshot plan's
44
44
  * `promotion` shows its monthly price with the regular one struck through,
45
45
  * and how to get it ("Save 50% with code LAUNCH50 for 3 months").
46
46
  *
@@ -156,13 +156,13 @@ const styles = {
156
156
 
157
157
  /**
158
158
  * What a plan lists, as `{ text, description }`: its `bullet_details`, else
159
- * its bullets, else its own display text, else its feature ids.
159
+ * its bullets, else its features by name, else by id.
160
160
  */
161
161
  function planBullets(plan) {
162
162
  if (Array.isArray(plan.bullet_details)) return plan.bullet_details;
163
- let texts = plan.features || [];
164
- if (Array.isArray(plan.bullets)) texts = plan.bullets;
165
- else if (plan.display_features?.length) texts = plan.display_features;
163
+ const texts = Array.isArray(plan.bullets)
164
+ ? plan.bullets
165
+ : (plan.features || []).map((f) => (typeof f === "string" ? f : f.name || f.id));
166
166
  return texts.map((text) => ({ text, description: null }));
167
167
  }
168
168
 
@@ -260,7 +260,8 @@ function PlanUsage({ usage }) {
260
260
  }
261
261
 
262
262
  // A plan's call-to-action link, {CUSTOMER_EMAIL} filled in; null unless it's
263
- // an http(s), mailto: or tel: link, or a path on this site.
263
+ // an http(s), mailto: or tel: link, or a path on this site (not one a
264
+ // browser reads as another host: "//", "/\\").
264
265
  function ctaLink(plan, customerEmail) {
265
266
  if (!plan.cta?.url) return null;
266
267
  const email = encodeURIComponent(customerEmail || "");
@@ -269,7 +270,7 @@ function ctaLink(plan, customerEmail) {
269
270
  .join(email)
270
271
  .split("%7BCUSTOMER_EMAIL%7D")
271
272
  .join(email);
272
- return /^(https?:|mailto:|tel:|\/(?!\/))/i.test(url) ? { url, label: plan.cta.label } : null;
273
+ return /^(https?:|mailto:|tel:|\/(?![/\\]))/i.test(url) ? { url, label: plan.cta.label } : null;
273
274
  }
274
275
 
275
276
  /** A plan from the public snapshot, in the shape the table renders. */
@@ -283,7 +284,7 @@ function fromSnapshot(p) {
283
284
  bullet_details: p.bullet_details || null,
284
285
  included_credits: p.included_credits || null,
285
286
  promotion: p.promotion || null,
286
- stripe_price_monthly_usd: p.price ? p.price.monthly_usd : 0,
287
+ stripe_price_monthly_usd: p.price ? p.price.monthly_usd : null,
287
288
  annual_free_months: p.annual_free_months == null ? null : p.annual_free_months,
288
289
  localized_prices: p.localized_prices || [],
289
290
  usage: p.usage || null,
@@ -148,7 +148,9 @@ function SubscriptionPreview({
148
148
  // admin endpoint). Field names match the backend exactly.
149
149
  const current = data.current || null;
150
150
  const target = data.target || null;
151
- const newMrr = data.new_mrr_usd ?? data.proration?.new_plan_prorated_usd ?? null;
151
+ // Null new_mrr_usd: the plan has no fixed price, so the new MRR isn't known.
152
+ const newMrr =
153
+ "new_mrr_usd" in data ? data.new_mrr_usd : (data.proration?.new_plan_prorated_usd ?? null);
152
154
  const prevMrr = current ? current.price_monthly_usd : null;
153
155
  const mrrDelta = newMrr != null && prevMrr != null ? newMrr - prevMrr : null;
154
156
  const amountDue = data.amount_due_usd ?? null;
@@ -96,8 +96,11 @@ function UsageProgress({
96
96
  if (!data) return null;
97
97
 
98
98
  const used = data.usage?.[metric] ?? 0;
99
- const cap = data.plan?.limits?.[metric] ?? 0;
100
- const fraction = cap > 0 ? Math.min(1, used / cap) : 0;
99
+ // No limit (null): no bar to fill. None included (0): any use fills it.
100
+ const cap = data.plan?.limits?.[metric] ?? null;
101
+ let fraction = 0;
102
+ if (cap > 0) fraction = Math.min(1, used / cap);
103
+ else if (cap === 0 && used > 0) fraction = 1;
101
104
  const fillStyle = { ...styles.fill, width: `${fraction * 100}%` };
102
105
  if (fraction >= dangerAt) Object.assign(fillStyle, styles.danger);
103
106
  else if (fraction >= warnAt) Object.assign(fillStyle, styles.warn);
@@ -112,7 +115,7 @@ function UsageProgress({
112
115
  React.createElement(
113
116
  "span",
114
117
  { style: styles.value },
115
- `${used.toLocaleString()}${cap > 0 ? ` / ${cap.toLocaleString()}` : ""}`,
118
+ `${used.toLocaleString()}${cap != null ? ` / ${cap.toLocaleString()}` : ""}`,
116
119
  ),
117
120
  ),
118
121
  React.createElement(
package/src/i18n.js CHANGED
@@ -42,6 +42,7 @@ const en = {
42
42
  "plans.error": "Could not load plans.",
43
43
  "plans.annualNote":
44
44
  "Cost preview isn't available for annual billing yet — the amount due will be confirmed at checkout.",
45
+ "plans.noFixedPrice": "{plan} has no fixed price. Get in touch to move to it.",
45
46
 
46
47
  "cancel.button": "Cancel subscription",
47
48
  "cancel.why": "Why are you cancelling?",
@@ -193,6 +194,7 @@ const es = {
193
194
  "plans.error": "No se pudieron cargar los planes.",
194
195
  "plans.annualNote":
195
196
  "La vista previa del costo aún no está disponible para la facturación anual. El importe se confirma al pagar.",
197
+ "plans.noFixedPrice": "{plan} no tiene un precio fijo. Contáctanos para cambiarte a este plan.",
196
198
 
197
199
  "cancel.button": "Cancelar suscripción",
198
200
  "cancel.why": "¿Por qué cancelas?",
@@ -344,6 +346,7 @@ const fr = {
344
346
  "plans.error": "Impossible de charger les forfaits.",
345
347
  "plans.annualNote":
346
348
  "L'aperçu du coût n'est pas encore disponible pour la facturation annuelle. Le montant dû est confirmé au paiement.",
349
+ "plans.noFixedPrice": "{plan} n'a pas de prix fixe. Contactez-nous pour passer à ce forfait.",
347
350
 
348
351
  "cancel.button": "Résilier l'abonnement",
349
352
  "cancel.why": "Pourquoi résiliez-vous ?",
@@ -495,6 +498,8 @@ const de = {
495
498
  "plans.error": "Die Tarife konnten nicht geladen werden.",
496
499
  "plans.annualNote":
497
500
  "Eine Kostenvorschau ist für die jährliche Abrechnung noch nicht verfügbar. Der fällige Betrag wird beim Bezahlen bestätigt.",
501
+ "plans.noFixedPrice":
502
+ "{plan} hat keinen Festpreis. Kontaktieren Sie uns, um zu diesem Tarif zu wechseln.",
498
503
 
499
504
  "cancel.button": "Abonnement kündigen",
500
505
  "cancel.why": "Warum möchten Sie kündigen?",