@copilotz/billing 1.0.0-rc.53 → 1.0.0-rc.55
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/credits/actions/check.d.ts +8 -0
- package/credits/actions/check.js +31 -1
- package/credits/mod.d.ts +3 -1
- package/credits/mod.js +6 -2
- package/credits/views/web/plan.d.ts +5 -1
- package/credits/views/web/plan.js +8 -5
- package/credits/views/web/setup.d.ts +11 -0
- package/credits/views/web/setup.js +39 -0
- package/credits/web.d.ts +2 -1
- package/credits/web.js +15 -1
- package/package.json +2 -2
- package/stripe/actions/checkout.js +5 -2
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
export declare const checkAction: import("copilotz").ActionDef;
|
|
2
2
|
export declare const mayAction: import("copilotz").ActionDef;
|
|
3
3
|
export declare const spentAction: import("copilotz").ActionDef;
|
|
4
|
+
/**
|
|
5
|
+
* `billing.credits` `{}`: what credits the org's plan gives (the `planCredits`
|
|
6
|
+
* resource), for pages that say how far they go: its name and title, the
|
|
7
|
+
* amount (USD), once (a trial's) or each month, and whether that's per seat.
|
|
8
|
+
* A plan that gives none (Free, for a team) says 0, once. Null while limits
|
|
9
|
+
* are off.
|
|
10
|
+
*/
|
|
11
|
+
export declare const creditsAction: import("copilotz").ActionDef;
|
|
4
12
|
export declare const priceListAction: import("copilotz").ActionDef;
|
|
5
13
|
export declare const tierAction: import("copilotz").ActionDef;
|
package/credits/actions/check.js
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
*/
|
|
19
19
|
import { defineAction } from "copilotz";
|
|
20
20
|
import { settingsOf } from "../shared/settings.js";
|
|
21
|
-
import { planOf, refresh, rooms, verdictOf } from "../shared/standing.js";
|
|
21
|
+
import { planOf, refresh, rooms, termsFor, verdictOf } from "../shared/standing.js";
|
|
22
22
|
const OK = { ok: true };
|
|
23
23
|
export const checkAction = defineAction({
|
|
24
24
|
description: "Whether the org can spend now, and why not",
|
|
@@ -79,6 +79,36 @@ export const spentAction = defineAction({
|
|
|
79
79
|
});
|
|
80
80
|
},
|
|
81
81
|
});
|
|
82
|
+
/**
|
|
83
|
+
* `billing.credits` `{}`: what credits the org's plan gives (the `planCredits`
|
|
84
|
+
* resource), for pages that say how far they go: its name and title, the
|
|
85
|
+
* amount (USD), once (a trial's) or each month, and whether that's per seat.
|
|
86
|
+
* A plan that gives none (Free, for a team) says 0, once. Null while limits
|
|
87
|
+
* are off.
|
|
88
|
+
*/
|
|
89
|
+
export const creditsAction = defineAction({
|
|
90
|
+
description: "What credits the org's plan gives",
|
|
91
|
+
record: false,
|
|
92
|
+
input: { type: "object", additionalProperties: false },
|
|
93
|
+
run: async (ctx) => {
|
|
94
|
+
const set = settingsOf(ctx);
|
|
95
|
+
if (!set.enforce)
|
|
96
|
+
return null;
|
|
97
|
+
const plan = await planOf(ctx);
|
|
98
|
+
const name = plan?.name ?? set.start;
|
|
99
|
+
const terms = plan?.terms ?? termsFor(ctx, name);
|
|
100
|
+
if (!terms)
|
|
101
|
+
return null;
|
|
102
|
+
const credits = terms.credits ?? {};
|
|
103
|
+
const said = { plan: name, title: terms.title };
|
|
104
|
+
if (credits.perSeat) {
|
|
105
|
+
return { ...said, amount: credits.perSeat, every: "month", perSeat: true };
|
|
106
|
+
}
|
|
107
|
+
if (credits.monthly)
|
|
108
|
+
return { ...said, amount: credits.monthly, every: "month" };
|
|
109
|
+
return { ...said, amount: credits.once ?? 0, every: "once" };
|
|
110
|
+
},
|
|
111
|
+
});
|
|
82
112
|
export const priceListAction = defineAction({
|
|
83
113
|
description: "The price list the org's plan names",
|
|
84
114
|
record: false,
|
package/credits/mod.d.ts
CHANGED
|
@@ -20,7 +20,9 @@
|
|
|
20
20
|
* - **Who a plan is for** (`for`: personal or team orgs): an org of the other
|
|
21
21
|
* kind isn't offered it and can't be moved to it, by anyone. A plan can name
|
|
22
22
|
* the model tier its agents use while the org hasn't chosen one (`models`,
|
|
23
|
-
* read through `billing.tier`, the `planTier` resource)
|
|
23
|
+
* read through `billing.tier`, the `planTier` resource); what credits it
|
|
24
|
+
* gives, through `billing.credits` (`planCredits`), for pages that say how
|
|
25
|
+
* far they go.
|
|
24
26
|
*
|
|
25
27
|
* plugins: [models, usage, credits, …]
|
|
26
28
|
* resources: {
|
package/credits/mod.js
CHANGED
|
@@ -20,7 +20,9 @@
|
|
|
20
20
|
* - **Who a plan is for** (`for`: personal or team orgs): an org of the other
|
|
21
21
|
* kind isn't offered it and can't be moved to it, by anyone. A plan can name
|
|
22
22
|
* the model tier its agents use while the org hasn't chosen one (`models`,
|
|
23
|
-
* read through `billing.tier`, the `planTier` resource)
|
|
23
|
+
* read through `billing.tier`, the `planTier` resource); what credits it
|
|
24
|
+
* gives, through `billing.credits` (`planCredits`), for pages that say how
|
|
25
|
+
* far they go.
|
|
24
26
|
*
|
|
25
27
|
* plugins: [models, usage, credits, …]
|
|
26
28
|
* resources: {
|
|
@@ -30,7 +32,7 @@
|
|
|
30
32
|
* }
|
|
31
33
|
*/
|
|
32
34
|
import { definePlugin } from "copilotz";
|
|
33
|
-
import { checkAction, mayAction, priceListAction, spentAction, tierAction, } from "./actions/check.js";
|
|
35
|
+
import { checkAction, creditsAction, mayAction, priceListAction, spentAction, tierAction, } from "./actions/check.js";
|
|
34
36
|
import { applyAction, budgetAction, grantAction, payAction, planAction, redeemAction, setPlanAction, settleAction, waiveAction, } from "./actions/manage.js";
|
|
35
37
|
import { noticeAction, stateAction } from "./actions/state.js";
|
|
36
38
|
import { credit } from "./collections/credit.js";
|
|
@@ -48,6 +50,7 @@ export const credits = definePlugin({
|
|
|
48
50
|
"billing.spent": spentAction,
|
|
49
51
|
"billing.priceList": priceListAction,
|
|
50
52
|
"billing.tier": tierAction,
|
|
53
|
+
"billing.credits": creditsAction,
|
|
51
54
|
"billing.state": stateAction,
|
|
52
55
|
"billing.notice": noticeAction,
|
|
53
56
|
"billing.setPlan": setPlanAction,
|
|
@@ -67,6 +70,7 @@ export const credits = definePlugin({
|
|
|
67
70
|
spending: { check: "billing.check", may: "billing.may" },
|
|
68
71
|
// Which model tier the org's plan gives its agents, for the tiers plugin.
|
|
69
72
|
planTier: { action: "billing.tier" },
|
|
73
|
+
planCredits: { action: "billing.credits" },
|
|
70
74
|
},
|
|
71
75
|
});
|
|
72
76
|
export default credits;
|
|
@@ -21,8 +21,12 @@ export declare function PlanCard({ state, team, personal, call }: {
|
|
|
21
21
|
call: Call;
|
|
22
22
|
}): ReactNode;
|
|
23
23
|
/** The plans they can move to; none while a subscription runs (that's Manage billing's). */
|
|
24
|
-
export declare function PlanOffers({ state, personal, call }: {
|
|
24
|
+
export declare function PlanOffers({ state, personal, call, back, title }: {
|
|
25
25
|
state: BillingState;
|
|
26
26
|
personal?: boolean;
|
|
27
27
|
call: Call;
|
|
28
|
+
/** Where the payment page comes back to (a path); else Billing. */
|
|
29
|
+
back?: string;
|
|
30
|
+
/** The card's heading, in place of "Move to a plan". */
|
|
31
|
+
title?: string;
|
|
28
32
|
}): ReactNode;
|
|
@@ -50,7 +50,7 @@ function PlanCredits({ credits, renews }) {
|
|
|
50
50
|
return (_jsxs("div", { className: "billing-plan-credits", children: [_jsx("p", { className: "billing-plan-left", children: said.title }), _jsx("div", { className: "billing-meter", role: "meter", "aria-label": "This month's plan credits left", "aria-valuemin": 0, "aria-valuemax": credits.amount, "aria-valuenow": Math.round(credits.left * 100) / 100, children: _jsx("span", { style: { width: `${Math.round(share * 1000) / 10}%` } }) }), _jsx("p", { className: "billing-small", children: said.more })] }));
|
|
51
51
|
}
|
|
52
52
|
/** The plans they can move to; none while a subscription runs (that's Manage billing's). */
|
|
53
|
-
export function PlanOffers({ state, personal = false, call }) {
|
|
53
|
+
export function PlanOffers({ state, personal = false, call, back, title }) {
|
|
54
54
|
const plan = state.plan;
|
|
55
55
|
const offers = (state.pay?.plans ?? []).filter((offer) => offer.name !== plan?.name);
|
|
56
56
|
// A personal org isn't offered a team's plan: it's told where that is instead.
|
|
@@ -60,10 +60,10 @@ export function PlanOffers({ state, personal = false, call }) {
|
|
|
60
60
|
if ((!offers.length && !forTeams.length) || subscribed || plan?.fixedSeats !== undefined) {
|
|
61
61
|
return null;
|
|
62
62
|
}
|
|
63
|
-
return (_jsxs(Card, { as: "section", className: "billing-card", "aria-labelledby": "billing-offers", children: [_jsxs("header", { className: "billing-card-head", children: [_jsx("h3", { id: "billing-offers", children: offers.length ? "Move to a plan" : "Plans" }), offers.length
|
|
63
|
+
return (_jsxs(Card, { as: "section", className: "billing-card", "aria-labelledby": "billing-offers", children: [_jsxs("header", { className: "billing-card-head", children: [_jsx("h3", { id: "billing-offers", children: title ?? (offers.length ? "Move to a plan" : "Plans") }), offers.length
|
|
64
64
|
? _jsx("p", { className: "billing-small", children: "You'll confirm on a secure payment page before you pay." })
|
|
65
65
|
: null] }), offers.length
|
|
66
|
-
? (_jsx("ul", { className: "billing-offers", children: offers.map((offer) => (_jsx(OfferRow, { offer: offer, state: state, personal: personal, call: call }, offer.name))) }))
|
|
66
|
+
? (_jsx("ul", { className: "billing-offers", children: offers.map((offer) => (_jsx(OfferRow, { offer: offer, state: state, personal: personal, call: call, ...(back ? { back } : {}) }, offer.name))) }))
|
|
67
67
|
: null, forTeams.length ? _jsx(ForTeams, { offers: forTeams }) : null] }));
|
|
68
68
|
}
|
|
69
69
|
/** A team's plans, said to a personal org: what they are, and that a team org takes them. */
|
|
@@ -72,13 +72,16 @@ function ForTeams({ offers }) {
|
|
|
72
72
|
return (_jsxs("p", { className: "billing-small billing-for-teams", children: [_jsx(Icon, { name: "users", size: 14 }), _jsxs("span", { children: ["Working with others? ", names.join(" and "), " ", offers.length === 1 ? "is" : "are", " ", "for team orgs: make one from the org switcher, and choose it in that org's Billing."] })] }));
|
|
73
73
|
}
|
|
74
74
|
/** A plan they can move to: what it costs them, before they go. */
|
|
75
|
-
function OfferRow({ offer, state, personal, call }) {
|
|
75
|
+
function OfferRow({ offer, state, personal, call, back }) {
|
|
76
76
|
const { busy, error, run, release } = useAct();
|
|
77
77
|
useBackFromLeaving(release);
|
|
78
78
|
const price = priceFor(offer.seat, state.billedSeats ?? state.seats, personal);
|
|
79
79
|
const gets = includes(offer, state.seats, personal);
|
|
80
80
|
return (_jsxs("li", { className: "billing-offer", children: [_jsxs("div", { className: "billing-offer-text", children: [_jsx("b", { children: offer.title }), _jsx("span", { className: "billing-offer-total", children: price.total }), price.each ? _jsx("span", { children: price.each }) : null, gets.length ? _jsx("span", { children: gets.join(" · ") }) : null] }), _jsxs(Button, { className: "billing-go", loading: busy, onClick: () => void run(async () => {
|
|
81
|
-
const { url } = await call("billing.checkout", {
|
|
81
|
+
const { url } = await call("billing.checkout", {
|
|
82
|
+
plan: offer.name,
|
|
83
|
+
...(back ? { back } : {}),
|
|
84
|
+
});
|
|
82
85
|
leavingFor(url, state);
|
|
83
86
|
}, true), children: ["Move to ", offer.title] }), error ? _jsx(Notice, { tone: "destructive", role: "alert", children: error }) : null] }));
|
|
84
87
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Choosing a plan as a team org starts (kind `billing.setup`, a step of chat's
|
|
3
|
+
* `welcome` for owners and admins of team orgs): a team org comes with no
|
|
4
|
+
* credits, so its agents wait for a plan. Its plans, each with what it comes
|
|
5
|
+
* to for its seats and what it gives, and a payment page that comes back to
|
|
6
|
+
* the welcome (`/?welcome=1`). Already on one, it says so; where paying isn't
|
|
7
|
+
* set up, it says who adds credits.
|
|
8
|
+
*/
|
|
9
|
+
import { type ReactNode } from "react";
|
|
10
|
+
import type { ViewContext } from "copilotz";
|
|
11
|
+
export declare const billingSetupView: (_: unknown, ctx: ViewContext<ReactNode>) => ReactNode;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Choosing a plan as a team org starts (kind `billing.setup`, a step of chat's
|
|
4
|
+
* `welcome` for owners and admins of team orgs): a team org comes with no
|
|
5
|
+
* credits, so its agents wait for a plan. Its plans, each with what it comes
|
|
6
|
+
* to for its seats and what it gives, and a payment page that comes back to
|
|
7
|
+
* the welcome (`/?welcome=1`). Already on one, it says so; where paying isn't
|
|
8
|
+
* set up, it says who adds credits.
|
|
9
|
+
*/
|
|
10
|
+
import { useEffect, useState } from "react";
|
|
11
|
+
import { message, Notice, Skeleton } from "copilotz/web";
|
|
12
|
+
import { PlanOffers } from "./plan.js";
|
|
13
|
+
import { STYLE } from "./style.js";
|
|
14
|
+
export const billingSetupView = (_, ctx) => (_jsxs(_Fragment, { children: [_jsx("style", { href: "billing-web", precedence: "copilotz", children: STYLE }), _jsx(Setup, { call: ctx.call })] }));
|
|
15
|
+
function Setup({ call }) {
|
|
16
|
+
const [state, setState] = useState();
|
|
17
|
+
const [error, setError] = useState();
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
let live = true;
|
|
20
|
+
call("billing.state", {}).then((answer) => live && setState(answer), (e) => live && setError(message(e)));
|
|
21
|
+
return () => {
|
|
22
|
+
live = false;
|
|
23
|
+
};
|
|
24
|
+
}, []);
|
|
25
|
+
if (error)
|
|
26
|
+
return _jsx(Notice, { tone: "destructive", role: "alert", children: error });
|
|
27
|
+
if (!state)
|
|
28
|
+
return _jsx(Skeleton, { height: 160, radius: "lg" });
|
|
29
|
+
const plan = state.plan;
|
|
30
|
+
const subscribed = !!plan?.subscription && plan.status !== "canceled";
|
|
31
|
+
if (subscribed || (plan && plan.name !== "free" && (state.balance ?? 0) > 0)) {
|
|
32
|
+
return (_jsxs(Notice, { tone: "success", icon: "check", children: [_jsxs("b", { children: ["You're on ", plan?.terms?.title ?? "a plan", "."] }), " ", "Your agents can work: each seat's price comes back as credits every month."] }));
|
|
33
|
+
}
|
|
34
|
+
const offers = state.pay?.plans ?? [];
|
|
35
|
+
if (!offers.length) {
|
|
36
|
+
return (_jsx(Notice, { tone: "neutral", icon: "info", children: "Paying online isn't set up here yet. Credits can be added in Billing, under your org's settings." }));
|
|
37
|
+
}
|
|
38
|
+
return (_jsxs("div", { className: "billing-setup", children: [_jsx("p", { className: "billing-small", children: "A team org starts with no credits. On a plan, each seat's price comes back as credits every month, shared by everyone here, and you can change or cancel it any time." }), _jsx(PlanOffers, { state: state, call: call, back: "/?welcome=1", title: "Plans for teams" })] }));
|
|
39
|
+
}
|
package/credits/web.d.ts
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
* platform staff, setting all of that by hand. And a short note above where
|
|
6
6
|
* you type (chat's `composerNotes`), so people know before they send that the
|
|
7
7
|
* org is out, or running low. Add it beside the web shell, where the browser
|
|
8
|
-
* draws.
|
|
8
|
+
* draws. As a team org starts (chat's `welcome`), choosing its plan
|
|
9
|
+
* (`billing.setup`).
|
|
9
10
|
*/
|
|
10
11
|
import { type Plugin } from "copilotz";
|
|
11
12
|
export declare const creditsWeb: Plugin;
|
package/credits/web.js
CHANGED
|
@@ -5,17 +5,20 @@
|
|
|
5
5
|
* platform staff, setting all of that by hand. And a short note above where
|
|
6
6
|
* you type (chat's `composerNotes`), so people know before they send that the
|
|
7
7
|
* org is out, or running low. Add it beside the web shell, where the browser
|
|
8
|
-
* draws.
|
|
8
|
+
* draws. As a team org starts (chat's `welcome`), choosing its plan
|
|
9
|
+
* (`billing.setup`).
|
|
9
10
|
*/
|
|
10
11
|
import { definePlugin } from "copilotz";
|
|
11
12
|
import { composerNoteView } from "./views/web/composer.js";
|
|
12
13
|
import { orgBillingView } from "./views/web/org.js";
|
|
14
|
+
import { billingSetupView } from "./views/web/setup.js";
|
|
13
15
|
export const creditsWeb = definePlugin({
|
|
14
16
|
name: "credits-web",
|
|
15
17
|
requires: ["web-shell"],
|
|
16
18
|
views: {
|
|
17
19
|
"billing.org": orgBillingView,
|
|
18
20
|
"billing.composer": composerNoteView,
|
|
21
|
+
"billing.setup": billingSetupView,
|
|
19
22
|
},
|
|
20
23
|
resources: {
|
|
21
24
|
orgSettings: {
|
|
@@ -28,6 +31,17 @@ export const creditsWeb = definePlugin({
|
|
|
28
31
|
},
|
|
29
32
|
},
|
|
30
33
|
composerNotes: { billing: { view: "billing.composer" } },
|
|
34
|
+
// Chat's welcome, for who runs a team org: it comes with no credits, so a plan first.
|
|
35
|
+
welcome: {
|
|
36
|
+
plan: {
|
|
37
|
+
title: "Choose a plan",
|
|
38
|
+
description: "Your agents start working once the org has credits.",
|
|
39
|
+
view: "billing.setup",
|
|
40
|
+
order: 5,
|
|
41
|
+
roles: ["owner", "admin"],
|
|
42
|
+
orgs: ["team"],
|
|
43
|
+
},
|
|
44
|
+
},
|
|
31
45
|
},
|
|
32
46
|
});
|
|
33
47
|
export default creditsWeb;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@copilotz/billing",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.55",
|
|
4
4
|
"description": "What an org has to spend (credits, plans, budgets) and paying for it with Stripe, on Copilotz's usage ledger. A Copilotz plugin.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"copilotz",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"dependencies": {},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"@types/react": "^19.3.0",
|
|
55
|
-
"copilotz": "1.0.0-rc.
|
|
55
|
+
"copilotz": "1.0.0-rc.55",
|
|
56
56
|
"react": "^19.3.1"
|
|
57
57
|
},
|
|
58
58
|
"peerDependenciesMeta": {
|
|
@@ -46,6 +46,8 @@ export const checkoutAction = defineAction({
|
|
|
46
46
|
credits: { type: "number", exclusiveMinimum: 0 },
|
|
47
47
|
plan: { type: "string" },
|
|
48
48
|
country: { type: "string", minLength: 2, maxLength: 2 },
|
|
49
|
+
/** Where in the app the payment page comes back to (a path); else Billing. */
|
|
50
|
+
back: { type: "string", pattern: "^/[^/\\\\]", maxLength: 200 },
|
|
49
51
|
},
|
|
50
52
|
additionalProperties: false,
|
|
51
53
|
},
|
|
@@ -64,11 +66,12 @@ export const checkoutAction = defineAction({
|
|
|
64
66
|
if (!chosen)
|
|
65
67
|
throw failure("no_seller", "Paying isn't set up here yet.");
|
|
66
68
|
const [name, seller] = chosen;
|
|
67
|
-
const
|
|
69
|
+
const where = input.back ?? "/org?tab=billing";
|
|
70
|
+
const back = (paid) => `${set.url}${where}${where.includes("?") ? "&" : "?"}paid=${paid}`;
|
|
68
71
|
const common = {
|
|
69
72
|
...(plan.customer ? { customer: plan.customer } : {}),
|
|
70
73
|
client_reference_id: org,
|
|
71
|
-
cancel_url: `${set.url}
|
|
74
|
+
cancel_url: `${set.url}${where}`,
|
|
72
75
|
};
|
|
73
76
|
const call = (params) => stripeCall({ key: seller.key, fetch: ctx.fetch }, "POST", "/v1/checkout/sessions", {
|
|
74
77
|
...common,
|