@fonderie/react-billing 0.1.0 → 0.2.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 +86 -64
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -8
- package/dist/index.d.ts +10 -8
- package/dist/index.js +46 -24
- 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,23 +81,28 @@ 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
|
|
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)(async () => {
|
|
93
102
|
setIsLoading(true);
|
|
94
103
|
setError(null);
|
|
95
104
|
try {
|
|
96
|
-
const { result } = await
|
|
105
|
+
const { result } = await billing.getPlan(planId);
|
|
97
106
|
setPlan(result.plan);
|
|
98
107
|
} catch (err) {
|
|
99
108
|
const apiError = err instanceof import_client3.FonderieApiError ? err : new import_client3.FonderieApiError("unknown", String(err), 0);
|
|
@@ -101,8 +110,8 @@ function usePlan(client, planId) {
|
|
|
101
110
|
} finally {
|
|
102
111
|
setIsLoading(false);
|
|
103
112
|
}
|
|
104
|
-
}, [
|
|
105
|
-
(0,
|
|
113
|
+
}, [billing, planId]);
|
|
114
|
+
(0, import_react6.useEffect)(() => {
|
|
106
115
|
void refresh();
|
|
107
116
|
}, [refresh]);
|
|
108
117
|
return { plan, isLoading, error, refresh };
|
|
@@ -110,16 +119,18 @@ function usePlan(client, planId) {
|
|
|
110
119
|
|
|
111
120
|
// src/hooks/usePlanAdmin.ts
|
|
112
121
|
var import_client4 = require("@fonderie/client");
|
|
113
|
-
var
|
|
122
|
+
var import_react7 = require("@fonderie/react");
|
|
123
|
+
var import_react8 = require("react");
|
|
114
124
|
function usePlanAdmin(client) {
|
|
115
|
-
const
|
|
116
|
-
const [
|
|
117
|
-
const
|
|
125
|
+
const billing = (0, import_react7.useFonderieSubClient)(client, (c) => c.billing, "usePlanAdmin");
|
|
126
|
+
const [isLoading, setIsLoading] = (0, import_react8.useState)(false);
|
|
127
|
+
const [error, setError] = (0, import_react8.useState)(null);
|
|
128
|
+
const createPlan = (0, import_react8.useCallback)(
|
|
118
129
|
async (input) => {
|
|
119
130
|
setIsLoading(true);
|
|
120
131
|
setError(null);
|
|
121
132
|
try {
|
|
122
|
-
const { result } = await
|
|
133
|
+
const { result } = await billing.createPlan(input);
|
|
123
134
|
return result.plan;
|
|
124
135
|
} catch (err) {
|
|
125
136
|
const apiError = err instanceof import_client4.FonderieApiError ? err : new import_client4.FonderieApiError("unknown", String(err), 0);
|
|
@@ -129,14 +140,14 @@ function usePlanAdmin(client) {
|
|
|
129
140
|
setIsLoading(false);
|
|
130
141
|
}
|
|
131
142
|
},
|
|
132
|
-
[
|
|
143
|
+
[billing]
|
|
133
144
|
);
|
|
134
|
-
const updatePlan = (0,
|
|
145
|
+
const updatePlan = (0, import_react8.useCallback)(
|
|
135
146
|
async (planId, input) => {
|
|
136
147
|
setIsLoading(true);
|
|
137
148
|
setError(null);
|
|
138
149
|
try {
|
|
139
|
-
const { result } = await
|
|
150
|
+
const { result } = await billing.updatePlan(planId, input);
|
|
140
151
|
return result.plan;
|
|
141
152
|
} catch (err) {
|
|
142
153
|
const apiError = err instanceof import_client4.FonderieApiError ? err : new import_client4.FonderieApiError("unknown", String(err), 0);
|
|
@@ -146,14 +157,14 @@ function usePlanAdmin(client) {
|
|
|
146
157
|
setIsLoading(false);
|
|
147
158
|
}
|
|
148
159
|
},
|
|
149
|
-
[
|
|
160
|
+
[billing]
|
|
150
161
|
);
|
|
151
|
-
const deletePlan = (0,
|
|
162
|
+
const deletePlan = (0, import_react8.useCallback)(
|
|
152
163
|
async (planId) => {
|
|
153
164
|
setIsLoading(true);
|
|
154
165
|
setError(null);
|
|
155
166
|
try {
|
|
156
|
-
await
|
|
167
|
+
await billing.deletePlan(planId);
|
|
157
168
|
} catch (err) {
|
|
158
169
|
const apiError = err instanceof import_client4.FonderieApiError ? err : new import_client4.FonderieApiError("unknown", String(err), 0);
|
|
159
170
|
setError(apiError);
|
|
@@ -162,23 +173,25 @@ function usePlanAdmin(client) {
|
|
|
162
173
|
setIsLoading(false);
|
|
163
174
|
}
|
|
164
175
|
},
|
|
165
|
-
[
|
|
176
|
+
[billing]
|
|
166
177
|
);
|
|
167
178
|
return { createPlan, updatePlan, deletePlan, isLoading, error };
|
|
168
179
|
}
|
|
169
180
|
|
|
170
181
|
// src/hooks/usePlans.ts
|
|
171
182
|
var import_client5 = require("@fonderie/client");
|
|
172
|
-
var
|
|
183
|
+
var import_react9 = require("@fonderie/react");
|
|
184
|
+
var import_react10 = require("react");
|
|
173
185
|
function usePlans(client) {
|
|
174
|
-
const
|
|
175
|
-
const [
|
|
176
|
-
const [
|
|
177
|
-
const
|
|
186
|
+
const billing = (0, import_react9.useFonderieSubClient)(client, (c) => c.billing, "usePlans");
|
|
187
|
+
const [plans, setPlans] = (0, import_react10.useState)([]);
|
|
188
|
+
const [isLoading, setIsLoading] = (0, import_react10.useState)(true);
|
|
189
|
+
const [error, setError] = (0, import_react10.useState)(null);
|
|
190
|
+
const refresh = (0, import_react10.useCallback)(async () => {
|
|
178
191
|
setIsLoading(true);
|
|
179
192
|
setError(null);
|
|
180
193
|
try {
|
|
181
|
-
const { result } = await
|
|
194
|
+
const { result } = await billing.listPlans();
|
|
182
195
|
setPlans(result.plans);
|
|
183
196
|
} catch (err) {
|
|
184
197
|
const apiError = err instanceof import_client5.FonderieApiError ? err : new import_client5.FonderieApiError("unknown", String(err), 0);
|
|
@@ -186,8 +199,8 @@ function usePlans(client) {
|
|
|
186
199
|
} finally {
|
|
187
200
|
setIsLoading(false);
|
|
188
201
|
}
|
|
189
|
-
}, [
|
|
190
|
-
(0,
|
|
202
|
+
}, [billing]);
|
|
203
|
+
(0, import_react10.useEffect)(() => {
|
|
191
204
|
void refresh();
|
|
192
205
|
}, [refresh]);
|
|
193
206
|
return { plans, isLoading, error, refresh };
|
|
@@ -195,16 +208,18 @@ function usePlans(client) {
|
|
|
195
208
|
|
|
196
209
|
// src/hooks/useRecordUsage.ts
|
|
197
210
|
var import_client6 = require("@fonderie/client");
|
|
198
|
-
var
|
|
211
|
+
var import_react11 = require("@fonderie/react");
|
|
212
|
+
var import_react12 = require("react");
|
|
199
213
|
function useRecordUsage(client) {
|
|
200
|
-
const
|
|
201
|
-
const [
|
|
202
|
-
const
|
|
214
|
+
const billing = (0, import_react11.useFonderieSubClient)(client, (c) => c.billing, "useRecordUsage");
|
|
215
|
+
const [isLoading, setIsLoading] = (0, import_react12.useState)(false);
|
|
216
|
+
const [error, setError] = (0, import_react12.useState)(null);
|
|
217
|
+
const recordUsage = (0, import_react12.useCallback)(
|
|
203
218
|
async (input) => {
|
|
204
219
|
setIsLoading(true);
|
|
205
220
|
setError(null);
|
|
206
221
|
try {
|
|
207
|
-
await
|
|
222
|
+
await billing.recordUsage(input);
|
|
208
223
|
} catch (err) {
|
|
209
224
|
const apiError = err instanceof import_client6.FonderieApiError ? err : new import_client6.FonderieApiError("unknown", String(err), 0);
|
|
210
225
|
setError(apiError);
|
|
@@ -213,23 +228,25 @@ function useRecordUsage(client) {
|
|
|
213
228
|
setIsLoading(false);
|
|
214
229
|
}
|
|
215
230
|
},
|
|
216
|
-
[
|
|
231
|
+
[billing]
|
|
217
232
|
);
|
|
218
233
|
return { recordUsage, isLoading, error };
|
|
219
234
|
}
|
|
220
235
|
|
|
221
236
|
// src/hooks/useSubscription.ts
|
|
222
237
|
var import_client7 = require("@fonderie/client");
|
|
223
|
-
var
|
|
238
|
+
var import_react13 = require("@fonderie/react");
|
|
239
|
+
var import_react14 = require("react");
|
|
224
240
|
function useSubscription(client) {
|
|
225
|
-
const
|
|
226
|
-
const [
|
|
227
|
-
const [
|
|
228
|
-
const
|
|
241
|
+
const billing = (0, import_react13.useFonderieSubClient)(client, (c) => c.billing, "useSubscription");
|
|
242
|
+
const [subscription, setSubscription] = (0, import_react14.useState)(null);
|
|
243
|
+
const [isLoading, setIsLoading] = (0, import_react14.useState)(true);
|
|
244
|
+
const [error, setError] = (0, import_react14.useState)(null);
|
|
245
|
+
const refresh = (0, import_react14.useCallback)(async () => {
|
|
229
246
|
setIsLoading(true);
|
|
230
247
|
setError(null);
|
|
231
248
|
try {
|
|
232
|
-
const { result } = await
|
|
249
|
+
const { result } = await billing.getSubscription();
|
|
233
250
|
setSubscription(result.subscription);
|
|
234
251
|
} catch (err) {
|
|
235
252
|
const apiError = err instanceof import_client7.FonderieApiError ? err : new import_client7.FonderieApiError("unknown", String(err), 0);
|
|
@@ -238,8 +255,8 @@ function useSubscription(client) {
|
|
|
238
255
|
} finally {
|
|
239
256
|
setIsLoading(false);
|
|
240
257
|
}
|
|
241
|
-
}, [
|
|
242
|
-
(0,
|
|
258
|
+
}, [billing]);
|
|
259
|
+
(0, import_react14.useEffect)(() => {
|
|
243
260
|
void refresh();
|
|
244
261
|
}, [refresh]);
|
|
245
262
|
return { subscription, isLoading, error, refresh };
|
|
@@ -247,16 +264,21 @@ function useSubscription(client) {
|
|
|
247
264
|
|
|
248
265
|
// src/hooks/useUsage.ts
|
|
249
266
|
var import_client8 = require("@fonderie/client");
|
|
250
|
-
var
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
const
|
|
254
|
-
const
|
|
255
|
-
const
|
|
267
|
+
var import_react15 = require("@fonderie/react");
|
|
268
|
+
var import_react16 = require("react");
|
|
269
|
+
function useUsage(clientOrMetric, maybeMetric) {
|
|
270
|
+
const firstIsClient = clientOrMetric === void 0 || clientOrMetric instanceof import_client8.BillingClient;
|
|
271
|
+
const explicit = firstIsClient ? clientOrMetric : void 0;
|
|
272
|
+
const metric = firstIsClient ? maybeMetric : clientOrMetric;
|
|
273
|
+
const billing = (0, import_react15.useFonderieSubClient)(explicit, (c) => c.billing, "useUsage");
|
|
274
|
+
const [total, setTotal] = (0, import_react16.useState)(null);
|
|
275
|
+
const [isLoading, setIsLoading] = (0, import_react16.useState)(true);
|
|
276
|
+
const [error, setError] = (0, import_react16.useState)(null);
|
|
277
|
+
const refresh = (0, import_react16.useCallback)(async () => {
|
|
256
278
|
setIsLoading(true);
|
|
257
279
|
setError(null);
|
|
258
280
|
try {
|
|
259
|
-
const { result } = await
|
|
281
|
+
const { result } = await billing.getUsage(metric);
|
|
260
282
|
setTotal(result.total);
|
|
261
283
|
} catch (err) {
|
|
262
284
|
const apiError = err instanceof import_client8.FonderieApiError ? err : new import_client8.FonderieApiError("unknown", String(err), 0);
|
|
@@ -264,8 +286,8 @@ function useUsage(client, metric) {
|
|
|
264
286
|
} finally {
|
|
265
287
|
setIsLoading(false);
|
|
266
288
|
}
|
|
267
|
-
}, [
|
|
268
|
-
(0,
|
|
289
|
+
}, [billing, metric]);
|
|
290
|
+
(0, import_react16.useEffect)(() => {
|
|
269
291
|
void refresh();
|
|
270
292
|
}, [refresh]);
|
|
271
293
|
return { total, isLoading, error, refresh };
|
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,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ChD,sBAAgB,OAAO,YAAY;AAAA,IACpC,SAAS,KAAK;AACb,YAAM,WACL,eAAe,kCAAmB,MAAM,IAAI,gCAAiB,WAAW,OAAO,GAAG,GAAG,CAAC;AAEvF,UAAI,SAAS,WAAW,IAAK,UAAS,QAAQ;AAC9C,sBAAgB,IAAI;AAAA,IACrB,UAAE;AACD,mBAAa,KAAK;AAAA,IACnB;AAAA,EACD,GAAG,CAAC,MAAM,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: () => 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(async () => {\n\t\tsetIsLoading(true);\n\t\tsetError(null);\n\t\ttry {\n\t\t\tconst { result } = await billing.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}, [billing, 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 { useFonderieSubClient } from '@fonderie/react';\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 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 { BillingClient, IPlanDTO } 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: () => 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(async () => {\n\t\tsetIsLoading(true);\n\t\tsetError(null);\n\t\ttry {\n\t\t\tconst { result } = await billing.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}, [billing]);\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 { useFonderieSubClient } from '@fonderie/react';\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 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: () => 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(async () => {\n\t\tsetIsLoading(true);\n\t\tsetError(null);\n\t\ttry {\n\t\t\tconst { result } = await billing.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}, [billing]);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { subscription, isLoading, error, refresh };\n}\n","import { 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: () => 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(async () => {\n\t\tsetIsLoading(true);\n\t\tsetError(null);\n\t\ttry {\n\t\t\tconst { result } = await billing.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}, [billing, 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,mBAAqC;AACrC,IAAAC,gBAAsC;AAQ/B,SAAS,iBAAiB,QAAiD;AACjF,QAAM,cAAU,mCAAqB,QAAQ,CAAC,MAAM,EAAE,SAAS,kBAAkB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AqB,UAAU,CAAC,MAAM,EAAE,SAAS,UAAU;AAC3E,QAAM,CAAC,OAAO,QAAQ,QAAI,yBAAwB,IAAI;AACtD,QAAM,CAAC,WAAW,YAAY,QAAI,yBAAS,IAAI;AAC/C,QAAM,CAAC,OAAO,QAAQ,QAAI,yBAAkC,IAAI;AAEhE,QAAM,cAAU,4BAAY,YAAY;AACvC,iBAAa,IAAI;AACjB,aAAS,IAAI;AACb,QAAI;AACH,YAAM,EAAE,OAAO,IAAI,MAAM,QAAQ,SAAS,MAAM;AAChD,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,SAAS,MAAM,CAAC;AAEpB,gCAAU,MAAM;AACf,SAAK,QAAQ;AAAA,EACd,GAAG,CAAC,OAAO,CAAC;AAEZ,SAAO,EAAE,OAAO,WAAW,OAAO,QAAQ;AAC3C;","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"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -6,14 +6,14 @@ interface IUseBillingPortalReturn {
|
|
|
6
6
|
isLoading: boolean;
|
|
7
7
|
error: FonderieApiError | null;
|
|
8
8
|
}
|
|
9
|
-
declare function useBillingPortal(client
|
|
9
|
+
declare function useBillingPortal(client?: BillingClient): IUseBillingPortalReturn;
|
|
10
10
|
|
|
11
11
|
interface IUseCheckoutReturn {
|
|
12
12
|
checkout: (input: ICheckoutInput) => Promise<string>;
|
|
13
13
|
isLoading: boolean;
|
|
14
14
|
error: FonderieApiError | null;
|
|
15
15
|
}
|
|
16
|
-
declare function useCheckout(client
|
|
16
|
+
declare function useCheckout(client?: BillingClient): IUseCheckoutReturn;
|
|
17
17
|
|
|
18
18
|
interface IUsePlanReturn {
|
|
19
19
|
plan: IPlanDTO | null;
|
|
@@ -21,7 +21,8 @@ interface IUsePlanReturn {
|
|
|
21
21
|
error: FonderieApiError | null;
|
|
22
22
|
refresh: () => Promise<void>;
|
|
23
23
|
}
|
|
24
|
-
declare function usePlan(
|
|
24
|
+
declare function usePlan(planId: string): IUsePlanReturn;
|
|
25
|
+
declare function usePlan(client: BillingClient | undefined, planId: string): IUsePlanReturn;
|
|
25
26
|
|
|
26
27
|
interface IUsePlanAdminReturn {
|
|
27
28
|
createPlan: (input: ICreatePlanInput) => Promise<IPlanDTO>;
|
|
@@ -30,7 +31,7 @@ interface IUsePlanAdminReturn {
|
|
|
30
31
|
isLoading: boolean;
|
|
31
32
|
error: FonderieApiError | null;
|
|
32
33
|
}
|
|
33
|
-
declare function usePlanAdmin(client
|
|
34
|
+
declare function usePlanAdmin(client?: BillingClient): IUsePlanAdminReturn;
|
|
34
35
|
|
|
35
36
|
interface IUsePlansReturn {
|
|
36
37
|
plans: IPlanDTO[];
|
|
@@ -38,14 +39,14 @@ interface IUsePlansReturn {
|
|
|
38
39
|
error: FonderieApiError | null;
|
|
39
40
|
refresh: () => Promise<void>;
|
|
40
41
|
}
|
|
41
|
-
declare function usePlans(client
|
|
42
|
+
declare function usePlans(client?: BillingClient): IUsePlansReturn;
|
|
42
43
|
|
|
43
44
|
interface IUseRecordUsageReturn {
|
|
44
45
|
recordUsage: (input: IRecordUsageInput) => Promise<void>;
|
|
45
46
|
isLoading: boolean;
|
|
46
47
|
error: FonderieApiError | null;
|
|
47
48
|
}
|
|
48
|
-
declare function useRecordUsage(client
|
|
49
|
+
declare function useRecordUsage(client?: BillingClient): IUseRecordUsageReturn;
|
|
49
50
|
|
|
50
51
|
interface IUseSubscriptionReturn {
|
|
51
52
|
subscription: ISubscriptionDTO | null;
|
|
@@ -53,7 +54,7 @@ interface IUseSubscriptionReturn {
|
|
|
53
54
|
error: FonderieApiError | null;
|
|
54
55
|
refresh: () => Promise<void>;
|
|
55
56
|
}
|
|
56
|
-
declare function useSubscription(client
|
|
57
|
+
declare function useSubscription(client?: BillingClient): IUseSubscriptionReturn;
|
|
57
58
|
|
|
58
59
|
interface IUseUsageReturn {
|
|
59
60
|
total: number | null;
|
|
@@ -61,6 +62,7 @@ interface IUseUsageReturn {
|
|
|
61
62
|
error: FonderieApiError | null;
|
|
62
63
|
refresh: () => Promise<void>;
|
|
63
64
|
}
|
|
64
|
-
declare function useUsage(
|
|
65
|
+
declare function useUsage(metric: string): IUseUsageReturn;
|
|
66
|
+
declare function useUsage(client: BillingClient | undefined, metric: string): IUseUsageReturn;
|
|
65
67
|
|
|
66
68
|
export { type IUseBillingPortalReturn, type IUseCheckoutReturn, type IUsePlanAdminReturn, type IUsePlanReturn, type IUsePlansReturn, type IUseRecordUsageReturn, type IUseSubscriptionReturn, type IUseUsageReturn, useBillingPortal, useCheckout, usePlan, usePlanAdmin, usePlans, useRecordUsage, useSubscription, useUsage };
|
package/dist/index.d.ts
CHANGED
|
@@ -6,14 +6,14 @@ interface IUseBillingPortalReturn {
|
|
|
6
6
|
isLoading: boolean;
|
|
7
7
|
error: FonderieApiError | null;
|
|
8
8
|
}
|
|
9
|
-
declare function useBillingPortal(client
|
|
9
|
+
declare function useBillingPortal(client?: BillingClient): IUseBillingPortalReturn;
|
|
10
10
|
|
|
11
11
|
interface IUseCheckoutReturn {
|
|
12
12
|
checkout: (input: ICheckoutInput) => Promise<string>;
|
|
13
13
|
isLoading: boolean;
|
|
14
14
|
error: FonderieApiError | null;
|
|
15
15
|
}
|
|
16
|
-
declare function useCheckout(client
|
|
16
|
+
declare function useCheckout(client?: BillingClient): IUseCheckoutReturn;
|
|
17
17
|
|
|
18
18
|
interface IUsePlanReturn {
|
|
19
19
|
plan: IPlanDTO | null;
|
|
@@ -21,7 +21,8 @@ interface IUsePlanReturn {
|
|
|
21
21
|
error: FonderieApiError | null;
|
|
22
22
|
refresh: () => Promise<void>;
|
|
23
23
|
}
|
|
24
|
-
declare function usePlan(
|
|
24
|
+
declare function usePlan(planId: string): IUsePlanReturn;
|
|
25
|
+
declare function usePlan(client: BillingClient | undefined, planId: string): IUsePlanReturn;
|
|
25
26
|
|
|
26
27
|
interface IUsePlanAdminReturn {
|
|
27
28
|
createPlan: (input: ICreatePlanInput) => Promise<IPlanDTO>;
|
|
@@ -30,7 +31,7 @@ interface IUsePlanAdminReturn {
|
|
|
30
31
|
isLoading: boolean;
|
|
31
32
|
error: FonderieApiError | null;
|
|
32
33
|
}
|
|
33
|
-
declare function usePlanAdmin(client
|
|
34
|
+
declare function usePlanAdmin(client?: BillingClient): IUsePlanAdminReturn;
|
|
34
35
|
|
|
35
36
|
interface IUsePlansReturn {
|
|
36
37
|
plans: IPlanDTO[];
|
|
@@ -38,14 +39,14 @@ interface IUsePlansReturn {
|
|
|
38
39
|
error: FonderieApiError | null;
|
|
39
40
|
refresh: () => Promise<void>;
|
|
40
41
|
}
|
|
41
|
-
declare function usePlans(client
|
|
42
|
+
declare function usePlans(client?: BillingClient): IUsePlansReturn;
|
|
42
43
|
|
|
43
44
|
interface IUseRecordUsageReturn {
|
|
44
45
|
recordUsage: (input: IRecordUsageInput) => Promise<void>;
|
|
45
46
|
isLoading: boolean;
|
|
46
47
|
error: FonderieApiError | null;
|
|
47
48
|
}
|
|
48
|
-
declare function useRecordUsage(client
|
|
49
|
+
declare function useRecordUsage(client?: BillingClient): IUseRecordUsageReturn;
|
|
49
50
|
|
|
50
51
|
interface IUseSubscriptionReturn {
|
|
51
52
|
subscription: ISubscriptionDTO | null;
|
|
@@ -53,7 +54,7 @@ interface IUseSubscriptionReturn {
|
|
|
53
54
|
error: FonderieApiError | null;
|
|
54
55
|
refresh: () => Promise<void>;
|
|
55
56
|
}
|
|
56
|
-
declare function useSubscription(client
|
|
57
|
+
declare function useSubscription(client?: BillingClient): IUseSubscriptionReturn;
|
|
57
58
|
|
|
58
59
|
interface IUseUsageReturn {
|
|
59
60
|
total: number | null;
|
|
@@ -61,6 +62,7 @@ interface IUseUsageReturn {
|
|
|
61
62
|
error: FonderieApiError | null;
|
|
62
63
|
refresh: () => Promise<void>;
|
|
63
64
|
}
|
|
64
|
-
declare function useUsage(
|
|
65
|
+
declare function useUsage(metric: string): IUseUsageReturn;
|
|
66
|
+
declare function useUsage(client: BillingClient | undefined, metric: string): IUseUsageReturn;
|
|
65
67
|
|
|
66
68
|
export { type IUseBillingPortalReturn, type IUseCheckoutReturn, type IUsePlanAdminReturn, type IUsePlanReturn, type IUsePlansReturn, type IUseRecordUsageReturn, type IUseSubscriptionReturn, type IUseUsageReturn, useBillingPortal, useCheckout, usePlan, usePlanAdmin, usePlans, useRecordUsage, useSubscription, useUsage };
|
package/dist/index.js
CHANGED
|
@@ -3,15 +3,17 @@ import { FonderieApiError as FonderieApiError9 } from "@fonderie/client";
|
|
|
3
3
|
|
|
4
4
|
// src/hooks/useBillingPortal.ts
|
|
5
5
|
import { FonderieApiError } from "@fonderie/client";
|
|
6
|
+
import { useFonderieSubClient } from "@fonderie/react";
|
|
6
7
|
import { useCallback, useState } from "react";
|
|
7
8
|
function useBillingPortal(client) {
|
|
9
|
+
const billing = useFonderieSubClient(client, (c) => c.billing, "useBillingPortal");
|
|
8
10
|
const [isLoading, setIsLoading] = useState(false);
|
|
9
11
|
const [error, setError] = useState(null);
|
|
10
12
|
const openPortal = useCallback(async () => {
|
|
11
13
|
setIsLoading(true);
|
|
12
14
|
setError(null);
|
|
13
15
|
try {
|
|
14
|
-
const { result } = await
|
|
16
|
+
const { result } = await billing.createPortalSession();
|
|
15
17
|
return result.url;
|
|
16
18
|
} catch (err) {
|
|
17
19
|
const apiError = err instanceof FonderieApiError ? err : new FonderieApiError("unknown", String(err), 0);
|
|
@@ -20,14 +22,16 @@ function useBillingPortal(client) {
|
|
|
20
22
|
} finally {
|
|
21
23
|
setIsLoading(false);
|
|
22
24
|
}
|
|
23
|
-
}, [
|
|
25
|
+
}, [billing]);
|
|
24
26
|
return { openPortal, isLoading, error };
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
// src/hooks/useCheckout.ts
|
|
28
30
|
import { FonderieApiError as FonderieApiError2 } from "@fonderie/client";
|
|
31
|
+
import { useFonderieSubClient as useFonderieSubClient2 } from "@fonderie/react";
|
|
29
32
|
import { useCallback as useCallback2, useState as useState2 } from "react";
|
|
30
33
|
function useCheckout(client) {
|
|
34
|
+
const billing = useFonderieSubClient2(client, (c) => c.billing, "useCheckout");
|
|
31
35
|
const [isLoading, setIsLoading] = useState2(false);
|
|
32
36
|
const [error, setError] = useState2(null);
|
|
33
37
|
const checkout = useCallback2(
|
|
@@ -35,7 +39,7 @@ function useCheckout(client) {
|
|
|
35
39
|
setIsLoading(true);
|
|
36
40
|
setError(null);
|
|
37
41
|
try {
|
|
38
|
-
const { result } = await
|
|
42
|
+
const { result } = await billing.createCheckoutSession(input);
|
|
39
43
|
return result.url;
|
|
40
44
|
} catch (err) {
|
|
41
45
|
const apiError = err instanceof FonderieApiError2 ? err : new FonderieApiError2("unknown", String(err), 0);
|
|
@@ -45,15 +49,20 @@ function useCheckout(client) {
|
|
|
45
49
|
setIsLoading(false);
|
|
46
50
|
}
|
|
47
51
|
},
|
|
48
|
-
[
|
|
52
|
+
[billing]
|
|
49
53
|
);
|
|
50
54
|
return { checkout, isLoading, error };
|
|
51
55
|
}
|
|
52
56
|
|
|
53
57
|
// src/hooks/usePlan.ts
|
|
54
|
-
import { FonderieApiError as FonderieApiError3 } from "@fonderie/client";
|
|
58
|
+
import { BillingClient, FonderieApiError as FonderieApiError3 } from "@fonderie/client";
|
|
59
|
+
import { useFonderieSubClient as useFonderieSubClient3 } from "@fonderie/react";
|
|
55
60
|
import { useCallback as useCallback3, useEffect, useState as useState3 } from "react";
|
|
56
|
-
function usePlan(
|
|
61
|
+
function usePlan(clientOrPlanId, maybePlanId) {
|
|
62
|
+
const firstIsClient = clientOrPlanId === void 0 || clientOrPlanId instanceof BillingClient;
|
|
63
|
+
const explicit = firstIsClient ? clientOrPlanId : void 0;
|
|
64
|
+
const planId = firstIsClient ? maybePlanId : clientOrPlanId;
|
|
65
|
+
const billing = useFonderieSubClient3(explicit, (c) => c.billing, "usePlan");
|
|
57
66
|
const [plan, setPlan] = useState3(null);
|
|
58
67
|
const [isLoading, setIsLoading] = useState3(true);
|
|
59
68
|
const [error, setError] = useState3(null);
|
|
@@ -61,7 +70,7 @@ function usePlan(client, planId) {
|
|
|
61
70
|
setIsLoading(true);
|
|
62
71
|
setError(null);
|
|
63
72
|
try {
|
|
64
|
-
const { result } = await
|
|
73
|
+
const { result } = await billing.getPlan(planId);
|
|
65
74
|
setPlan(result.plan);
|
|
66
75
|
} catch (err) {
|
|
67
76
|
const apiError = err instanceof FonderieApiError3 ? err : new FonderieApiError3("unknown", String(err), 0);
|
|
@@ -69,7 +78,7 @@ function usePlan(client, planId) {
|
|
|
69
78
|
} finally {
|
|
70
79
|
setIsLoading(false);
|
|
71
80
|
}
|
|
72
|
-
}, [
|
|
81
|
+
}, [billing, planId]);
|
|
73
82
|
useEffect(() => {
|
|
74
83
|
void refresh();
|
|
75
84
|
}, [refresh]);
|
|
@@ -78,8 +87,10 @@ function usePlan(client, planId) {
|
|
|
78
87
|
|
|
79
88
|
// src/hooks/usePlanAdmin.ts
|
|
80
89
|
import { FonderieApiError as FonderieApiError4 } from "@fonderie/client";
|
|
90
|
+
import { useFonderieSubClient as useFonderieSubClient4 } from "@fonderie/react";
|
|
81
91
|
import { useCallback as useCallback4, useState as useState4 } from "react";
|
|
82
92
|
function usePlanAdmin(client) {
|
|
93
|
+
const billing = useFonderieSubClient4(client, (c) => c.billing, "usePlanAdmin");
|
|
83
94
|
const [isLoading, setIsLoading] = useState4(false);
|
|
84
95
|
const [error, setError] = useState4(null);
|
|
85
96
|
const createPlan = useCallback4(
|
|
@@ -87,7 +98,7 @@ function usePlanAdmin(client) {
|
|
|
87
98
|
setIsLoading(true);
|
|
88
99
|
setError(null);
|
|
89
100
|
try {
|
|
90
|
-
const { result } = await
|
|
101
|
+
const { result } = await billing.createPlan(input);
|
|
91
102
|
return result.plan;
|
|
92
103
|
} catch (err) {
|
|
93
104
|
const apiError = err instanceof FonderieApiError4 ? err : new FonderieApiError4("unknown", String(err), 0);
|
|
@@ -97,14 +108,14 @@ function usePlanAdmin(client) {
|
|
|
97
108
|
setIsLoading(false);
|
|
98
109
|
}
|
|
99
110
|
},
|
|
100
|
-
[
|
|
111
|
+
[billing]
|
|
101
112
|
);
|
|
102
113
|
const updatePlan = useCallback4(
|
|
103
114
|
async (planId, input) => {
|
|
104
115
|
setIsLoading(true);
|
|
105
116
|
setError(null);
|
|
106
117
|
try {
|
|
107
|
-
const { result } = await
|
|
118
|
+
const { result } = await billing.updatePlan(planId, input);
|
|
108
119
|
return result.plan;
|
|
109
120
|
} catch (err) {
|
|
110
121
|
const apiError = err instanceof FonderieApiError4 ? err : new FonderieApiError4("unknown", String(err), 0);
|
|
@@ -114,14 +125,14 @@ function usePlanAdmin(client) {
|
|
|
114
125
|
setIsLoading(false);
|
|
115
126
|
}
|
|
116
127
|
},
|
|
117
|
-
[
|
|
128
|
+
[billing]
|
|
118
129
|
);
|
|
119
130
|
const deletePlan = useCallback4(
|
|
120
131
|
async (planId) => {
|
|
121
132
|
setIsLoading(true);
|
|
122
133
|
setError(null);
|
|
123
134
|
try {
|
|
124
|
-
await
|
|
135
|
+
await billing.deletePlan(planId);
|
|
125
136
|
} catch (err) {
|
|
126
137
|
const apiError = err instanceof FonderieApiError4 ? err : new FonderieApiError4("unknown", String(err), 0);
|
|
127
138
|
setError(apiError);
|
|
@@ -130,15 +141,17 @@ function usePlanAdmin(client) {
|
|
|
130
141
|
setIsLoading(false);
|
|
131
142
|
}
|
|
132
143
|
},
|
|
133
|
-
[
|
|
144
|
+
[billing]
|
|
134
145
|
);
|
|
135
146
|
return { createPlan, updatePlan, deletePlan, isLoading, error };
|
|
136
147
|
}
|
|
137
148
|
|
|
138
149
|
// src/hooks/usePlans.ts
|
|
139
150
|
import { FonderieApiError as FonderieApiError5 } from "@fonderie/client";
|
|
151
|
+
import { useFonderieSubClient as useFonderieSubClient5 } from "@fonderie/react";
|
|
140
152
|
import { useCallback as useCallback5, useEffect as useEffect2, useState as useState5 } from "react";
|
|
141
153
|
function usePlans(client) {
|
|
154
|
+
const billing = useFonderieSubClient5(client, (c) => c.billing, "usePlans");
|
|
142
155
|
const [plans, setPlans] = useState5([]);
|
|
143
156
|
const [isLoading, setIsLoading] = useState5(true);
|
|
144
157
|
const [error, setError] = useState5(null);
|
|
@@ -146,7 +159,7 @@ function usePlans(client) {
|
|
|
146
159
|
setIsLoading(true);
|
|
147
160
|
setError(null);
|
|
148
161
|
try {
|
|
149
|
-
const { result } = await
|
|
162
|
+
const { result } = await billing.listPlans();
|
|
150
163
|
setPlans(result.plans);
|
|
151
164
|
} catch (err) {
|
|
152
165
|
const apiError = err instanceof FonderieApiError5 ? err : new FonderieApiError5("unknown", String(err), 0);
|
|
@@ -154,7 +167,7 @@ function usePlans(client) {
|
|
|
154
167
|
} finally {
|
|
155
168
|
setIsLoading(false);
|
|
156
169
|
}
|
|
157
|
-
}, [
|
|
170
|
+
}, [billing]);
|
|
158
171
|
useEffect2(() => {
|
|
159
172
|
void refresh();
|
|
160
173
|
}, [refresh]);
|
|
@@ -163,8 +176,10 @@ function usePlans(client) {
|
|
|
163
176
|
|
|
164
177
|
// src/hooks/useRecordUsage.ts
|
|
165
178
|
import { FonderieApiError as FonderieApiError6 } from "@fonderie/client";
|
|
179
|
+
import { useFonderieSubClient as useFonderieSubClient6 } from "@fonderie/react";
|
|
166
180
|
import { useCallback as useCallback6, useState as useState6 } from "react";
|
|
167
181
|
function useRecordUsage(client) {
|
|
182
|
+
const billing = useFonderieSubClient6(client, (c) => c.billing, "useRecordUsage");
|
|
168
183
|
const [isLoading, setIsLoading] = useState6(false);
|
|
169
184
|
const [error, setError] = useState6(null);
|
|
170
185
|
const recordUsage = useCallback6(
|
|
@@ -172,7 +187,7 @@ function useRecordUsage(client) {
|
|
|
172
187
|
setIsLoading(true);
|
|
173
188
|
setError(null);
|
|
174
189
|
try {
|
|
175
|
-
await
|
|
190
|
+
await billing.recordUsage(input);
|
|
176
191
|
} catch (err) {
|
|
177
192
|
const apiError = err instanceof FonderieApiError6 ? err : new FonderieApiError6("unknown", String(err), 0);
|
|
178
193
|
setError(apiError);
|
|
@@ -181,15 +196,17 @@ function useRecordUsage(client) {
|
|
|
181
196
|
setIsLoading(false);
|
|
182
197
|
}
|
|
183
198
|
},
|
|
184
|
-
[
|
|
199
|
+
[billing]
|
|
185
200
|
);
|
|
186
201
|
return { recordUsage, isLoading, error };
|
|
187
202
|
}
|
|
188
203
|
|
|
189
204
|
// src/hooks/useSubscription.ts
|
|
190
205
|
import { FonderieApiError as FonderieApiError7 } from "@fonderie/client";
|
|
206
|
+
import { useFonderieSubClient as useFonderieSubClient7 } from "@fonderie/react";
|
|
191
207
|
import { useCallback as useCallback7, useEffect as useEffect3, useState as useState7 } from "react";
|
|
192
208
|
function useSubscription(client) {
|
|
209
|
+
const billing = useFonderieSubClient7(client, (c) => c.billing, "useSubscription");
|
|
193
210
|
const [subscription, setSubscription] = useState7(null);
|
|
194
211
|
const [isLoading, setIsLoading] = useState7(true);
|
|
195
212
|
const [error, setError] = useState7(null);
|
|
@@ -197,7 +214,7 @@ function useSubscription(client) {
|
|
|
197
214
|
setIsLoading(true);
|
|
198
215
|
setError(null);
|
|
199
216
|
try {
|
|
200
|
-
const { result } = await
|
|
217
|
+
const { result } = await billing.getSubscription();
|
|
201
218
|
setSubscription(result.subscription);
|
|
202
219
|
} catch (err) {
|
|
203
220
|
const apiError = err instanceof FonderieApiError7 ? err : new FonderieApiError7("unknown", String(err), 0);
|
|
@@ -206,7 +223,7 @@ function useSubscription(client) {
|
|
|
206
223
|
} finally {
|
|
207
224
|
setIsLoading(false);
|
|
208
225
|
}
|
|
209
|
-
}, [
|
|
226
|
+
}, [billing]);
|
|
210
227
|
useEffect3(() => {
|
|
211
228
|
void refresh();
|
|
212
229
|
}, [refresh]);
|
|
@@ -214,9 +231,14 @@ function useSubscription(client) {
|
|
|
214
231
|
}
|
|
215
232
|
|
|
216
233
|
// src/hooks/useUsage.ts
|
|
217
|
-
import { FonderieApiError as FonderieApiError8 } from "@fonderie/client";
|
|
234
|
+
import { BillingClient as BillingClient2, FonderieApiError as FonderieApiError8 } from "@fonderie/client";
|
|
235
|
+
import { useFonderieSubClient as useFonderieSubClient8 } from "@fonderie/react";
|
|
218
236
|
import { useCallback as useCallback8, useEffect as useEffect4, useState as useState8 } from "react";
|
|
219
|
-
function useUsage(
|
|
237
|
+
function useUsage(clientOrMetric, maybeMetric) {
|
|
238
|
+
const firstIsClient = clientOrMetric === void 0 || clientOrMetric instanceof BillingClient2;
|
|
239
|
+
const explicit = firstIsClient ? clientOrMetric : void 0;
|
|
240
|
+
const metric = firstIsClient ? maybeMetric : clientOrMetric;
|
|
241
|
+
const billing = useFonderieSubClient8(explicit, (c) => c.billing, "useUsage");
|
|
220
242
|
const [total, setTotal] = useState8(null);
|
|
221
243
|
const [isLoading, setIsLoading] = useState8(true);
|
|
222
244
|
const [error, setError] = useState8(null);
|
|
@@ -224,7 +246,7 @@ function useUsage(client, metric) {
|
|
|
224
246
|
setIsLoading(true);
|
|
225
247
|
setError(null);
|
|
226
248
|
try {
|
|
227
|
-
const { result } = await
|
|
249
|
+
const { result } = await billing.getUsage(metric);
|
|
228
250
|
setTotal(result.total);
|
|
229
251
|
} catch (err) {
|
|
230
252
|
const apiError = err instanceof FonderieApiError8 ? err : new FonderieApiError8("unknown", String(err), 0);
|
|
@@ -232,7 +254,7 @@ function useUsage(client, metric) {
|
|
|
232
254
|
} finally {
|
|
233
255
|
setIsLoading(false);
|
|
234
256
|
}
|
|
235
|
-
}, [
|
|
257
|
+
}, [billing, metric]);
|
|
236
258
|
useEffect4(() => {
|
|
237
259
|
void refresh();
|
|
238
260
|
}, [refresh]);
|
package/dist/index.js.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":";AAWA,SAAS,oBAAAA,yBAAwB;;;ACVjC,SAAS,wBAAwB;AACjC,SAAS,aAAa,gBAAgB;AAQ/B,SAAS,iBAAiB,QAAgD;AAChF,QAAM,CAAC,WAAW,YAAY,IAAI,SAAS,KAAK;AAChD,QAAM,CAAC,OAAO,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AAC;AAEZ,SAAO,EAAE,OAAO,WAAW,OAAO,QAAQ;AAC3C;","names":["FonderieApiError","FonderieApiError","useCallback","useState","FonderieApiError","useCallback","useState","FonderieApiError","useCallback","useState","FonderieApiError","useCallback","useEffect","useState","FonderieApiError","useCallback","useState","FonderieApiError","useCallback","useEffect","useState","FonderieApiError","useCallback","useEffect","useState"]}
|
|
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: () => 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(async () => {\n\t\tsetIsLoading(true);\n\t\tsetError(null);\n\t\ttry {\n\t\t\tconst { result } = await billing.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}, [billing, 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 { useFonderieSubClient } from '@fonderie/react';\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 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 { BillingClient, IPlanDTO } 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: () => 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(async () => {\n\t\tsetIsLoading(true);\n\t\tsetError(null);\n\t\ttry {\n\t\t\tconst { result } = await billing.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}, [billing]);\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 { useFonderieSubClient } from '@fonderie/react';\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 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: () => 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(async () => {\n\t\tsetIsLoading(true);\n\t\tsetError(null);\n\t\ttry {\n\t\t\tconst { result } = await billing.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}, [billing]);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { subscription, isLoading, error, refresh };\n}\n","import { 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: () => 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(async () => {\n\t\tsetIsLoading(true);\n\t\tsetError(null);\n\t\ttry {\n\t\t\tconst { result } = await billing.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}, [billing, metric]);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { total, isLoading, error, refresh };\n}\n"],"mappings":";AAWA,SAAS,oBAAAA,yBAAw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","useFonderieSubClient","useCallback","useState","FonderieApiError","useFonderieSubClient","useCallback","useState","FonderieApiError","useFonderieSubClient","useCallback","useState","FonderieApiError","useFonderieSubClient","useCallback","useEffect","useState","FonderieApiError","useFonderieSubClient","useCallback","useState","FonderieApiError","useFonderieSubClient","useCallback","useEffect","useState","BillingClient","FonderieApiError","useFonderieSubClient","useCallback","useEffect","useState"]}
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fonderie/react-billing",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "React hooks for Fonderie billing — thin bindings over @fonderie/client.",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"
|
|
6
|
+
"fonderiejs",
|
|
7
7
|
"react",
|
|
8
8
|
"billing",
|
|
9
9
|
"stripe",
|
|
@@ -29,21 +29,25 @@
|
|
|
29
29
|
"build": "tsup",
|
|
30
30
|
"dev": "tsup --watch",
|
|
31
31
|
"typecheck": "tsc --noEmit",
|
|
32
|
+
"test": "tsx --test src/__tests__/*.test.tsx",
|
|
32
33
|
"lint": "biome lint src",
|
|
33
34
|
"format": "biome format --write src",
|
|
34
35
|
"check": "biome check --write src"
|
|
35
36
|
},
|
|
36
37
|
"dependencies": {
|
|
37
|
-
"@fonderie/client": "*"
|
|
38
|
+
"@fonderie/client": "*",
|
|
39
|
+
"@fonderie/react": "*"
|
|
38
40
|
},
|
|
39
41
|
"peerDependencies": {
|
|
40
42
|
"react": ">=18.0.0"
|
|
41
43
|
},
|
|
42
44
|
"devDependencies": {
|
|
43
|
-
"@types/node": "^
|
|
44
|
-
"@types/react": "^
|
|
45
|
-
"react": "^
|
|
45
|
+
"@types/node": "^26.2.0",
|
|
46
|
+
"@types/react": "^19.2.18",
|
|
47
|
+
"react": "^19.2.8",
|
|
48
|
+
"react-dom": "^19.2.8",
|
|
46
49
|
"tsup": "^8.5.1",
|
|
50
|
+
"tsx": "^4.21.0",
|
|
47
51
|
"typescript": "^6.0.3"
|
|
48
52
|
},
|
|
49
53
|
"publishConfig": {
|