@meterbox/react 0.1.1 → 0.1.2
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 +6 -0
- package/package.json +1 -1
- package/src/PricingTable.js +72 -0
package/README.md
CHANGED
|
@@ -62,6 +62,12 @@ whichever interval was selected, ready to hand straight to
|
|
|
62
62
|
`<CheckoutButton billingInterval>`. `PricingTable.annualPriceUsd(plan)` is
|
|
63
63
|
exposed as a static if you need the same total outside the grid.
|
|
64
64
|
|
|
65
|
+
Plans from the snapshot (or the customer portal's plan list) also carry
|
|
66
|
+
`usage`, and each card then shows what an AI product's customers actually
|
|
67
|
+
pay for usage: the amounts included each month, what happens past them
|
|
68
|
+
(billed, stopped until next month, or an upgrade), and every model's input
|
|
69
|
+
and output rates per 1M tokens, tier ladders included.
|
|
70
|
+
|
|
65
71
|
### `<PlanComparison from to onSwitch? />`
|
|
66
72
|
|
|
67
73
|
Side-by-side comparison of two plan records with added / removed feature
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meterbox/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
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
|
@@ -21,6 +21,11 @@
|
|
|
21
21
|
* total divided back into a misleading "$X/mo" figure — a shopper who
|
|
22
22
|
* commits annually is billed once for the year, not monthly.
|
|
23
23
|
*
|
|
24
|
+
* A plan with `usage` (the pricing snapshot and the customer portal's plan
|
|
25
|
+
* list carry it) also shows its included amounts, what happens past them,
|
|
26
|
+
* and its models' input and output rates per 1M tokens, tier ladders
|
|
27
|
+
* included.
|
|
28
|
+
*
|
|
24
29
|
* Pure presentational + inline styles — no CSS pipeline required from the
|
|
25
30
|
* tenant.
|
|
26
31
|
*/
|
|
@@ -94,6 +99,13 @@ const styles = {
|
|
|
94
99
|
cursor: "pointer",
|
|
95
100
|
},
|
|
96
101
|
ctaCurrent: { background: "#e5e7eb", color: "#111", cursor: "default" },
|
|
102
|
+
usage: {
|
|
103
|
+
display: "grid",
|
|
104
|
+
gap: 4,
|
|
105
|
+
fontSize: 12,
|
|
106
|
+
borderTop: "1px solid #e5e7eb",
|
|
107
|
+
paddingTop: 10,
|
|
108
|
+
},
|
|
97
109
|
badge: {
|
|
98
110
|
fontSize: 11,
|
|
99
111
|
fontWeight: 600,
|
|
@@ -118,6 +130,64 @@ function formatPrice(amount, currency = "USD") {
|
|
|
118
130
|
}
|
|
119
131
|
}
|
|
120
132
|
|
|
133
|
+
const PAST_INCLUDED = {
|
|
134
|
+
billed: "Past that, per 1M tokens:",
|
|
135
|
+
blocked: "Usage stops there until next month.",
|
|
136
|
+
upgrade: "Past that, your plan is upgraded automatically.",
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
function compact(n) {
|
|
140
|
+
return new Intl.NumberFormat("en", { notation: "compact" }).format(n);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function rate(perUnit) {
|
|
144
|
+
const v = Math.round(perUnit * 1e6) / 1e6;
|
|
145
|
+
return `$${v > 0 && v < 0.01 ? v.toPrecision(2) : v.toFixed(2)}`;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** "$3.00 to 10M then $2.50" — a tier ladder priced per 1,000 units × `scale`. */
|
|
149
|
+
function ladderText(tiers, scale) {
|
|
150
|
+
return tiers
|
|
151
|
+
.map((t) => rate(t.per_1k * scale) + (t.up_to == null ? "" : ` to ${compact(t.up_to)}`))
|
|
152
|
+
.join(" then ");
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** Included amounts, what happens past them, and the models' rates. */
|
|
156
|
+
function PlanUsage({ usage }) {
|
|
157
|
+
const { included, overage, models, api_call_overage_tiers: callTiers } = usage;
|
|
158
|
+
const parts = [
|
|
159
|
+
[included.input_tokens, "input tokens"],
|
|
160
|
+
[included.output_tokens, "output tokens"],
|
|
161
|
+
[included.api_calls, "API calls"],
|
|
162
|
+
]
|
|
163
|
+
.filter(([n]) => n > 0)
|
|
164
|
+
.map(([n, label]) => `${compact(n)} ${label}`);
|
|
165
|
+
const billed = overage === "billed";
|
|
166
|
+
return React.createElement(
|
|
167
|
+
"div",
|
|
168
|
+
{ className: "meterbox-plan-usage", style: styles.usage },
|
|
169
|
+
parts.length > 0 && React.createElement("div", null, `Includes ${parts.join(", ")} a month`),
|
|
170
|
+
React.createElement(
|
|
171
|
+
"div",
|
|
172
|
+
{ style: { opacity: 0.75 } },
|
|
173
|
+
billed && parts.length === 0 ? "Per 1M tokens:" : PAST_INCLUDED[overage],
|
|
174
|
+
),
|
|
175
|
+
billed
|
|
176
|
+
? models.map((m) =>
|
|
177
|
+
React.createElement(
|
|
178
|
+
"div",
|
|
179
|
+
{ key: m.id },
|
|
180
|
+
`${m.name}: ${ladderText(m.input_tiers, 1000)} in, ${ladderText(m.output_tiers, 1000)} out`,
|
|
181
|
+
),
|
|
182
|
+
)
|
|
183
|
+
: models.length > 0 &&
|
|
184
|
+
React.createElement("div", null, `Models: ${models.map((m) => m.name).join(", ")}`),
|
|
185
|
+
billed &&
|
|
186
|
+
callTiers &&
|
|
187
|
+
React.createElement("div", null, `API calls: ${ladderText(callTiers, 1)} per 1K`),
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
|
|
121
191
|
/** A plan from the public snapshot, in the shape the table renders. */
|
|
122
192
|
function fromSnapshot(p) {
|
|
123
193
|
return {
|
|
@@ -128,6 +198,7 @@ function fromSnapshot(p) {
|
|
|
128
198
|
stripe_price_monthly_usd: p.price ? p.price.monthly_usd : 0,
|
|
129
199
|
annual_free_months: p.annual_free_months == null ? null : p.annual_free_months,
|
|
130
200
|
localized_prices: p.localized_prices || [],
|
|
201
|
+
usage: p.usage || null,
|
|
131
202
|
};
|
|
132
203
|
}
|
|
133
204
|
|
|
@@ -257,6 +328,7 @@ function PricingTable({
|
|
|
257
328
|
React.createElement("li", { key: f }, `• ${f.replace(/_/g, " ")}`),
|
|
258
329
|
),
|
|
259
330
|
),
|
|
331
|
+
plan.usage && React.createElement(PlanUsage, { usage: plan.usage }),
|
|
260
332
|
React.createElement(
|
|
261
333
|
"button",
|
|
262
334
|
{
|