@fonderie/react-billing 0.1.0 → 0.3.0
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 +24 -5
- package/dist/index.cjs +199 -107
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +30 -12
- package/dist/index.d.ts +30 -12
- package/dist/index.js +163 -71
- package/dist/index.js.map +1 -1
- package/package.json +10 -6
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
React hooks for Fonderie billing — `usePlans`, `usePlan`, `useSubscription`,
|
|
4
4
|
`useCheckout`, `useBillingPortal`, `useUsage`, and `useRecordUsage`. Thin
|
|
5
|
-
bindings over [`@fonderie/client`](https://github.com/
|
|
5
|
+
bindings over [`@fonderie/client`](https://github.com/fonderiejs/sdk/tree/main/packages/client):
|
|
6
6
|
loading/error state and the request itself, nothing else. Bring your own UI.
|
|
7
7
|
|
|
8
8
|
## Install
|
|
@@ -11,6 +11,25 @@ loading/error state and the request itself, nothing else. Bring your own UI.
|
|
|
11
11
|
npm install @fonderie/react-billing
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
+
## One client at the root (recommended)
|
|
15
|
+
|
|
16
|
+
Wrap your app in `FonderieProvider` from [`@fonderie/react`](../react) once and
|
|
17
|
+
every hook resolves the client from context — no client argument at call sites:
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
import { FonderieProvider } from "@fonderie/react";
|
|
21
|
+
|
|
22
|
+
<FonderieProvider client={client}>
|
|
23
|
+
<App />
|
|
24
|
+
</FonderieProvider>;
|
|
25
|
+
|
|
26
|
+
// anywhere below it:
|
|
27
|
+
const { ...state } = usePlans();
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Passing a client explicitly (as below) still works everywhere and takes
|
|
31
|
+
precedence over context — handy in tests and multi-client apps.
|
|
32
|
+
|
|
14
33
|
## Use
|
|
15
34
|
|
|
16
35
|
```tsx
|
|
@@ -47,19 +66,19 @@ Each hook takes the same `BillingClient` instance (`client.billing`) —
|
|
|
47
66
|
construct one `FonderieClient` at the app root and pass it down (React
|
|
48
67
|
context or a prop). The client's access token is shared with `client.auth`
|
|
49
68
|
automatically, so signing in via
|
|
50
|
-
[`@fonderie/react-auth`](https://github.com/
|
|
69
|
+
[`@fonderie/react-auth`](https://github.com/fonderiejs/sdk/tree/main/packages/react-auth)
|
|
51
70
|
is enough to authenticate billing requests too. Billing by workspace instead
|
|
52
71
|
of by user? Call `client.billing.setWorkspaceId(id)`.
|
|
53
72
|
|
|
54
73
|
Want pre-built screens instead of wiring your own pricing table?
|
|
55
|
-
See [`@fonderie/react-billing-screens`](https://github.com/
|
|
74
|
+
See [`@fonderie/react-billing-screens`](https://github.com/fonderiejs/sdk/tree/main/packages/react-billing-screens).
|
|
56
75
|
|
|
57
76
|
## Why this exists
|
|
58
77
|
|
|
59
78
|
You've shipped this plumbing before — auth, teams, billing, messaging —
|
|
60
79
|
and the next project will ask for it again. Fonderie packages it once:
|
|
61
80
|
plain TypeScript modules for
|
|
62
|
-
[`@fonderie/core`](https://github.com/
|
|
81
|
+
[`@fonderie/core`](https://github.com/fonderiejs/sdk/tree/main/packages/core),
|
|
63
82
|
PostgreSQL-backed, self-hosted, MIT. No external control plane, no
|
|
64
83
|
per-seat anything. Register the modules you need; skip the ones you don't.
|
|
65
84
|
|
|
@@ -68,7 +87,7 @@ around `@fonderie/client`, nothing more. No business logic lives here; it
|
|
|
68
87
|
lives in `@fonderie/billing` on the server.
|
|
69
88
|
|
|
70
89
|
Browse the whole set at
|
|
71
|
-
[
|
|
90
|
+
[fonderiejs/sdk](https://github.com/fonderiejs/sdk) · follow
|
|
72
91
|
[@fonderiejs](https://x.com/fonderiejs)
|
|
73
92
|
|
|
74
93
|
## License
|
package/dist/index.cjs
CHANGED
|
@@ -35,15 +35,17 @@ var import_client9 = require("@fonderie/client");
|
|
|
35
35
|
|
|
36
36
|
// src/hooks/useBillingPortal.ts
|
|
37
37
|
var import_client = require("@fonderie/client");
|
|
38
|
-
var import_react = require("react");
|
|
38
|
+
var import_react = require("@fonderie/react");
|
|
39
|
+
var import_react2 = require("react");
|
|
39
40
|
function useBillingPortal(client) {
|
|
40
|
-
const
|
|
41
|
-
const [
|
|
42
|
-
const
|
|
41
|
+
const billing = (0, import_react.useFonderieSubClient)(client, (c) => c.billing, "useBillingPortal");
|
|
42
|
+
const [isLoading, setIsLoading] = (0, import_react2.useState)(false);
|
|
43
|
+
const [error, setError] = (0, import_react2.useState)(null);
|
|
44
|
+
const openPortal = (0, import_react2.useCallback)(async () => {
|
|
43
45
|
setIsLoading(true);
|
|
44
46
|
setError(null);
|
|
45
47
|
try {
|
|
46
|
-
const { result } = await
|
|
48
|
+
const { result } = await billing.createPortalSession();
|
|
47
49
|
return result.url;
|
|
48
50
|
} catch (err) {
|
|
49
51
|
const apiError = err instanceof import_client.FonderieApiError ? err : new import_client.FonderieApiError("unknown", String(err), 0);
|
|
@@ -52,22 +54,24 @@ function useBillingPortal(client) {
|
|
|
52
54
|
} finally {
|
|
53
55
|
setIsLoading(false);
|
|
54
56
|
}
|
|
55
|
-
}, [
|
|
57
|
+
}, [billing]);
|
|
56
58
|
return { openPortal, isLoading, error };
|
|
57
59
|
}
|
|
58
60
|
|
|
59
61
|
// src/hooks/useCheckout.ts
|
|
60
62
|
var import_client2 = require("@fonderie/client");
|
|
61
|
-
var
|
|
63
|
+
var import_react3 = require("@fonderie/react");
|
|
64
|
+
var import_react4 = require("react");
|
|
62
65
|
function useCheckout(client) {
|
|
63
|
-
const
|
|
64
|
-
const [
|
|
65
|
-
const
|
|
66
|
+
const billing = (0, import_react3.useFonderieSubClient)(client, (c) => c.billing, "useCheckout");
|
|
67
|
+
const [isLoading, setIsLoading] = (0, import_react4.useState)(false);
|
|
68
|
+
const [error, setError] = (0, import_react4.useState)(null);
|
|
69
|
+
const checkout = (0, import_react4.useCallback)(
|
|
66
70
|
async (input) => {
|
|
67
71
|
setIsLoading(true);
|
|
68
72
|
setError(null);
|
|
69
73
|
try {
|
|
70
|
-
const { result } = await
|
|
74
|
+
const { result } = await billing.createCheckoutSession(input);
|
|
71
75
|
return result.url;
|
|
72
76
|
} catch (err) {
|
|
73
77
|
const apiError = err instanceof import_client2.FonderieApiError ? err : new import_client2.FonderieApiError("unknown", String(err), 0);
|
|
@@ -77,32 +81,40 @@ function useCheckout(client) {
|
|
|
77
81
|
setIsLoading(false);
|
|
78
82
|
}
|
|
79
83
|
},
|
|
80
|
-
[
|
|
84
|
+
[billing]
|
|
81
85
|
);
|
|
82
86
|
return { checkout, isLoading, error };
|
|
83
87
|
}
|
|
84
88
|
|
|
85
89
|
// src/hooks/usePlan.ts
|
|
86
90
|
var import_client3 = require("@fonderie/client");
|
|
87
|
-
var
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const
|
|
91
|
-
const
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
setError(
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
91
|
+
var import_react5 = require("@fonderie/react");
|
|
92
|
+
var import_react6 = require("react");
|
|
93
|
+
function usePlan(clientOrPlanId, maybePlanId) {
|
|
94
|
+
const firstIsClient = clientOrPlanId === void 0 || clientOrPlanId instanceof import_client3.BillingClient;
|
|
95
|
+
const explicit = firstIsClient ? clientOrPlanId : void 0;
|
|
96
|
+
const planId = firstIsClient ? maybePlanId : clientOrPlanId;
|
|
97
|
+
const billing = (0, import_react5.useFonderieSubClient)(explicit, (c) => c.billing, "usePlan");
|
|
98
|
+
const [plan, setPlan] = (0, import_react6.useState)(null);
|
|
99
|
+
const [isLoading, setIsLoading] = (0, import_react6.useState)(true);
|
|
100
|
+
const [error, setError] = (0, import_react6.useState)(null);
|
|
101
|
+
const refresh = (0, import_react6.useCallback)(
|
|
102
|
+
async (opts) => {
|
|
103
|
+
setIsLoading(true);
|
|
104
|
+
setError(null);
|
|
105
|
+
try {
|
|
106
|
+
const { result } = await billing.getPlan(planId, { bust: opts?.force });
|
|
107
|
+
setPlan(result.plan);
|
|
108
|
+
} catch (err) {
|
|
109
|
+
const apiError = err instanceof import_client3.FonderieApiError ? err : new import_client3.FonderieApiError("unknown", String(err), 0);
|
|
110
|
+
setError(apiError);
|
|
111
|
+
} finally {
|
|
112
|
+
setIsLoading(false);
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
[billing, planId]
|
|
116
|
+
);
|
|
117
|
+
(0, import_react6.useEffect)(() => {
|
|
106
118
|
void refresh();
|
|
107
119
|
}, [refresh]);
|
|
108
120
|
return { plan, isLoading, error, refresh };
|
|
@@ -110,16 +122,18 @@ function usePlan(client, planId) {
|
|
|
110
122
|
|
|
111
123
|
// src/hooks/usePlanAdmin.ts
|
|
112
124
|
var import_client4 = require("@fonderie/client");
|
|
113
|
-
var
|
|
125
|
+
var import_react7 = require("@fonderie/react");
|
|
126
|
+
var import_react8 = require("react");
|
|
114
127
|
function usePlanAdmin(client) {
|
|
115
|
-
const
|
|
116
|
-
const [
|
|
117
|
-
const
|
|
128
|
+
const billing = (0, import_react7.useFonderieSubClient)(client, (c) => c.billing, "usePlanAdmin");
|
|
129
|
+
const [isLoading, setIsLoading] = (0, import_react8.useState)(false);
|
|
130
|
+
const [error, setError] = (0, import_react8.useState)(null);
|
|
131
|
+
const createPlan = (0, import_react8.useCallback)(
|
|
118
132
|
async (input) => {
|
|
119
133
|
setIsLoading(true);
|
|
120
134
|
setError(null);
|
|
121
135
|
try {
|
|
122
|
-
const { result } = await
|
|
136
|
+
const { result } = await billing.createPlan(input);
|
|
123
137
|
return result.plan;
|
|
124
138
|
} catch (err) {
|
|
125
139
|
const apiError = err instanceof import_client4.FonderieApiError ? err : new import_client4.FonderieApiError("unknown", String(err), 0);
|
|
@@ -129,14 +143,14 @@ function usePlanAdmin(client) {
|
|
|
129
143
|
setIsLoading(false);
|
|
130
144
|
}
|
|
131
145
|
},
|
|
132
|
-
[
|
|
146
|
+
[billing]
|
|
133
147
|
);
|
|
134
|
-
const updatePlan = (0,
|
|
148
|
+
const updatePlan = (0, import_react8.useCallback)(
|
|
135
149
|
async (planId, input) => {
|
|
136
150
|
setIsLoading(true);
|
|
137
151
|
setError(null);
|
|
138
152
|
try {
|
|
139
|
-
const { result } = await
|
|
153
|
+
const { result } = await billing.updatePlan(planId, input);
|
|
140
154
|
return result.plan;
|
|
141
155
|
} catch (err) {
|
|
142
156
|
const apiError = err instanceof import_client4.FonderieApiError ? err : new import_client4.FonderieApiError("unknown", String(err), 0);
|
|
@@ -146,14 +160,14 @@ function usePlanAdmin(client) {
|
|
|
146
160
|
setIsLoading(false);
|
|
147
161
|
}
|
|
148
162
|
},
|
|
149
|
-
[
|
|
163
|
+
[billing]
|
|
150
164
|
);
|
|
151
|
-
const deletePlan = (0,
|
|
165
|
+
const deletePlan = (0, import_react8.useCallback)(
|
|
152
166
|
async (planId) => {
|
|
153
167
|
setIsLoading(true);
|
|
154
168
|
setError(null);
|
|
155
169
|
try {
|
|
156
|
-
await
|
|
170
|
+
await billing.deletePlan(planId);
|
|
157
171
|
} catch (err) {
|
|
158
172
|
const apiError = err instanceof import_client4.FonderieApiError ? err : new import_client4.FonderieApiError("unknown", String(err), 0);
|
|
159
173
|
setError(apiError);
|
|
@@ -162,49 +176,100 @@ function usePlanAdmin(client) {
|
|
|
162
176
|
setIsLoading(false);
|
|
163
177
|
}
|
|
164
178
|
},
|
|
165
|
-
[
|
|
179
|
+
[billing]
|
|
166
180
|
);
|
|
167
181
|
return { createPlan, updatePlan, deletePlan, isLoading, error };
|
|
168
182
|
}
|
|
169
183
|
|
|
170
184
|
// src/hooks/usePlans.ts
|
|
171
185
|
var import_client5 = require("@fonderie/client");
|
|
172
|
-
var
|
|
186
|
+
var import_react9 = require("@fonderie/react");
|
|
187
|
+
var import_react10 = require("react");
|
|
173
188
|
function usePlans(client) {
|
|
174
|
-
const
|
|
175
|
-
const [
|
|
176
|
-
const [
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
189
|
+
const billing = (0, import_react9.useFonderieSubClient)(client, (c) => c.billing, "usePlans");
|
|
190
|
+
const [plans, setPlans] = (0, import_react10.useState)([]);
|
|
191
|
+
const [isLoading, setIsLoading] = (0, import_react10.useState)(true);
|
|
192
|
+
const [error, setError] = (0, import_react10.useState)(null);
|
|
193
|
+
const refresh = (0, import_react10.useCallback)(
|
|
194
|
+
async (opts) => {
|
|
195
|
+
setIsLoading(true);
|
|
196
|
+
setError(null);
|
|
197
|
+
try {
|
|
198
|
+
const { result } = await billing.listPlans({ bust: opts?.force });
|
|
199
|
+
setPlans(result.plans);
|
|
200
|
+
} catch (err) {
|
|
201
|
+
const apiError = err instanceof import_client5.FonderieApiError ? err : new import_client5.FonderieApiError("unknown", String(err), 0);
|
|
202
|
+
setError(apiError);
|
|
203
|
+
} finally {
|
|
204
|
+
setIsLoading(false);
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
[billing]
|
|
208
|
+
);
|
|
209
|
+
const createPlan = (0, import_react10.useCallback)(
|
|
210
|
+
async (input) => {
|
|
211
|
+
setError(null);
|
|
212
|
+
try {
|
|
213
|
+
const { result } = await billing.createPlan(input);
|
|
214
|
+
await refresh();
|
|
215
|
+
return result.plan;
|
|
216
|
+
} catch (err) {
|
|
217
|
+
const apiError = err instanceof import_client5.FonderieApiError ? err : new import_client5.FonderieApiError("unknown", String(err), 0);
|
|
218
|
+
setError(apiError);
|
|
219
|
+
throw apiError;
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
[billing, refresh]
|
|
223
|
+
);
|
|
224
|
+
const updatePlan = (0, import_react10.useCallback)(
|
|
225
|
+
async (planId, input) => {
|
|
226
|
+
setError(null);
|
|
227
|
+
try {
|
|
228
|
+
const { result } = await billing.updatePlan(planId, input);
|
|
229
|
+
await refresh();
|
|
230
|
+
return result.plan;
|
|
231
|
+
} catch (err) {
|
|
232
|
+
const apiError = err instanceof import_client5.FonderieApiError ? err : new import_client5.FonderieApiError("unknown", String(err), 0);
|
|
233
|
+
setError(apiError);
|
|
234
|
+
throw apiError;
|
|
235
|
+
}
|
|
236
|
+
},
|
|
237
|
+
[billing, refresh]
|
|
238
|
+
);
|
|
239
|
+
const deletePlan = (0, import_react10.useCallback)(
|
|
240
|
+
async (planId) => {
|
|
241
|
+
setError(null);
|
|
242
|
+
try {
|
|
243
|
+
await billing.deletePlan(planId);
|
|
244
|
+
await refresh();
|
|
245
|
+
} catch (err) {
|
|
246
|
+
const apiError = err instanceof import_client5.FonderieApiError ? err : new import_client5.FonderieApiError("unknown", String(err), 0);
|
|
247
|
+
setError(apiError);
|
|
248
|
+
throw apiError;
|
|
249
|
+
}
|
|
250
|
+
},
|
|
251
|
+
[billing, refresh]
|
|
252
|
+
);
|
|
253
|
+
(0, import_react10.useEffect)(() => {
|
|
191
254
|
void refresh();
|
|
192
255
|
}, [refresh]);
|
|
193
|
-
return { plans, isLoading, error, refresh };
|
|
256
|
+
return { plans, isLoading, error, refresh, createPlan, updatePlan, deletePlan };
|
|
194
257
|
}
|
|
195
258
|
|
|
196
259
|
// src/hooks/useRecordUsage.ts
|
|
197
260
|
var import_client6 = require("@fonderie/client");
|
|
198
|
-
var
|
|
261
|
+
var import_react11 = require("@fonderie/react");
|
|
262
|
+
var import_react12 = require("react");
|
|
199
263
|
function useRecordUsage(client) {
|
|
200
|
-
const
|
|
201
|
-
const [
|
|
202
|
-
const
|
|
264
|
+
const billing = (0, import_react11.useFonderieSubClient)(client, (c) => c.billing, "useRecordUsage");
|
|
265
|
+
const [isLoading, setIsLoading] = (0, import_react12.useState)(false);
|
|
266
|
+
const [error, setError] = (0, import_react12.useState)(null);
|
|
267
|
+
const recordUsage = (0, import_react12.useCallback)(
|
|
203
268
|
async (input) => {
|
|
204
269
|
setIsLoading(true);
|
|
205
270
|
setError(null);
|
|
206
271
|
try {
|
|
207
|
-
await
|
|
272
|
+
await billing.recordUsage(input);
|
|
208
273
|
} catch (err) {
|
|
209
274
|
const apiError = err instanceof import_client6.FonderieApiError ? err : new import_client6.FonderieApiError("unknown", String(err), 0);
|
|
210
275
|
setError(apiError);
|
|
@@ -213,33 +278,38 @@ function useRecordUsage(client) {
|
|
|
213
278
|
setIsLoading(false);
|
|
214
279
|
}
|
|
215
280
|
},
|
|
216
|
-
[
|
|
281
|
+
[billing]
|
|
217
282
|
);
|
|
218
283
|
return { recordUsage, isLoading, error };
|
|
219
284
|
}
|
|
220
285
|
|
|
221
286
|
// src/hooks/useSubscription.ts
|
|
222
287
|
var import_client7 = require("@fonderie/client");
|
|
223
|
-
var
|
|
288
|
+
var import_react13 = require("@fonderie/react");
|
|
289
|
+
var import_react14 = require("react");
|
|
224
290
|
function useSubscription(client) {
|
|
225
|
-
const
|
|
226
|
-
const [
|
|
227
|
-
const [
|
|
228
|
-
const
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
291
|
+
const billing = (0, import_react13.useFonderieSubClient)(client, (c) => c.billing, "useSubscription");
|
|
292
|
+
const [subscription, setSubscription] = (0, import_react14.useState)(null);
|
|
293
|
+
const [isLoading, setIsLoading] = (0, import_react14.useState)(true);
|
|
294
|
+
const [error, setError] = (0, import_react14.useState)(null);
|
|
295
|
+
const refresh = (0, import_react14.useCallback)(
|
|
296
|
+
async (opts) => {
|
|
297
|
+
setIsLoading(true);
|
|
298
|
+
setError(null);
|
|
299
|
+
try {
|
|
300
|
+
const { result } = await billing.getSubscription({ bust: opts?.force });
|
|
301
|
+
setSubscription(result.subscription);
|
|
302
|
+
} catch (err) {
|
|
303
|
+
const apiError = err instanceof import_client7.FonderieApiError ? err : new import_client7.FonderieApiError("unknown", String(err), 0);
|
|
304
|
+
if (apiError.status !== 404) setError(apiError);
|
|
305
|
+
setSubscription(null);
|
|
306
|
+
} finally {
|
|
307
|
+
setIsLoading(false);
|
|
308
|
+
}
|
|
309
|
+
},
|
|
310
|
+
[billing]
|
|
311
|
+
);
|
|
312
|
+
(0, import_react14.useEffect)(() => {
|
|
243
313
|
void refresh();
|
|
244
314
|
}, [refresh]);
|
|
245
315
|
return { subscription, isLoading, error, refresh };
|
|
@@ -247,28 +317,50 @@ function useSubscription(client) {
|
|
|
247
317
|
|
|
248
318
|
// src/hooks/useUsage.ts
|
|
249
319
|
var import_client8 = require("@fonderie/client");
|
|
250
|
-
var
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
const
|
|
254
|
-
const
|
|
255
|
-
const
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
setError(
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
320
|
+
var import_react15 = require("@fonderie/react");
|
|
321
|
+
var import_react16 = require("react");
|
|
322
|
+
function useUsage(clientOrMetric, maybeMetric) {
|
|
323
|
+
const firstIsClient = clientOrMetric === void 0 || clientOrMetric instanceof import_client8.BillingClient;
|
|
324
|
+
const explicit = firstIsClient ? clientOrMetric : void 0;
|
|
325
|
+
const metric = firstIsClient ? maybeMetric : clientOrMetric;
|
|
326
|
+
const billing = (0, import_react15.useFonderieSubClient)(explicit, (c) => c.billing, "useUsage");
|
|
327
|
+
const [total, setTotal] = (0, import_react16.useState)(null);
|
|
328
|
+
const [isLoading, setIsLoading] = (0, import_react16.useState)(true);
|
|
329
|
+
const [error, setError] = (0, import_react16.useState)(null);
|
|
330
|
+
const refresh = (0, import_react16.useCallback)(
|
|
331
|
+
async (opts) => {
|
|
332
|
+
setIsLoading(true);
|
|
333
|
+
setError(null);
|
|
334
|
+
try {
|
|
335
|
+
const { result } = await billing.getUsage(metric, { bust: opts?.force });
|
|
336
|
+
setTotal(result.total);
|
|
337
|
+
} catch (err) {
|
|
338
|
+
const apiError = err instanceof import_client8.FonderieApiError ? err : new import_client8.FonderieApiError("unknown", String(err), 0);
|
|
339
|
+
setError(apiError);
|
|
340
|
+
} finally {
|
|
341
|
+
setIsLoading(false);
|
|
342
|
+
}
|
|
343
|
+
},
|
|
344
|
+
[billing, metric]
|
|
345
|
+
);
|
|
346
|
+
const recordUsage = (0, import_react16.useCallback)(
|
|
347
|
+
async (input) => {
|
|
348
|
+
setError(null);
|
|
349
|
+
try {
|
|
350
|
+
await billing.recordUsage(input);
|
|
351
|
+
await refresh();
|
|
352
|
+
} catch (err) {
|
|
353
|
+
const apiError = err instanceof import_client8.FonderieApiError ? err : new import_client8.FonderieApiError("unknown", String(err), 0);
|
|
354
|
+
setError(apiError);
|
|
355
|
+
throw apiError;
|
|
356
|
+
}
|
|
357
|
+
},
|
|
358
|
+
[billing, refresh]
|
|
359
|
+
);
|
|
360
|
+
(0, import_react16.useEffect)(() => {
|
|
269
361
|
void refresh();
|
|
270
362
|
}, [refresh]);
|
|
271
|
-
return { total, isLoading, error, refresh };
|
|
363
|
+
return { total, isLoading, error, refresh, recordUsage };
|
|
272
364
|
}
|
|
273
365
|
// Annotate the CommonJS export names for ESM import in node:
|
|
274
366
|
0 && (module.exports = {
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/hooks/useBillingPortal.ts","../src/hooks/useCheckout.ts","../src/hooks/usePlan.ts","../src/hooks/usePlanAdmin.ts","../src/hooks/usePlans.ts","../src/hooks/useRecordUsage.ts","../src/hooks/useSubscription.ts","../src/hooks/useUsage.ts"],"sourcesContent":["export type {\n\tBillingClient,\n\tICheckoutInput,\n\tICreatePlanInput,\n\tIPlanDTO,\n\tIPlanFeature,\n\tIRecordUsageInput,\n\tISubscriptionDTO,\n\tIUpdatePlanInput,\n\tSubscriberType,\n} from '@fonderie/client';\nexport { FonderieApiError } from '@fonderie/client';\nexport type {\n\tIUseBillingPortalReturn,\n\tIUseCheckoutReturn,\n\tIUsePlanAdminReturn,\n\tIUsePlanReturn,\n\tIUsePlansReturn,\n\tIUseRecordUsageReturn,\n\tIUseSubscriptionReturn,\n\tIUseUsageReturn,\n} from './hooks';\nexport {\n\tuseBillingPortal,\n\tuseCheckout,\n\tusePlan,\n\tusePlanAdmin,\n\tusePlans,\n\tuseRecordUsage,\n\tuseSubscription,\n\tuseUsage,\n} from './hooks';\n","import type { BillingClient } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useCallback, useState } from 'react';\n\nexport interface IUseBillingPortalReturn {\n\topenPortal: () => Promise<string>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n}\n\nexport function useBillingPortal(client: BillingClient): IUseBillingPortalReturn {\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst openPortal = useCallback(async () => {\n\t\tsetIsLoading(true);\n\t\tsetError(null);\n\t\ttry {\n\t\t\tconst { result } = await client.createPortalSession();\n\t\t\treturn result.url;\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\tsetError(apiError);\n\t\t\tthrow apiError;\n\t\t} finally {\n\t\t\tsetIsLoading(false);\n\t\t}\n\t}, [client]);\n\n\treturn { openPortal, isLoading, error };\n}\n","import type { BillingClient, ICheckoutInput } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useCallback, useState } from 'react';\n\nexport interface IUseCheckoutReturn {\n\tcheckout: (input: ICheckoutInput) => Promise<string>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n}\n\nexport function useCheckout(client: BillingClient): IUseCheckoutReturn {\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst checkout = useCallback(\n\t\tasync (input: ICheckoutInput) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await client.createCheckoutSession(input);\n\t\t\t\treturn result.url;\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[client],\n\t);\n\n\treturn { checkout, isLoading, error };\n}\n","import type { BillingClient, IPlanDTO } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUsePlanReturn {\n\tplan: IPlanDTO | null;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: () => Promise<void>;\n}\n\nexport function usePlan(client: BillingClient, planId: string): IUsePlanReturn {\n\tconst [plan, setPlan] = useState<IPlanDTO | null>(null);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(async () => {\n\t\tsetIsLoading(true);\n\t\tsetError(null);\n\t\ttry {\n\t\t\tconst { result } = await client.getPlan(planId);\n\t\t\tsetPlan(result.plan);\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\tsetError(apiError);\n\t\t} finally {\n\t\t\tsetIsLoading(false);\n\t\t}\n\t}, [client, planId]);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { plan, isLoading, error, refresh };\n}\n","import type { BillingClient, ICreatePlanInput, IPlanDTO, IUpdatePlanInput } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useCallback, useState } from 'react';\n\nexport interface IUsePlanAdminReturn {\n\tcreatePlan: (input: ICreatePlanInput) => Promise<IPlanDTO>;\n\tupdatePlan: (planId: string, input: IUpdatePlanInput) => Promise<IPlanDTO>;\n\tdeletePlan: (planId: string) => Promise<void>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n}\n\n// Action-only, like useUpdateRole/useWorkspaceProfile — pair with usePlans()\n// for the list and call its refresh() after a write.\n//\n// Unlike every other write in this SDK, @fonderie/billing does not gate\n// createPlan/updatePlan/deletePlan with requireAuth or an admin token — the\n// server trusts the caller to authorize access itself. Gate the UI that\n// calls this hook behind your own admin check before shipping it.\nexport function usePlanAdmin(client: BillingClient): IUsePlanAdminReturn {\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst createPlan = useCallback(\n\t\tasync (input: ICreatePlanInput) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await client.createPlan(input);\n\t\t\t\treturn result.plan;\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[client],\n\t);\n\n\tconst updatePlan = useCallback(\n\t\tasync (planId: string, input: IUpdatePlanInput) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await client.updatePlan(planId, input);\n\t\t\t\treturn result.plan;\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[client],\n\t);\n\n\tconst deletePlan = useCallback(\n\t\tasync (planId: string) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tawait client.deletePlan(planId);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[client],\n\t);\n\n\treturn { createPlan, updatePlan, deletePlan, isLoading, error };\n}\n","import type { BillingClient, IPlanDTO } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUsePlansReturn {\n\tplans: IPlanDTO[];\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: () => Promise<void>;\n}\n\nexport function usePlans(client: BillingClient): IUsePlansReturn {\n\tconst [plans, setPlans] = useState<IPlanDTO[]>([]);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(async () => {\n\t\tsetIsLoading(true);\n\t\tsetError(null);\n\t\ttry {\n\t\t\tconst { result } = await client.listPlans();\n\t\t\tsetPlans(result.plans);\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\tsetError(apiError);\n\t\t} finally {\n\t\t\tsetIsLoading(false);\n\t\t}\n\t}, [client]);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { plans, isLoading, error, refresh };\n}\n","import type { BillingClient, IRecordUsageInput } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useCallback, useState } from 'react';\n\nexport interface IUseRecordUsageReturn {\n\trecordUsage: (input: IRecordUsageInput) => Promise<void>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n}\n\nexport function useRecordUsage(client: BillingClient): IUseRecordUsageReturn {\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst recordUsage = useCallback(\n\t\tasync (input: IRecordUsageInput) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tawait client.recordUsage(input);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[client],\n\t);\n\n\treturn { recordUsage, isLoading, error };\n}\n","import type { BillingClient, ISubscriptionDTO } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUseSubscriptionReturn {\n\tsubscription: ISubscriptionDTO | null;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: () => Promise<void>;\n}\n\nexport function useSubscription(client: BillingClient): IUseSubscriptionReturn {\n\tconst [subscription, setSubscription] = useState<ISubscriptionDTO | null>(null);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(async () => {\n\t\tsetIsLoading(true);\n\t\tsetError(null);\n\t\ttry {\n\t\t\tconst { result } = await client.getSubscription();\n\t\t\tsetSubscription(result.subscription);\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t// No active subscription is a normal, expected state — not an error banner.\n\t\t\tif (apiError.status !== 404) setError(apiError);\n\t\t\tsetSubscription(null);\n\t\t} finally {\n\t\t\tsetIsLoading(false);\n\t\t}\n\t}, [client]);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { subscription, isLoading, error, refresh };\n}\n","import type { BillingClient } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUseUsageReturn {\n\ttotal: number | null;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: () => Promise<void>;\n}\n\nexport function useUsage(client: BillingClient, metric: string): IUseUsageReturn {\n\tconst [total, setTotal] = useState<number | null>(null);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(async () => {\n\t\tsetIsLoading(true);\n\t\tsetError(null);\n\t\ttry {\n\t\t\tconst { result } = await client.getUsage(metric);\n\t\t\tsetTotal(result.total);\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\tsetError(apiError);\n\t\t} finally {\n\t\t\tsetIsLoading(false);\n\t\t}\n\t}, [client, metric]);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { total, isLoading, error, refresh };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,IAAAA,iBAAiC;;;ACVjC,oBAAiC;AACjC,mBAAsC;AAQ/B,SAAS,iBAAiB,QAAgD;AAChF,QAAM,CAAC,WAAW,YAAY,QAAI,uBAAS,KAAK;AAChD,QAAM,CAAC,OAAO,QAAQ,QAAI,uBAAkC,IAAI;AAEhE,QAAM,iBAAa,0BAAY,YAAY;AAC1C,iBAAa,IAAI;AACjB,aAAS,IAAI;AACb,QAAI;AACH,YAAM,EAAE,OAAO,IAAI,MAAM,OAAO,oBAA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AM,CAAC;AAEX,+BAAU,MAAM;AACf,SAAK,QAAQ;AAAA,EACd,GAAG,CAAC,OAAO,CAAC;AAEZ,SAAO,EAAE,cAAc,WAAW,OAAO,QAAQ;AAClD;;;ACrCA,IAAAC,iBAAiC;AACjC,IAAAC,gBAAiD;AAS1C,SAAS,SAAS,QAAuB,QAAiC;AAChF,QAAM,CAAC,OAAO,QAAQ,QAAI,wBAAwB,IAAI;AACtD,QAAM,CAAC,WAAW,YAAY,QAAI,wBAAS,IAAI;AAC/C,QAAM,CAAC,OAAO,QAAQ,QAAI,wBAAkC,IAAI;AAEhE,QAAM,cAAU,2BAAY,YAAY;AACvC,iBAAa,IAAI;AACjB,aAAS,IAAI;AACb,QAAI;AACH,YAAM,EAAE,OAAO,IAAI,MAAM,OAAO,SAAS,MAAM;AAC/C,eAAS,OAAO,KAAK;AAAA,IACtB,SAAS,KAAK;AACb,YAAM,WACL,eAAe,kCAAmB,MAAM,IAAI,gCAAiB,WAAW,OAAO,GAAG,GAAG,CAAC;AACvF,eAAS,QAAQ;AAAA,IAClB,UAAE;AACD,mBAAa,KAAK;AAAA,IACnB;AAAA,EACD,GAAG,CAAC,QAAQ,MAAM,CAAC;AAEnB,+BAAU,MAAM;AACf,SAAK,QAAQ;AAAA,EACd,GAAG,CAAC,OAAO,CAAC;AAEZ,SAAO,EAAE,OAAO,WAAW,OAAO,QAAQ;AAC3C;","names":["import_client","import_client","import_react","import_client","import_react","import_client","import_react","import_client","import_react","import_client","import_react","import_client","import_react","import_client","import_react"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/hooks/useBillingPortal.ts","../src/hooks/useCheckout.ts","../src/hooks/usePlan.ts","../src/hooks/usePlanAdmin.ts","../src/hooks/usePlans.ts","../src/hooks/useRecordUsage.ts","../src/hooks/useSubscription.ts","../src/hooks/useUsage.ts"],"sourcesContent":["export type {\n\tBillingClient,\n\tICheckoutInput,\n\tICreatePlanInput,\n\tIPlanDTO,\n\tIPlanFeature,\n\tIRecordUsageInput,\n\tISubscriptionDTO,\n\tIUpdatePlanInput,\n\tSubscriberType,\n} from '@fonderie/client';\nexport { FonderieApiError } from '@fonderie/client';\nexport type {\n\tIUseBillingPortalReturn,\n\tIUseCheckoutReturn,\n\tIUsePlanAdminReturn,\n\tIUsePlanReturn,\n\tIUsePlansReturn,\n\tIUseRecordUsageReturn,\n\tIUseSubscriptionReturn,\n\tIUseUsageReturn,\n} from './hooks';\nexport {\n\tuseBillingPortal,\n\tuseCheckout,\n\tusePlan,\n\tusePlanAdmin,\n\tusePlans,\n\tuseRecordUsage,\n\tuseSubscription,\n\tuseUsage,\n} from './hooks';\n","import type { BillingClient } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useState } from 'react';\n\nexport interface IUseBillingPortalReturn {\n\topenPortal: () => Promise<string>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n}\n\nexport function useBillingPortal(client?: BillingClient): IUseBillingPortalReturn {\n\tconst billing = useFonderieSubClient(client, (c) => c.billing, 'useBillingPortal');\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst openPortal = useCallback(async () => {\n\t\tsetIsLoading(true);\n\t\tsetError(null);\n\t\ttry {\n\t\t\tconst { result } = await billing.createPortalSession();\n\t\t\treturn result.url;\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\tsetError(apiError);\n\t\t\tthrow apiError;\n\t\t} finally {\n\t\t\tsetIsLoading(false);\n\t\t}\n\t}, [billing]);\n\n\treturn { openPortal, isLoading, error };\n}\n","import type { BillingClient, ICheckoutInput } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useState } from 'react';\n\nexport interface IUseCheckoutReturn {\n\tcheckout: (input: ICheckoutInput) => Promise<string>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n}\n\nexport function useCheckout(client?: BillingClient): IUseCheckoutReturn {\n\tconst billing = useFonderieSubClient(client, (c) => c.billing, 'useCheckout');\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst checkout = useCallback(\n\t\tasync (input: ICheckoutInput) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.createCheckoutSession(input);\n\t\t\t\treturn result.url;\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[billing],\n\t);\n\n\treturn { checkout, isLoading, error };\n}\n","import type { IPlanDTO } from '@fonderie/client';\nimport { BillingClient, FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUsePlanReturn {\n\tplan: IPlanDTO | null;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: (opts?: { force?: boolean }) => Promise<void>;\n}\n\nexport function usePlan(planId: string): IUsePlanReturn;\nexport function usePlan(client: BillingClient | undefined, planId: string): IUsePlanReturn;\nexport function usePlan(\n\tclientOrPlanId: BillingClient | string | undefined,\n\tmaybePlanId?: string,\n): IUsePlanReturn {\n\tconst firstIsClient = clientOrPlanId === undefined || clientOrPlanId instanceof BillingClient;\n\tconst explicit = firstIsClient ? (clientOrPlanId as BillingClient | undefined) : undefined;\n\tconst planId = firstIsClient ? (maybePlanId as string) : clientOrPlanId;\n\tconst billing = useFonderieSubClient(explicit, (c) => c.billing, 'usePlan');\n\tconst [plan, setPlan] = useState<IPlanDTO | null>(null);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(\n\t\tasync (opts?: { force?: boolean }) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.getPlan(planId, { bust: opts?.force });\n\t\t\t\tsetPlan(result.plan);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[billing, planId],\n\t);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { plan, isLoading, error, refresh };\n}\n","import type { BillingClient, ICreatePlanInput, IPlanDTO, IUpdatePlanInput } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useState } from 'react';\n\n/** @deprecated Use `usePlans().createPlan` / `updatePlan` / `deletePlan` instead — the list hook self-refreshes after each write. */\nexport interface IUsePlanAdminReturn {\n\tcreatePlan: (input: ICreatePlanInput) => Promise<IPlanDTO>;\n\tupdatePlan: (planId: string, input: IUpdatePlanInput) => Promise<IPlanDTO>;\n\tdeletePlan: (planId: string) => Promise<void>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n}\n\n// Action-only, like useUpdateRole/useWorkspaceProfile — pair with usePlans()\n// for the list and call its refresh() after a write.\n//\n// Unlike every other write in this SDK, @fonderie/billing does not gate\n// createPlan/updatePlan/deletePlan with requireAuth or an admin token — the\n// server trusts the caller to authorize access itself. Gate the UI that\n// calls this hook behind your own admin check before shipping it.\n/** @deprecated Use `usePlans().createPlan` / `updatePlan` / `deletePlan` instead — the list hook self-refreshes after each write. */\nexport function usePlanAdmin(client?: BillingClient): IUsePlanAdminReturn {\n\tconst billing = useFonderieSubClient(client, (c) => c.billing, 'usePlanAdmin');\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst createPlan = useCallback(\n\t\tasync (input: ICreatePlanInput) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.createPlan(input);\n\t\t\t\treturn result.plan;\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[billing],\n\t);\n\n\tconst updatePlan = useCallback(\n\t\tasync (planId: string, input: IUpdatePlanInput) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.updatePlan(planId, input);\n\t\t\t\treturn result.plan;\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[billing],\n\t);\n\n\tconst deletePlan = useCallback(\n\t\tasync (planId: string) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tawait billing.deletePlan(planId);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[billing],\n\t);\n\n\treturn { createPlan, updatePlan, deletePlan, isLoading, error };\n}\n","import type {\n\tBillingClient,\n\tICreatePlanInput,\n\tIPlanDTO,\n\tIUpdatePlanInput,\n} from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUsePlansReturn {\n\tplans: IPlanDTO[];\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: (opts?: { force?: boolean }) => Promise<void>;\n\tcreatePlan: (input: ICreatePlanInput) => Promise<IPlanDTO>;\n\tupdatePlan: (planId: string, input: IUpdatePlanInput) => Promise<IPlanDTO>;\n\tdeletePlan: (planId: string) => Promise<void>;\n}\n\nexport function usePlans(client?: BillingClient): IUsePlansReturn {\n\tconst billing = useFonderieSubClient(client, (c) => c.billing, 'usePlans');\n\tconst [plans, setPlans] = useState<IPlanDTO[]>([]);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(\n\t\tasync (opts?: { force?: boolean }) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.listPlans({ bust: opts?.force });\n\t\t\t\tsetPlans(result.plans);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[billing],\n\t);\n\n\t// Like usePlanAdmin, these writes are not auth-gated by @fonderie/billing —\n\t// gate the UI that calls them behind your own admin check before shipping it.\n\tconst createPlan = useCallback(\n\t\tasync (input: ICreatePlanInput) => {\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.createPlan(input);\n\t\t\t\tawait refresh();\n\t\t\t\treturn result.plan;\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t}\n\t\t},\n\t\t[billing, refresh],\n\t);\n\n\tconst updatePlan = useCallback(\n\t\tasync (planId: string, input: IUpdatePlanInput) => {\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.updatePlan(planId, input);\n\t\t\t\tawait refresh();\n\t\t\t\treturn result.plan;\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t}\n\t\t},\n\t\t[billing, refresh],\n\t);\n\n\tconst deletePlan = useCallback(\n\t\tasync (planId: string) => {\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tawait billing.deletePlan(planId);\n\t\t\t\tawait refresh();\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t}\n\t\t},\n\t\t[billing, refresh],\n\t);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { plans, isLoading, error, refresh, createPlan, updatePlan, deletePlan };\n}\n","import type { BillingClient, IRecordUsageInput } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useState } from 'react';\n\n/** @deprecated Use `useUsage(metric).recordUsage` instead — the usage hook self-refreshes after the write. */\nexport interface IUseRecordUsageReturn {\n\trecordUsage: (input: IRecordUsageInput) => Promise<void>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n}\n\n/** @deprecated Use `useUsage(metric).recordUsage` instead — the usage hook self-refreshes after the write. */\nexport function useRecordUsage(client?: BillingClient): IUseRecordUsageReturn {\n\tconst billing = useFonderieSubClient(client, (c) => c.billing, 'useRecordUsage');\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst recordUsage = useCallback(\n\t\tasync (input: IRecordUsageInput) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tawait billing.recordUsage(input);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[billing],\n\t);\n\n\treturn { recordUsage, isLoading, error };\n}\n","import type { BillingClient, ISubscriptionDTO } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUseSubscriptionReturn {\n\tsubscription: ISubscriptionDTO | null;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: (opts?: { force?: boolean }) => Promise<void>;\n}\n\nexport function useSubscription(client?: BillingClient): IUseSubscriptionReturn {\n\tconst billing = useFonderieSubClient(client, (c) => c.billing, 'useSubscription');\n\tconst [subscription, setSubscription] = useState<ISubscriptionDTO | null>(null);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(\n\t\tasync (opts?: { force?: boolean }) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.getSubscription({ bust: opts?.force });\n\t\t\t\tsetSubscription(result.subscription);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\t// No active subscription is a normal, expected state — not an error banner.\n\t\t\t\tif (apiError.status !== 404) setError(apiError);\n\t\t\t\tsetSubscription(null);\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[billing],\n\t);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { subscription, isLoading, error, refresh };\n}\n","import type { IRecordUsageInput } from '@fonderie/client';\nimport { BillingClient, FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUseUsageReturn {\n\ttotal: number | null;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: (opts?: { force?: boolean }) => Promise<void>;\n\trecordUsage: (input: IRecordUsageInput) => Promise<void>;\n}\n\nexport function useUsage(metric: string): IUseUsageReturn;\nexport function useUsage(client: BillingClient | undefined, metric: string): IUseUsageReturn;\nexport function useUsage(\n\tclientOrMetric: BillingClient | string | undefined,\n\tmaybeMetric?: string,\n): IUseUsageReturn {\n\tconst firstIsClient = clientOrMetric === undefined || clientOrMetric instanceof BillingClient;\n\tconst explicit = firstIsClient ? (clientOrMetric as BillingClient | undefined) : undefined;\n\tconst metric = firstIsClient ? (maybeMetric as string) : clientOrMetric;\n\tconst billing = useFonderieSubClient(explicit, (c) => c.billing, 'useUsage');\n\tconst [total, setTotal] = useState<number | null>(null);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(\n\t\tasync (opts?: { force?: boolean }) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.getUsage(metric, { bust: opts?.force });\n\t\t\t\tsetTotal(result.total);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[billing, metric],\n\t);\n\n\tconst recordUsage = useCallback(\n\t\tasync (input: IRecordUsageInput) => {\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tawait billing.recordUsage(input);\n\t\t\t\tawait refresh();\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t}\n\t\t},\n\t\t[billing, refresh],\n\t);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { total, isLoading, error, refresh, recordUsage };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,IAAAA,iBAAiC;;;ACVjC,oBAAiC;AACjC,mBAAqC;AACrC,IAAAC,gBAAsC;AAQ/B,SAAS,iBAAiB,QAAiD;AACjF,QAAM,cAAU,mCAAqB,QAAQ,CAAC,MAAM,EAAE,SAAS,kBAAkB;AACjF,QAAM,CAAC,WAAW,YAAY,QAAI,wBAAS,KAAK;AAChD,QAAM,CAAC,OAAO,QAAQ,QAAI,wBAAkC,IAAI;AAEhE,QAAM,iBAAa,2BAAY,YAAY;AAC1C,iBAAa,IAAI;AACjB,aAAS,IAAI;AACb,QAAI;AACH,YAAM,EAAE,OAAO,IAAI,MAAM,QAAQ,oBAAoB;AACrD,aAAO,OAAO;AAAA,IACf,SAAS,KAAK;AACb,YAAM,WACL,eAAe,iCAAmB,MAAM,IAAI,+BAAiB,WAAW,OAAO,GAAG,GAAG,CAAC;AACvF,eAAS,QAAQ;AACjB,YAAM;AAAA,IACP,UAAE;AACD,mBAAa,KAAK;AAAA,IACnB;AAAA,EACD,GAAG,CAAC,OAAO,CAAC;AAEZ,SA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O,GAAG,GAAG,CAAC;AACvF,iBAAS,QAAQ;AAAA,MAClB,UAAE;AACD,qBAAa,KAAK;AAAA,MACnB;AAAA,IACD;AAAA,IACA,CAAC,SAAS,MAAM;AAAA,EACjB;AAEA,QAAM,kBAAc;AAAA,IACnB,OAAO,UAA6B;AACnC,eAAS,IAAI;AACb,UAAI;AACH,cAAM,QAAQ,YAAY,KAAK;AAC/B,cAAM,QAAQ;AAAA,MACf,SAAS,KAAK;AACb,cAAM,WACL,eAAe,kCAAmB,MAAM,IAAI,gCAAiB,WAAW,OAAO,GAAG,GAAG,CAAC;AACvF,iBAAS,QAAQ;AACjB,cAAM;AAAA,MACP;AAAA,IACD;AAAA,IACA,CAAC,SAAS,OAAO;AAAA,EAClB;AAEA,gCAAU,MAAM;AACf,SAAK,QAAQ;AAAA,EACd,GAAG,CAAC,OAAO,CAAC;AAEZ,SAAO,EAAE,OAAO,WAAW,OAAO,SAAS,YAAY;AACxD;","names":["import_client","import_react","import_client","import_react","import_client","import_react","import_client","import_react","import_client","import_react","import_client","import_react","import_client","import_react","import_client","import_react"]}
|