@meterbox/react 0.1.3 → 0.1.4

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
@@ -45,7 +45,7 @@ import {
45
45
  } from "@meterbox/react";
46
46
  ```
47
47
 
48
- ### `<PricingTable plans currentPlanId? currency? onSelect? />` or `<PricingTable baseUrl publishableKey … />`
48
+ ### `<PricingTable plans currentPlanId? currency? onSelect? customerEmail? />` or `<PricingTable baseUrl publishableKey … />`
49
49
 
50
50
  On a public page with no backend of its own, pass `baseUrl` and a
51
51
  publishable key (`mb_pub_...`, from Settings > API keys) instead of `plans`.
@@ -63,6 +63,11 @@ whichever interval was selected, ready to hand straight to
63
63
  `<CheckoutButton billingInterval>`. `PricingTable.annualPriceUsd(plan)` is
64
64
  exposed as a static if you need the same total outside the grid.
65
65
 
66
+ From the snapshot, the featured plan is highlighted with its badge ("Most
67
+ popular"), a plan's free trial shows as "14-day free trial", and, without
68
+ `onSelect`, each plan's button is its own call-to-action link (e.g. Enterprise
69
+ to a contact page); `customerEmail` fills `{CUSTOMER_EMAIL}` in it.
70
+
66
71
  Plans from the snapshot (or the customer portal's plan list) also carry
67
72
  `usage`, and each card then shows what an AI product's customers actually
68
73
  pay for usage: the amounts included each month, what happens past them
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meterbox/react",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
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",
@@ -26,6 +26,11 @@
26
26
  * and its models' input and output rates per 1M tokens, tier ladders
27
27
  * included.
28
28
  *
29
+ * From the snapshot, the featured plan is highlighted with its `badge`, a
30
+ * plan's `trial_days` shows as "14-day free trial", and without `onSelect`
31
+ * each plan's button is its call-to-action link (`customerEmail` fills
32
+ * {CUSTOMER_EMAIL} in it).
33
+ *
29
34
  * Pure presentational + inline styles — no CSS pipeline required from the
30
35
  * tenant.
31
36
  */
@@ -99,6 +104,7 @@ const styles = {
99
104
  cursor: "pointer",
100
105
  },
101
106
  ctaCurrent: { background: "#e5e7eb", color: "#111", cursor: "default" },
107
+ trial: { fontSize: 13, fontWeight: 600 },
102
108
  usage: {
103
109
  display: "grid",
104
110
  gap: 4,
@@ -188,6 +194,19 @@ function PlanUsage({ usage }) {
188
194
  );
189
195
  }
190
196
 
197
+ // A plan's call-to-action link from the snapshot, {CUSTOMER_EMAIL} filled in;
198
+ // null unless it's an http(s), mailto: or tel: link.
199
+ function ctaLink(plan, customerEmail) {
200
+ if (!plan.cta?.url) return null;
201
+ const email = encodeURIComponent(customerEmail || "");
202
+ const url = plan.cta.url
203
+ .split("{CUSTOMER_EMAIL}")
204
+ .join(email)
205
+ .split("%7BCUSTOMER_EMAIL%7D")
206
+ .join(email);
207
+ return /^(https?:|mailto:|tel:)/i.test(url) ? { url, label: plan.cta.label } : null;
208
+ }
209
+
191
210
  /** A plan from the public snapshot, in the shape the table renders. */
192
211
  function fromSnapshot(p) {
193
212
  return {
@@ -199,6 +218,10 @@ function fromSnapshot(p) {
199
218
  annual_free_months: p.annual_free_months == null ? null : p.annual_free_months,
200
219
  localized_prices: p.localized_prices || [],
201
220
  usage: p.usage || null,
221
+ highlight: !!p.highlight,
222
+ badge: p.badge || null,
223
+ trial_days: p.trial_days || null,
224
+ cta: p.cta || null,
202
225
  };
203
226
  }
204
227
 
@@ -217,6 +240,7 @@ function PricingTable({
217
240
  currentPlanId,
218
241
  currency = "USD",
219
242
  onSelect,
243
+ customerEmail,
220
244
  baseUrl,
221
245
  publishableKey,
222
246
  fetch: fetchImpl,
@@ -289,13 +313,18 @@ function PricingTable({
289
313
  // annual_free_months always shows its monthly price, even while the
290
314
  // toggle above is set to "Annual" for its siblings.
291
315
  const annual = billingInterval === "annual" ? annualPriceUsd(plan) : null;
316
+ const link = !onSelect && !isCurrent ? ctaLink(plan, customerEmail) : null;
292
317
  return React.createElement(
293
318
  "div",
294
319
  {
295
320
  key: plan.id,
296
- style: isCurrent ? { ...styles.card, ...styles.cardCurrent } : styles.card,
321
+ style:
322
+ isCurrent || plan.highlight ? { ...styles.card, ...styles.cardCurrent } : styles.card,
297
323
  },
298
324
  isCurrent && React.createElement("span", { style: styles.badge }, "Current"),
325
+ !isCurrent &&
326
+ plan.badge &&
327
+ React.createElement("span", { style: styles.badge }, plan.badge),
299
328
  React.createElement("h3", { style: styles.name }, plan.name || plan.id),
300
329
  plan.description &&
301
330
  React.createElement(
@@ -319,6 +348,12 @@ function PricingTable({
319
348
  annual != null ? "billed annually" : "/ month",
320
349
  ),
321
350
  ),
351
+ plan.trial_days > 0 &&
352
+ React.createElement(
353
+ "div",
354
+ { style: styles.trial },
355
+ `${plan.trial_days}-day free trial`,
356
+ ),
322
357
  Array.isArray(plan.features) &&
323
358
  plan.features.length > 0 &&
324
359
  React.createElement(
@@ -329,19 +364,28 @@ function PricingTable({
329
364
  ),
330
365
  ),
331
366
  plan.usage && React.createElement(PlanUsage, { usage: plan.usage }),
332
- React.createElement(
333
- "button",
334
- {
335
- type: "button",
336
- style: isCurrent ? { ...styles.cta, ...styles.ctaCurrent } : styles.cta,
337
- disabled: isCurrent,
338
- onClick: () => (onSelect ? onSelect(plan, billingInterval) : undefined),
339
- "aria-label": isCurrent
340
- ? `Currently on ${plan.name || plan.id}`
341
- : `Choose ${plan.name || plan.id}`,
342
- },
343
- isCurrent ? "Current plan" : "Choose plan",
344
- ),
367
+ link
368
+ ? React.createElement(
369
+ "a",
370
+ {
371
+ href: link.url,
372
+ style: { ...styles.cta, textAlign: "center", textDecoration: "none" },
373
+ },
374
+ link.label,
375
+ )
376
+ : React.createElement(
377
+ "button",
378
+ {
379
+ type: "button",
380
+ style: isCurrent ? { ...styles.cta, ...styles.ctaCurrent } : styles.cta,
381
+ disabled: isCurrent,
382
+ onClick: () => (onSelect ? onSelect(plan, billingInterval) : undefined),
383
+ "aria-label": isCurrent
384
+ ? `Currently on ${plan.name || plan.id}`
385
+ : `Choose ${plan.name || plan.id}`,
386
+ },
387
+ isCurrent ? "Current plan" : "Choose plan",
388
+ ),
345
389
  );
346
390
  }),
347
391
  ),