@fonderie/react-billing 0.5.0 → 0.6.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/dist/index.cjs CHANGED
@@ -20,17 +20,24 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
- FonderieApiError: () => import_client8.FonderieApiError,
23
+ FonderieApiError: () => import_client15.FonderieApiError,
24
24
  useBillingPortal: () => useBillingPortal,
25
+ useCancelSubscription: () => useCancelSubscription,
25
26
  useCheckout: () => useCheckout,
27
+ useInvoices: () => useInvoices,
28
+ usePaymentMethod: () => usePaymentMethod,
26
29
  usePlan: () => usePlan,
27
30
  usePlans: () => usePlans,
31
+ useReactivateSubscription: () => useReactivateSubscription,
28
32
  useSubscription: () => useSubscription,
29
33
  useUsage: () => useUsage,
30
- useWalletPreferences: () => useWalletPreferences
34
+ useWallet: () => useWallet,
35
+ useWalletCheckout: () => useWalletCheckout,
36
+ useWalletPreferences: () => useWalletPreferences,
37
+ useWalletTransactions: () => useWalletTransactions
31
38
  });
32
39
  module.exports = __toCommonJS(index_exports);
33
- var import_client8 = require("@fonderie/client");
40
+ var import_client15 = require("@fonderie/client");
34
41
 
35
42
  // src/hooks/useBillingPortal.ts
36
43
  var import_client = require("@fonderie/client");
@@ -318,15 +325,253 @@ function useWalletPreferences(client) {
318
325
  }, [refresh]);
319
326
  return { spendPurchased, isLoading, error, refresh, setSpendPurchased };
320
327
  }
328
+
329
+ // src/hooks/useWallet.ts
330
+ var import_client8 = require("@fonderie/client");
331
+ var import_react15 = require("@fonderie/react");
332
+ var import_react16 = require("react");
333
+ function useWallet(client) {
334
+ const billing = (0, import_react15.useFonderieSubClient)(client, (c) => c.billing, "useWallet");
335
+ const [wallet, setWallet] = (0, import_react16.useState)(null);
336
+ const [isLoading, setIsLoading] = (0, import_react16.useState)(true);
337
+ const [error, setError] = (0, import_react16.useState)(null);
338
+ const refresh = (0, import_react16.useCallback)(
339
+ async (opts) => {
340
+ setIsLoading(true);
341
+ setError(null);
342
+ try {
343
+ const { result } = await billing.getWallet({ bust: opts?.force });
344
+ setWallet(result.wallet);
345
+ } catch (err) {
346
+ const apiError = err instanceof import_client8.FonderieApiError ? err : new import_client8.FonderieApiError("unknown", String(err), 0);
347
+ setError(apiError);
348
+ setWallet(null);
349
+ } finally {
350
+ setIsLoading(false);
351
+ }
352
+ },
353
+ [billing]
354
+ );
355
+ (0, import_react16.useEffect)(() => {
356
+ void refresh();
357
+ }, [refresh]);
358
+ return { wallet, isLoading, error, refresh };
359
+ }
360
+
361
+ // src/hooks/useWalletTransactions.ts
362
+ var import_client9 = require("@fonderie/client");
363
+ var import_react17 = require("@fonderie/react");
364
+ var import_react18 = require("react");
365
+ function useWalletTransactions(client) {
366
+ const billing = (0, import_react17.useFonderieSubClient)(client, (c) => c.billing, "useWalletTransactions");
367
+ const [transactions, setTransactions] = (0, import_react18.useState)([]);
368
+ const [nextCursor, setNextCursor] = (0, import_react18.useState)(null);
369
+ const [isLoading, setIsLoading] = (0, import_react18.useState)(true);
370
+ const [error, setError] = (0, import_react18.useState)(null);
371
+ const refresh = (0, import_react18.useCallback)(
372
+ async (opts) => {
373
+ setIsLoading(true);
374
+ setError(null);
375
+ try {
376
+ const { result } = await billing.getWalletTransactions({ bust: opts?.force });
377
+ setTransactions(result.transactions);
378
+ setNextCursor(result.nextCursor);
379
+ } catch (err) {
380
+ const apiError = err instanceof import_client9.FonderieApiError ? err : new import_client9.FonderieApiError("unknown", String(err), 0);
381
+ setError(apiError);
382
+ } finally {
383
+ setIsLoading(false);
384
+ }
385
+ },
386
+ [billing]
387
+ );
388
+ const loadMore = (0, import_react18.useCallback)(async () => {
389
+ if (!nextCursor) return;
390
+ setError(null);
391
+ try {
392
+ const { result } = await billing.getWalletTransactions({ cursor: nextCursor });
393
+ setTransactions((prev) => [...prev, ...result.transactions]);
394
+ setNextCursor(result.nextCursor);
395
+ } catch (err) {
396
+ const apiError = err instanceof import_client9.FonderieApiError ? err : new import_client9.FonderieApiError("unknown", String(err), 0);
397
+ setError(apiError);
398
+ throw apiError;
399
+ }
400
+ }, [billing, nextCursor]);
401
+ (0, import_react18.useEffect)(() => {
402
+ void refresh();
403
+ }, [refresh]);
404
+ return {
405
+ transactions,
406
+ nextCursor,
407
+ hasMore: nextCursor !== null,
408
+ isLoading,
409
+ error,
410
+ refresh,
411
+ loadMore
412
+ };
413
+ }
414
+
415
+ // src/hooks/useWalletCheckout.ts
416
+ var import_client10 = require("@fonderie/client");
417
+ var import_react19 = require("@fonderie/react");
418
+ var import_react20 = require("react");
419
+ function useWalletCheckout(client) {
420
+ const billing = (0, import_react19.useFonderieSubClient)(client, (c) => c.billing, "useWalletCheckout");
421
+ const [isLoading, setIsLoading] = (0, import_react20.useState)(false);
422
+ const [error, setError] = (0, import_react20.useState)(null);
423
+ const checkout = (0, import_react20.useCallback)(
424
+ async (input) => {
425
+ setIsLoading(true);
426
+ setError(null);
427
+ try {
428
+ const { result } = await billing.createWalletCheckout(input);
429
+ return result.url;
430
+ } catch (err) {
431
+ const apiError = err instanceof import_client10.FonderieApiError ? err : new import_client10.FonderieApiError("unknown", String(err), 0);
432
+ setError(apiError);
433
+ throw apiError;
434
+ } finally {
435
+ setIsLoading(false);
436
+ }
437
+ },
438
+ [billing]
439
+ );
440
+ return { checkout, isLoading, error };
441
+ }
442
+
443
+ // src/hooks/useCancelSubscription.ts
444
+ var import_client11 = require("@fonderie/client");
445
+ var import_react21 = require("@fonderie/react");
446
+ var import_react22 = require("react");
447
+ function useCancelSubscription(client) {
448
+ const billing = (0, import_react21.useFonderieSubClient)(client, (c) => c.billing, "useCancelSubscription");
449
+ const [isLoading, setIsLoading] = (0, import_react22.useState)(false);
450
+ const [error, setError] = (0, import_react22.useState)(null);
451
+ const cancel = (0, import_react22.useCallback)(
452
+ async (input) => {
453
+ setIsLoading(true);
454
+ setError(null);
455
+ try {
456
+ const { result } = await billing.cancelSubscription(input);
457
+ return result;
458
+ } catch (err) {
459
+ const apiError = err instanceof import_client11.FonderieApiError ? err : new import_client11.FonderieApiError("unknown", String(err), 0);
460
+ setError(apiError);
461
+ throw apiError;
462
+ } finally {
463
+ setIsLoading(false);
464
+ }
465
+ },
466
+ [billing]
467
+ );
468
+ return { cancel, isLoading, error };
469
+ }
470
+
471
+ // src/hooks/useReactivateSubscription.ts
472
+ var import_client12 = require("@fonderie/client");
473
+ var import_react23 = require("@fonderie/react");
474
+ var import_react24 = require("react");
475
+ function useReactivateSubscription(client) {
476
+ const billing = (0, import_react23.useFonderieSubClient)(client, (c) => c.billing, "useReactivateSubscription");
477
+ const [isLoading, setIsLoading] = (0, import_react24.useState)(false);
478
+ const [error, setError] = (0, import_react24.useState)(null);
479
+ const reactivate = (0, import_react24.useCallback)(async () => {
480
+ setIsLoading(true);
481
+ setError(null);
482
+ try {
483
+ const { result } = await billing.reactivateSubscription();
484
+ return result;
485
+ } catch (err) {
486
+ const apiError = err instanceof import_client12.FonderieApiError ? err : new import_client12.FonderieApiError("unknown", String(err), 0);
487
+ setError(apiError);
488
+ throw apiError;
489
+ } finally {
490
+ setIsLoading(false);
491
+ }
492
+ }, [billing]);
493
+ return { reactivate, isLoading, error };
494
+ }
495
+
496
+ // src/hooks/usePaymentMethod.ts
497
+ var import_client13 = require("@fonderie/client");
498
+ var import_react25 = require("@fonderie/react");
499
+ var import_react26 = require("react");
500
+ function usePaymentMethod(client) {
501
+ const billing = (0, import_react25.useFonderieSubClient)(client, (c) => c.billing, "usePaymentMethod");
502
+ const [paymentMethod, setPaymentMethod] = (0, import_react26.useState)(null);
503
+ const [isLoading, setIsLoading] = (0, import_react26.useState)(true);
504
+ const [error, setError] = (0, import_react26.useState)(null);
505
+ const refresh = (0, import_react26.useCallback)(
506
+ async (opts) => {
507
+ setIsLoading(true);
508
+ setError(null);
509
+ try {
510
+ const { result } = await billing.getPaymentMethod({ bust: opts?.force });
511
+ setPaymentMethod(result.paymentMethod);
512
+ } catch (err) {
513
+ const apiError = err instanceof import_client13.FonderieApiError ? err : new import_client13.FonderieApiError("unknown", String(err), 0);
514
+ if (apiError.status !== 501) setError(apiError);
515
+ setPaymentMethod(null);
516
+ } finally {
517
+ setIsLoading(false);
518
+ }
519
+ },
520
+ [billing]
521
+ );
522
+ (0, import_react26.useEffect)(() => {
523
+ void refresh();
524
+ }, [refresh]);
525
+ return { paymentMethod, isLoading, error, refresh };
526
+ }
527
+
528
+ // src/hooks/useInvoices.ts
529
+ var import_client14 = require("@fonderie/client");
530
+ var import_react27 = require("@fonderie/react");
531
+ var import_react28 = require("react");
532
+ function useInvoices(client) {
533
+ const billing = (0, import_react27.useFonderieSubClient)(client, (c) => c.billing, "useInvoices");
534
+ const [invoices, setInvoices] = (0, import_react28.useState)([]);
535
+ const [isLoading, setIsLoading] = (0, import_react28.useState)(true);
536
+ const [error, setError] = (0, import_react28.useState)(null);
537
+ const refresh = (0, import_react28.useCallback)(
538
+ async (opts) => {
539
+ setIsLoading(true);
540
+ setError(null);
541
+ try {
542
+ const { result } = await billing.listInvoices({ bust: opts?.force });
543
+ setInvoices(result.invoices);
544
+ } catch (err) {
545
+ const apiError = err instanceof import_client14.FonderieApiError ? err : new import_client14.FonderieApiError("unknown", String(err), 0);
546
+ if (apiError.status !== 501) setError(apiError);
547
+ setInvoices([]);
548
+ } finally {
549
+ setIsLoading(false);
550
+ }
551
+ },
552
+ [billing]
553
+ );
554
+ (0, import_react28.useEffect)(() => {
555
+ void refresh();
556
+ }, [refresh]);
557
+ return { invoices, isLoading, error, refresh };
558
+ }
321
559
  // Annotate the CommonJS export names for ESM import in node:
322
560
  0 && (module.exports = {
323
561
  FonderieApiError,
324
562
  useBillingPortal,
563
+ useCancelSubscription,
325
564
  useCheckout,
565
+ useInvoices,
566
+ usePaymentMethod,
326
567
  usePlan,
327
568
  usePlans,
569
+ useReactivateSubscription,
328
570
  useSubscription,
329
571
  useUsage,
330
- useWalletPreferences
572
+ useWallet,
573
+ useWalletCheckout,
574
+ useWalletPreferences,
575
+ useWalletTransactions
331
576
  });
332
577
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/hooks/useBillingPortal.ts","../src/hooks/useCheckout.ts","../src/hooks/usePlan.ts","../src/hooks/usePlans.ts","../src/hooks/useSubscription.ts","../src/hooks/useUsage.ts","../src/hooks/useWalletPreferences.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\tIUsePlanReturn,\n\tIUsePlansReturn,\n\tIUseSubscriptionReturn,\n\tIUseUsageReturn,\n\tIUseWalletPreferencesReturn,\n} from './hooks';\nexport {\n\tuseBillingPortal,\n\tuseCheckout,\n\tusePlan,\n\tusePlans,\n\tuseSubscription,\n\tuseUsage,\n\tuseWalletPreferences,\n} from './hooks';\n","import type { BillingClient } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useState } from 'react';\n\nexport interface IUseBillingPortalReturn {\n\topenPortal: () => Promise<string>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n}\n\nexport function useBillingPortal(client?: BillingClient): IUseBillingPortalReturn {\n\tconst billing = useFonderieSubClient(client, (c) => c.billing, 'useBillingPortal');\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst openPortal = useCallback(async () => {\n\t\tsetIsLoading(true);\n\t\tsetError(null);\n\t\ttry {\n\t\t\tconst { result } = await billing.createPortalSession();\n\t\t\treturn result.url;\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\tsetError(apiError);\n\t\t\tthrow apiError;\n\t\t} finally {\n\t\t\tsetIsLoading(false);\n\t\t}\n\t}, [billing]);\n\n\treturn { openPortal, isLoading, error };\n}\n","import type { BillingClient, ICheckoutInput } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useState } from 'react';\n\nexport interface IUseCheckoutReturn {\n\tcheckout: (input: ICheckoutInput) => Promise<string>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n}\n\nexport function useCheckout(client?: BillingClient): IUseCheckoutReturn {\n\tconst billing = useFonderieSubClient(client, (c) => c.billing, 'useCheckout');\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst checkout = useCallback(\n\t\tasync (input: ICheckoutInput) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.createCheckoutSession(input);\n\t\t\t\treturn result.url;\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[billing],\n\t);\n\n\treturn { checkout, isLoading, error };\n}\n","import type { IPlanDTO } from '@fonderie/client';\nimport { BillingClient, FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUsePlanReturn {\n\tplan: IPlanDTO | null;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: (opts?: { force?: boolean }) => Promise<void>;\n}\n\nexport function usePlan(planId: string): IUsePlanReturn;\nexport function usePlan(client: BillingClient | undefined, planId: string): IUsePlanReturn;\nexport function usePlan(\n\tclientOrPlanId: BillingClient | string | undefined,\n\tmaybePlanId?: string,\n): IUsePlanReturn {\n\tconst firstIsClient = clientOrPlanId === undefined || clientOrPlanId instanceof BillingClient;\n\tconst explicit = firstIsClient ? (clientOrPlanId as BillingClient | undefined) : undefined;\n\tconst planId = firstIsClient ? (maybePlanId as string) : clientOrPlanId;\n\tconst billing = useFonderieSubClient(explicit, (c) => c.billing, 'usePlan');\n\tconst [plan, setPlan] = useState<IPlanDTO | null>(null);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(\n\t\tasync (opts?: { force?: boolean }) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.getPlan(planId, { bust: opts?.force });\n\t\t\t\tsetPlan(result.plan);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[billing, planId],\n\t);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { plan, isLoading, error, refresh };\n}\n","import type {\n\tBillingClient,\n\tICreatePlanInput,\n\tIPlanDTO,\n\tIUpdatePlanInput,\n} from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUsePlansReturn {\n\tplans: IPlanDTO[];\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: (opts?: { force?: boolean }) => Promise<void>;\n\tcreatePlan: (input: ICreatePlanInput) => Promise<IPlanDTO>;\n\tupdatePlan: (planId: string, input: IUpdatePlanInput) => Promise<IPlanDTO>;\n\tdeletePlan: (planId: string) => Promise<void>;\n}\n\nexport function usePlans(client?: BillingClient): IUsePlansReturn {\n\tconst billing = useFonderieSubClient(client, (c) => c.billing, 'usePlans');\n\tconst [plans, setPlans] = useState<IPlanDTO[]>([]);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(\n\t\tasync (opts?: { force?: boolean }) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.listPlans({ bust: opts?.force });\n\t\t\t\tsetPlans(result.plans);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[billing],\n\t);\n\n\t// These writes are not auth-gated by @fonderie/billing —\n\t// gate the UI that calls them behind your own admin check before shipping it.\n\tconst createPlan = useCallback(\n\t\tasync (input: ICreatePlanInput) => {\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.createPlan(input);\n\t\t\t\tawait refresh();\n\t\t\t\treturn result.plan;\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t}\n\t\t},\n\t\t[billing, refresh],\n\t);\n\n\tconst updatePlan = useCallback(\n\t\tasync (planId: string, input: IUpdatePlanInput) => {\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.updatePlan(planId, input);\n\t\t\t\tawait refresh();\n\t\t\t\treturn result.plan;\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t}\n\t\t},\n\t\t[billing, refresh],\n\t);\n\n\tconst deletePlan = useCallback(\n\t\tasync (planId: string) => {\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tawait billing.deletePlan(planId);\n\t\t\t\tawait refresh();\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t}\n\t\t},\n\t\t[billing, refresh],\n\t);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { plans, isLoading, error, refresh, createPlan, updatePlan, deletePlan };\n}\n","import type { BillingClient, ISubscriptionDTO } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUseSubscriptionReturn {\n\tsubscription: ISubscriptionDTO | null;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: (opts?: { force?: boolean }) => Promise<void>;\n}\n\nexport function useSubscription(client?: BillingClient): IUseSubscriptionReturn {\n\tconst billing = useFonderieSubClient(client, (c) => c.billing, 'useSubscription');\n\tconst [subscription, setSubscription] = useState<ISubscriptionDTO | null>(null);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(\n\t\tasync (opts?: { force?: boolean }) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.getSubscription({ bust: opts?.force });\n\t\t\t\tsetSubscription(result.subscription);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\t// No active subscription is a normal, expected state — not an error banner.\n\t\t\t\tif (apiError.status !== 404) setError(apiError);\n\t\t\t\tsetSubscription(null);\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[billing],\n\t);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { subscription, isLoading, error, refresh };\n}\n","import type { IRecordUsageInput } from '@fonderie/client';\nimport { BillingClient, FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUseUsageReturn {\n\ttotal: number | null;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: (opts?: { force?: boolean }) => Promise<void>;\n\trecordUsage: (input: IRecordUsageInput) => Promise<void>;\n}\n\nexport function useUsage(metric: string): IUseUsageReturn;\nexport function useUsage(client: BillingClient | undefined, metric: string): IUseUsageReturn;\nexport function useUsage(\n\tclientOrMetric: BillingClient | string | undefined,\n\tmaybeMetric?: string,\n): IUseUsageReturn {\n\tconst firstIsClient = clientOrMetric === undefined || clientOrMetric instanceof BillingClient;\n\tconst explicit = firstIsClient ? (clientOrMetric as BillingClient | undefined) : undefined;\n\tconst metric = firstIsClient ? (maybeMetric as string) : clientOrMetric;\n\tconst billing = useFonderieSubClient(explicit, (c) => c.billing, 'useUsage');\n\tconst [total, setTotal] = useState<number | null>(null);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(\n\t\tasync (opts?: { force?: boolean }) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.getUsage(metric, { bust: opts?.force });\n\t\t\t\tsetTotal(result.total);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[billing, metric],\n\t);\n\n\tconst recordUsage = useCallback(\n\t\tasync (input: IRecordUsageInput) => {\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tawait billing.recordUsage(input);\n\t\t\t\tawait refresh();\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t}\n\t\t},\n\t\t[billing, refresh],\n\t);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { total, isLoading, error, refresh, recordUsage };\n}\n","import { BillingClient, FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUseWalletPreferencesReturn {\n\t// Per-subscriber toggle: when false, a debit stops at the free allowance and\n\t// never draws down purchased credits. null until the first read resolves; a\n\t// subscriber with no balance row reads the server default (true).\n\tspendPurchased: boolean | null;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: (opts?: { force?: boolean }) => Promise<void>;\n\tsetSpendPurchased: (spendPurchased: boolean) => Promise<void>;\n}\n\nexport function useWalletPreferences(client?: BillingClient): IUseWalletPreferencesReturn {\n\tconst billing = useFonderieSubClient(client, (c) => c.billing, 'useWalletPreferences');\n\tconst [spendPurchased, setSpend] = useState<boolean | null>(null);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(\n\t\tasync (opts?: { force?: boolean }) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.getWallet({ bust: opts?.force });\n\t\t\t\t// The DTO omits spendPurchased when no balance row exists; surface the\n\t\t\t\t// server default (spend_purchased DEFAULT true) rather than null.\n\t\t\t\tsetSpend(result.wallet.spendPurchased ?? true);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[billing],\n\t);\n\n\tconst setSpendPurchased = useCallback(\n\t\tasync (next: boolean) => {\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\t// The toggle route returns the refreshed wallet, so adopt it directly.\n\t\t\t\tconst { result } = await billing.setWalletPreferences({ spendPurchased: next });\n\t\t\t\tsetSpend(result.wallet.spendPurchased ?? next);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t}\n\t\t},\n\t\t[billing],\n\t);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { spendPurchased, isLoading, error, refresh, setSpendPurchased };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,IAAAA,iBAAiC;;;ACVjC,oBAAiC;AACjC,mBAAqC;AACrC,IAAAC,gBAAsC;AAQ/B,SAAS,iBAAiB,QAAiD;AACjF,QAAM,cAAU,mCAAqB,QAAQ,CAAC,MAAM,EAAE,SAAS,kBAAkB;AACjF,QAAM,CAAC,WAAW,YAAY,QAAI,wBAAS,KAAK;AAChD,QAAM,CAAC,OAAO,QAAQ,QAAI,wBAAkC,IAAI;AAEhE,QAAM,iBAAa,2BAAY,YAAY;AAC1C,iBAAa,IAAI;AACjB,aAAS,IAAI;AACb,QAAI;AACH,YAAM,EAAE,OAAO,IAAI,MAAM,QAAQ,oBAAoB;AACrD,aAAO,OAAO;AAAA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AAqB,QAAqD;AACzF,QAAM,cAAU,qCAAqB,QAAQ,CAAC,MAAM,EAAE,SAAS,sBAAsB;AACrF,QAAM,CAAC,gBAAgB,QAAQ,QAAI,yBAAyB,IAAI;AAChE,QAAM,CAAC,WAAW,YAAY,QAAI,yBAAS,IAAI;AAC/C,QAAM,CAAC,OAAO,QAAQ,QAAI,yBAAkC,IAAI;AAEhE,QAAM,cAAU;AAAA,IACf,OAAO,SAA+B;AACrC,mBAAa,IAAI;AACjB,eAAS,IAAI;AACb,UAAI;AACH,cAAM,EAAE,OAAO,IAAI,MAAM,QAAQ,UAAU,EAAE,MAAM,MAAM,MAAM,CAAC;AAGhE,iBAAS,OAAO,OAAO,kBAAkB,IAAI;AAAA,MAC9C,SAAS,KAAK;AACb,cAAM,WACL,eAAe,kCAAmB,MAAM,IAAI,gCAAiB,WAAW,OAAO,GAAG,GAAG,CAAC;AACvF,iBAAS,QAAQ;AAAA,MAClB,UAAE;AACD,qBAAa,KAAK;AAAA,MACnB;AAAA,IACD;AAAA,IACA,CAAC,OAAO;AAAA,EACT;AAEA,QAAM,wBAAoB;AAAA,IACzB,OAAO,SAAkB;AACxB,eAAS,IAAI;AACb,UAAI;AAEH,cAAM,EAAE,OAAO,IAAI,MAAM,QAAQ,qBAAqB,EAAE,gBAAgB,KAAK,CAAC;AAC9E,iBAAS,OAAO,OAAO,kBAAkB,IAAI;AAAA,MAC9C,SAAS,KAAK;AACb,cAAM,WACL,eAAe,kCAAmB,MAAM,IAAI,gCAAiB,WAAW,OAAO,GAAG,GAAG,CAAC;AACvF,iBAAS,QAAQ;AACjB,cAAM;AAAA,MACP;AAAA,IACD;AAAA,IACA,CAAC,OAAO;AAAA,EACT;AAEA,gCAAU,MAAM;AACf,SAAK,QAAQ;AAAA,EACd,GAAG,CAAC,OAAO,CAAC;AAEZ,SAAO,EAAE,gBAAgB,WAAW,OAAO,SAAS,kBAAkB;AACvE;","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"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/hooks/useBillingPortal.ts","../src/hooks/useCheckout.ts","../src/hooks/usePlan.ts","../src/hooks/usePlans.ts","../src/hooks/useSubscription.ts","../src/hooks/useUsage.ts","../src/hooks/useWalletPreferences.ts","../src/hooks/useWallet.ts","../src/hooks/useWalletTransactions.ts","../src/hooks/useWalletCheckout.ts","../src/hooks/useCancelSubscription.ts","../src/hooks/useReactivateSubscription.ts","../src/hooks/usePaymentMethod.ts","../src/hooks/useInvoices.ts"],"sourcesContent":["export type {\n\tBillingClient,\n\tICancelSubscriptionInput,\n\tICheckoutInput,\n\tICreatePlanInput,\n\tIInvoiceDTO,\n\tIPaymentMethodDTO,\n\tIPlanDTO,\n\tIPlanFeature,\n\tIRecordUsageInput,\n\tISubscriptionChangeResult,\n\tISubscriptionDTO,\n\tIUpdatePlanInput,\n\tIWalletCheckoutInput,\n\tIWalletDTO,\n\tIWalletTransactionDTO,\n\tSubscriberType,\n} from '@fonderie/client';\nexport { FonderieApiError } from '@fonderie/client';\nexport type {\n\tIUseBillingPortalReturn,\n\tIUseCancelSubscriptionReturn,\n\tIUseCheckoutReturn,\n\tIUseInvoicesReturn,\n\tIUsePaymentMethodReturn,\n\tIUsePlanReturn,\n\tIUsePlansReturn,\n\tIUseReactivateSubscriptionReturn,\n\tIUseSubscriptionReturn,\n\tIUseUsageReturn,\n\tIUseWalletCheckoutReturn,\n\tIUseWalletPreferencesReturn,\n\tIUseWalletReturn,\n\tIUseWalletTransactionsReturn,\n} from './hooks';\nexport {\n\tuseBillingPortal,\n\tuseCancelSubscription,\n\tuseCheckout,\n\tuseInvoices,\n\tusePaymentMethod,\n\tusePlan,\n\tusePlans,\n\tuseReactivateSubscription,\n\tuseSubscription,\n\tuseUsage,\n\tuseWallet,\n\tuseWalletCheckout,\n\tuseWalletPreferences,\n\tuseWalletTransactions,\n} from './hooks';\n","import type { BillingClient } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useState } from 'react';\n\nexport interface IUseBillingPortalReturn {\n\topenPortal: () => Promise<string>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n}\n\nexport function useBillingPortal(client?: BillingClient): IUseBillingPortalReturn {\n\tconst billing = useFonderieSubClient(client, (c) => c.billing, 'useBillingPortal');\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst openPortal = useCallback(async () => {\n\t\tsetIsLoading(true);\n\t\tsetError(null);\n\t\ttry {\n\t\t\tconst { result } = await billing.createPortalSession();\n\t\t\treturn result.url;\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\tsetError(apiError);\n\t\t\tthrow apiError;\n\t\t} finally {\n\t\t\tsetIsLoading(false);\n\t\t}\n\t}, [billing]);\n\n\treturn { openPortal, isLoading, error };\n}\n","import type { BillingClient, ICheckoutInput } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useState } from 'react';\n\nexport interface IUseCheckoutReturn {\n\tcheckout: (input: ICheckoutInput) => Promise<string>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n}\n\nexport function useCheckout(client?: BillingClient): IUseCheckoutReturn {\n\tconst billing = useFonderieSubClient(client, (c) => c.billing, 'useCheckout');\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst checkout = useCallback(\n\t\tasync (input: ICheckoutInput) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.createCheckoutSession(input);\n\t\t\t\treturn result.url;\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[billing],\n\t);\n\n\treturn { checkout, isLoading, error };\n}\n","import type { IPlanDTO } from '@fonderie/client';\nimport { BillingClient, FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUsePlanReturn {\n\tplan: IPlanDTO | null;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: (opts?: { force?: boolean }) => Promise<void>;\n}\n\nexport function usePlan(planId: string): IUsePlanReturn;\nexport function usePlan(client: BillingClient | undefined, planId: string): IUsePlanReturn;\nexport function usePlan(\n\tclientOrPlanId: BillingClient | string | undefined,\n\tmaybePlanId?: string,\n): IUsePlanReturn {\n\tconst firstIsClient = clientOrPlanId === undefined || clientOrPlanId instanceof BillingClient;\n\tconst explicit = firstIsClient ? (clientOrPlanId as BillingClient | undefined) : undefined;\n\tconst planId = firstIsClient ? (maybePlanId as string) : clientOrPlanId;\n\tconst billing = useFonderieSubClient(explicit, (c) => c.billing, 'usePlan');\n\tconst [plan, setPlan] = useState<IPlanDTO | null>(null);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(\n\t\tasync (opts?: { force?: boolean }) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.getPlan(planId, { bust: opts?.force });\n\t\t\t\tsetPlan(result.plan);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[billing, planId],\n\t);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { plan, isLoading, error, refresh };\n}\n","import type {\n\tBillingClient,\n\tICreatePlanInput,\n\tIPlanDTO,\n\tIUpdatePlanInput,\n} from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUsePlansReturn {\n\tplans: IPlanDTO[];\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: (opts?: { force?: boolean }) => Promise<void>;\n\tcreatePlan: (input: ICreatePlanInput) => Promise<IPlanDTO>;\n\tupdatePlan: (planId: string, input: IUpdatePlanInput) => Promise<IPlanDTO>;\n\tdeletePlan: (planId: string) => Promise<void>;\n}\n\nexport function usePlans(client?: BillingClient): IUsePlansReturn {\n\tconst billing = useFonderieSubClient(client, (c) => c.billing, 'usePlans');\n\tconst [plans, setPlans] = useState<IPlanDTO[]>([]);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(\n\t\tasync (opts?: { force?: boolean }) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.listPlans({ bust: opts?.force });\n\t\t\t\tsetPlans(result.plans);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[billing],\n\t);\n\n\t// These writes are not auth-gated by @fonderie/billing —\n\t// gate the UI that calls them behind your own admin check before shipping it.\n\tconst createPlan = useCallback(\n\t\tasync (input: ICreatePlanInput) => {\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.createPlan(input);\n\t\t\t\tawait refresh();\n\t\t\t\treturn result.plan;\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t}\n\t\t},\n\t\t[billing, refresh],\n\t);\n\n\tconst updatePlan = useCallback(\n\t\tasync (planId: string, input: IUpdatePlanInput) => {\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.updatePlan(planId, input);\n\t\t\t\tawait refresh();\n\t\t\t\treturn result.plan;\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t}\n\t\t},\n\t\t[billing, refresh],\n\t);\n\n\tconst deletePlan = useCallback(\n\t\tasync (planId: string) => {\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tawait billing.deletePlan(planId);\n\t\t\t\tawait refresh();\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t}\n\t\t},\n\t\t[billing, refresh],\n\t);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { plans, isLoading, error, refresh, createPlan, updatePlan, deletePlan };\n}\n","import type { BillingClient, ISubscriptionDTO } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUseSubscriptionReturn {\n\tsubscription: ISubscriptionDTO | null;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: (opts?: { force?: boolean }) => Promise<void>;\n}\n\nexport function useSubscription(client?: BillingClient): IUseSubscriptionReturn {\n\tconst billing = useFonderieSubClient(client, (c) => c.billing, 'useSubscription');\n\tconst [subscription, setSubscription] = useState<ISubscriptionDTO | null>(null);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(\n\t\tasync (opts?: { force?: boolean }) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.getSubscription({ bust: opts?.force });\n\t\t\t\tsetSubscription(result.subscription);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\t// No active subscription is a normal, expected state — not an error banner.\n\t\t\t\tif (apiError.status !== 404) setError(apiError);\n\t\t\t\tsetSubscription(null);\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[billing],\n\t);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { subscription, isLoading, error, refresh };\n}\n","import type { IRecordUsageInput } from '@fonderie/client';\nimport { BillingClient, FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUseUsageReturn {\n\ttotal: number | null;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: (opts?: { force?: boolean }) => Promise<void>;\n\trecordUsage: (input: IRecordUsageInput) => Promise<void>;\n}\n\nexport function useUsage(metric: string): IUseUsageReturn;\nexport function useUsage(client: BillingClient | undefined, metric: string): IUseUsageReturn;\nexport function useUsage(\n\tclientOrMetric: BillingClient | string | undefined,\n\tmaybeMetric?: string,\n): IUseUsageReturn {\n\tconst firstIsClient = clientOrMetric === undefined || clientOrMetric instanceof BillingClient;\n\tconst explicit = firstIsClient ? (clientOrMetric as BillingClient | undefined) : undefined;\n\tconst metric = firstIsClient ? (maybeMetric as string) : clientOrMetric;\n\tconst billing = useFonderieSubClient(explicit, (c) => c.billing, 'useUsage');\n\tconst [total, setTotal] = useState<number | null>(null);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(\n\t\tasync (opts?: { force?: boolean }) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.getUsage(metric, { bust: opts?.force });\n\t\t\t\tsetTotal(result.total);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[billing, metric],\n\t);\n\n\tconst recordUsage = useCallback(\n\t\tasync (input: IRecordUsageInput) => {\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tawait billing.recordUsage(input);\n\t\t\t\tawait refresh();\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t}\n\t\t},\n\t\t[billing, refresh],\n\t);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { total, isLoading, error, refresh, recordUsage };\n}\n","import { BillingClient, FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUseWalletPreferencesReturn {\n\t// Per-subscriber toggle: when false, a debit stops at the free allowance and\n\t// never draws down purchased credits. null until the first read resolves; a\n\t// subscriber with no balance row reads the server default (true).\n\tspendPurchased: boolean | null;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: (opts?: { force?: boolean }) => Promise<void>;\n\tsetSpendPurchased: (spendPurchased: boolean) => Promise<void>;\n}\n\nexport function useWalletPreferences(client?: BillingClient): IUseWalletPreferencesReturn {\n\tconst billing = useFonderieSubClient(client, (c) => c.billing, 'useWalletPreferences');\n\tconst [spendPurchased, setSpend] = useState<boolean | null>(null);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(\n\t\tasync (opts?: { force?: boolean }) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.getWallet({ bust: opts?.force });\n\t\t\t\t// The DTO omits spendPurchased when no balance row exists; surface the\n\t\t\t\t// server default (spend_purchased DEFAULT true) rather than null.\n\t\t\t\tsetSpend(result.wallet.spendPurchased ?? true);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[billing],\n\t);\n\n\tconst setSpendPurchased = useCallback(\n\t\tasync (next: boolean) => {\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\t// The toggle route returns the refreshed wallet, so adopt it directly.\n\t\t\t\tconst { result } = await billing.setWalletPreferences({ spendPurchased: next });\n\t\t\t\tsetSpend(result.wallet.spendPurchased ?? next);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t}\n\t\t},\n\t\t[billing],\n\t);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { spendPurchased, isLoading, error, refresh, setSpendPurchased };\n}\n","import type { BillingClient, IWalletDTO } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUseWalletReturn {\n\t// The balance snapshot. Money fields are digit strings (server bigint →\n\t// string); null until the first read resolves or after a failed read.\n\twallet: IWalletDTO | null;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: (opts?: { force?: boolean }) => Promise<void>;\n}\n\n// The subscriber's stored-value wallet balance. Reads GET /billing/wallet, so\n// it reflects the periodic grant withBilling applies on every authed request.\nexport function useWallet(client?: BillingClient): IUseWalletReturn {\n\tconst billing = useFonderieSubClient(client, (c) => c.billing, 'useWallet');\n\tconst [wallet, setWallet] = useState<IWalletDTO | null>(null);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(\n\t\tasync (opts?: { force?: boolean }) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.getWallet({ bust: opts?.force });\n\t\t\t\tsetWallet(result.wallet);\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\tsetWallet(null);\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[billing],\n\t);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { wallet, isLoading, error, refresh };\n}\n","import type { BillingClient, IWalletTransactionDTO } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUseWalletTransactionsReturn {\n\ttransactions: IWalletTransactionDTO[];\n\t// Opaque cursor for the next page, or null when the ledger is exhausted.\n\tnextCursor: string | null;\n\thasMore: boolean;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: (opts?: { force?: boolean }) => Promise<void>;\n\t// Appends the next page. No-op when there is no further page.\n\tloadMore: () => Promise<void>;\n}\n\n// The wallet ledger, newest first — every credit/debit with a running\n// balanceAfter. Cursor-paginated: `loadMore` appends the next page.\nexport function useWalletTransactions(client?: BillingClient): IUseWalletTransactionsReturn {\n\tconst billing = useFonderieSubClient(client, (c) => c.billing, 'useWalletTransactions');\n\tconst [transactions, setTransactions] = useState<IWalletTransactionDTO[]>([]);\n\tconst [nextCursor, setNextCursor] = useState<string | null>(null);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(\n\t\tasync (opts?: { force?: boolean }) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.getWalletTransactions({ bust: opts?.force });\n\t\t\t\tsetTransactions(result.transactions);\n\t\t\t\tsetNextCursor(result.nextCursor);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[billing],\n\t);\n\n\tconst loadMore = useCallback(async () => {\n\t\tif (!nextCursor) return;\n\t\tsetError(null);\n\t\ttry {\n\t\t\tconst { result } = await billing.getWalletTransactions({ cursor: nextCursor });\n\t\t\tsetTransactions((prev) => [...prev, ...result.transactions]);\n\t\t\tsetNextCursor(result.nextCursor);\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}\n\t}, [billing, nextCursor]);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn {\n\t\ttransactions,\n\t\tnextCursor,\n\t\thasMore: nextCursor !== null,\n\t\tisLoading,\n\t\terror,\n\t\trefresh,\n\t\tloadMore,\n\t};\n}\n","import type { BillingClient, IWalletCheckoutInput } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useState } from 'react';\n\nexport interface IUseWalletCheckoutReturn {\n\t// Starts a one-time credit-pack purchase and resolves to the hosted checkout\n\t// URL to redirect the buyer to; the wallet is credited by the payment webhook.\n\tcheckout: (input: IWalletCheckoutInput) => Promise<string>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n}\n\nexport function useWalletCheckout(client?: BillingClient): IUseWalletCheckoutReturn {\n\tconst billing = useFonderieSubClient(client, (c) => c.billing, 'useWalletCheckout');\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst checkout = useCallback(\n\t\tasync (input: IWalletCheckoutInput) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.createWalletCheckout(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 {\n\tBillingClient,\n\tICancelSubscriptionInput,\n\tISubscriptionChangeResult,\n} from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useState } from 'react';\n\nexport interface IUseCancelSubscriptionReturn {\n\t// First-party cancel — no billing-portal round-trip. Default keeps access\n\t// until the paid-through date; pass { atPeriodEnd: false } to end it now.\n\t// Resolves to the new lifecycle state ({ atPeriodEnd, status, currentPeriodEnd }).\n\tcancel: (input?: ICancelSubscriptionInput) => Promise<ISubscriptionChangeResult>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n}\n\nexport function useCancelSubscription(client?: BillingClient): IUseCancelSubscriptionReturn {\n\tconst billing = useFonderieSubClient(client, (c) => c.billing, 'useCancelSubscription');\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst cancel = useCallback(\n\t\tasync (input?: ICancelSubscriptionInput) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.cancelSubscription(input);\n\t\t\t\treturn result;\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 { cancel, isLoading, error };\n}\n","import type { BillingClient, ISubscriptionChangeResult } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useState } from 'react';\n\nexport interface IUseReactivateSubscriptionReturn {\n\t// Un-cancel a subscription scheduled to cancel at period end. Resolves to the\n\t// new lifecycle state; rejects (409) if the subscription is already fully\n\t// canceled — the caller should start a fresh checkout in that case.\n\treactivate: () => Promise<ISubscriptionChangeResult>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n}\n\nexport function useReactivateSubscription(client?: BillingClient): IUseReactivateSubscriptionReturn {\n\tconst billing = useFonderieSubClient(client, (c) => c.billing, 'useReactivateSubscription');\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst reactivate = useCallback(async () => {\n\t\tsetIsLoading(true);\n\t\tsetError(null);\n\t\ttry {\n\t\t\tconst { result } = await billing.reactivateSubscription();\n\t\t\treturn result;\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 { reactivate, isLoading, error };\n}\n","import type { BillingClient, IPaymentMethodDTO } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUsePaymentMethodReturn {\n\t// The card on file (brand/last4/expiry), or null when none is stored or the\n\t// provider can't retrieve one (a normal \"no card\" state, not an error).\n\tpaymentMethod: IPaymentMethodDTO | null;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: (opts?: { force?: boolean }) => Promise<void>;\n}\n\n// The subscriber's card on file, for a billing page. Reads GET\n// /billing/payment-method.\nexport function usePaymentMethod(client?: BillingClient): IUsePaymentMethodReturn {\n\tconst billing = useFonderieSubClient(client, (c) => c.billing, 'usePaymentMethod');\n\tconst [paymentMethod, setPaymentMethod] = useState<IPaymentMethodDTO | null>(null);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(\n\t\tasync (opts?: { force?: boolean }) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.getPaymentMethod({ bust: opts?.force });\n\t\t\t\tsetPaymentMethod(result.paymentMethod);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\t// 501 = the provider can't retrieve a card — a normal \"no card on\n\t\t\t\t// file\" state for a UI, not an error banner.\n\t\t\t\tif (apiError.status !== 501) setError(apiError);\n\t\t\t\tsetPaymentMethod(null);\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[billing],\n\t);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { paymentMethod, isLoading, error, refresh };\n}\n","import type { BillingClient, IInvoiceDTO } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUseInvoicesReturn {\n\t// Invoices newest first; each links out via hostedInvoiceUrl/invoicePdf.\n\tinvoices: IInvoiceDTO[];\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: (opts?: { force?: boolean }) => Promise<void>;\n}\n\n// The subscriber's invoice history, for a billing page. Reads GET\n// /billing/invoices.\nexport function useInvoices(client?: BillingClient): IUseInvoicesReturn {\n\tconst billing = useFonderieSubClient(client, (c) => c.billing, 'useInvoices');\n\tconst [invoices, setInvoices] = useState<IInvoiceDTO[]>([]);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(\n\t\tasync (opts?: { force?: boolean }) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.listInvoices({ bust: opts?.force });\n\t\t\t\tsetInvoices(result.invoices);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\t// 501 = the provider can't list invoices — a normal \"no invoices\" state.\n\t\t\t\tif (apiError.status !== 501) setError(apiError);\n\t\t\t\tsetInvoices([]);\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[billing],\n\t);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { invoices, isLoading, error, refresh };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EhE,QAAM,cAAU;AAAA,IACf,OAAO,SAA+B;AACrC,mBAAa,IAAI;AACjB,eAAS,IAAI;AACb,UAAI;AACH,cAAM,EAAE,OAAO,IAAI,MAAM,QAAQ,aAAa,EAAE,MAAM,MAAM,MAAM,CAAC;AACnE,oBAAY,OAAO,QAAQ;AAAA,MAC5B,SAAS,KAAK;AACb,cAAM,WACL,eAAe,mCAAmB,MAAM,IAAI,iCAAiB,WAAW,OAAO,GAAG,GAAG,CAAC;AAEvF,YAAI,SAAS,WAAW,IAAK,UAAS,QAAQ;AAC9C,oBAAY,CAAC,CAAC;AAAA,MACf,UAAE;AACD,qBAAa,KAAK;AAAA,MACnB;AAAA,IACD;AAAA,IACA,CAAC,OAAO;AAAA,EACT;AAEA,gCAAU,MAAM;AACf,SAAK,QAAQ;AAAA,EACd,GAAG,CAAC,OAAO,CAAC;AAEZ,SAAO,EAAE,UAAU,WAAW,OAAO,QAAQ;AAC9C;","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","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
@@ -1,5 +1,5 @@
1
- import { FonderieApiError, BillingClient, ICheckoutInput, IPlanDTO, ICreatePlanInput, IUpdatePlanInput, ISubscriptionDTO, IRecordUsageInput } from '@fonderie/client';
2
- export { BillingClient, FonderieApiError, ICheckoutInput, ICreatePlanInput, IPlanDTO, IPlanFeature, IRecordUsageInput, ISubscriptionDTO, IUpdatePlanInput, SubscriberType } from '@fonderie/client';
1
+ import { FonderieApiError, BillingClient, ICheckoutInput, IPlanDTO, ICreatePlanInput, IUpdatePlanInput, ISubscriptionDTO, IRecordUsageInput, IWalletDTO, IWalletTransactionDTO, IWalletCheckoutInput, ICancelSubscriptionInput, ISubscriptionChangeResult, IPaymentMethodDTO, IInvoiceDTO } from '@fonderie/client';
2
+ export { BillingClient, FonderieApiError, ICancelSubscriptionInput, ICheckoutInput, ICreatePlanInput, IInvoiceDTO, IPaymentMethodDTO, IPlanDTO, IPlanFeature, IRecordUsageInput, ISubscriptionChangeResult, ISubscriptionDTO, IUpdatePlanInput, IWalletCheckoutInput, IWalletDTO, IWalletTransactionDTO, SubscriberType } from '@fonderie/client';
3
3
 
4
4
  interface IUseBillingPortalReturn {
5
5
  openPortal: () => Promise<string>;
@@ -72,4 +72,68 @@ interface IUseWalletPreferencesReturn {
72
72
  }
73
73
  declare function useWalletPreferences(client?: BillingClient): IUseWalletPreferencesReturn;
74
74
 
75
- export { type IUseBillingPortalReturn, type IUseCheckoutReturn, type IUsePlanReturn, type IUsePlansReturn, type IUseSubscriptionReturn, type IUseUsageReturn, type IUseWalletPreferencesReturn, useBillingPortal, useCheckout, usePlan, usePlans, useSubscription, useUsage, useWalletPreferences };
75
+ interface IUseWalletReturn {
76
+ wallet: IWalletDTO | null;
77
+ isLoading: boolean;
78
+ error: FonderieApiError | null;
79
+ refresh: (opts?: {
80
+ force?: boolean;
81
+ }) => Promise<void>;
82
+ }
83
+ declare function useWallet(client?: BillingClient): IUseWalletReturn;
84
+
85
+ interface IUseWalletTransactionsReturn {
86
+ transactions: IWalletTransactionDTO[];
87
+ nextCursor: string | null;
88
+ hasMore: boolean;
89
+ isLoading: boolean;
90
+ error: FonderieApiError | null;
91
+ refresh: (opts?: {
92
+ force?: boolean;
93
+ }) => Promise<void>;
94
+ loadMore: () => Promise<void>;
95
+ }
96
+ declare function useWalletTransactions(client?: BillingClient): IUseWalletTransactionsReturn;
97
+
98
+ interface IUseWalletCheckoutReturn {
99
+ checkout: (input: IWalletCheckoutInput) => Promise<string>;
100
+ isLoading: boolean;
101
+ error: FonderieApiError | null;
102
+ }
103
+ declare function useWalletCheckout(client?: BillingClient): IUseWalletCheckoutReturn;
104
+
105
+ interface IUseCancelSubscriptionReturn {
106
+ cancel: (input?: ICancelSubscriptionInput) => Promise<ISubscriptionChangeResult>;
107
+ isLoading: boolean;
108
+ error: FonderieApiError | null;
109
+ }
110
+ declare function useCancelSubscription(client?: BillingClient): IUseCancelSubscriptionReturn;
111
+
112
+ interface IUseReactivateSubscriptionReturn {
113
+ reactivate: () => Promise<ISubscriptionChangeResult>;
114
+ isLoading: boolean;
115
+ error: FonderieApiError | null;
116
+ }
117
+ declare function useReactivateSubscription(client?: BillingClient): IUseReactivateSubscriptionReturn;
118
+
119
+ interface IUsePaymentMethodReturn {
120
+ paymentMethod: IPaymentMethodDTO | null;
121
+ isLoading: boolean;
122
+ error: FonderieApiError | null;
123
+ refresh: (opts?: {
124
+ force?: boolean;
125
+ }) => Promise<void>;
126
+ }
127
+ declare function usePaymentMethod(client?: BillingClient): IUsePaymentMethodReturn;
128
+
129
+ interface IUseInvoicesReturn {
130
+ invoices: IInvoiceDTO[];
131
+ isLoading: boolean;
132
+ error: FonderieApiError | null;
133
+ refresh: (opts?: {
134
+ force?: boolean;
135
+ }) => Promise<void>;
136
+ }
137
+ declare function useInvoices(client?: BillingClient): IUseInvoicesReturn;
138
+
139
+ export { type IUseBillingPortalReturn, type IUseCancelSubscriptionReturn, type IUseCheckoutReturn, type IUseInvoicesReturn, type IUsePaymentMethodReturn, type IUsePlanReturn, type IUsePlansReturn, type IUseReactivateSubscriptionReturn, type IUseSubscriptionReturn, type IUseUsageReturn, type IUseWalletCheckoutReturn, type IUseWalletPreferencesReturn, type IUseWalletReturn, type IUseWalletTransactionsReturn, useBillingPortal, useCancelSubscription, useCheckout, useInvoices, usePaymentMethod, usePlan, usePlans, useReactivateSubscription, useSubscription, useUsage, useWallet, useWalletCheckout, useWalletPreferences, useWalletTransactions };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { FonderieApiError, BillingClient, ICheckoutInput, IPlanDTO, ICreatePlanInput, IUpdatePlanInput, ISubscriptionDTO, IRecordUsageInput } from '@fonderie/client';
2
- export { BillingClient, FonderieApiError, ICheckoutInput, ICreatePlanInput, IPlanDTO, IPlanFeature, IRecordUsageInput, ISubscriptionDTO, IUpdatePlanInput, SubscriberType } from '@fonderie/client';
1
+ import { FonderieApiError, BillingClient, ICheckoutInput, IPlanDTO, ICreatePlanInput, IUpdatePlanInput, ISubscriptionDTO, IRecordUsageInput, IWalletDTO, IWalletTransactionDTO, IWalletCheckoutInput, ICancelSubscriptionInput, ISubscriptionChangeResult, IPaymentMethodDTO, IInvoiceDTO } from '@fonderie/client';
2
+ export { BillingClient, FonderieApiError, ICancelSubscriptionInput, ICheckoutInput, ICreatePlanInput, IInvoiceDTO, IPaymentMethodDTO, IPlanDTO, IPlanFeature, IRecordUsageInput, ISubscriptionChangeResult, ISubscriptionDTO, IUpdatePlanInput, IWalletCheckoutInput, IWalletDTO, IWalletTransactionDTO, SubscriberType } from '@fonderie/client';
3
3
 
4
4
  interface IUseBillingPortalReturn {
5
5
  openPortal: () => Promise<string>;
@@ -72,4 +72,68 @@ interface IUseWalletPreferencesReturn {
72
72
  }
73
73
  declare function useWalletPreferences(client?: BillingClient): IUseWalletPreferencesReturn;
74
74
 
75
- export { type IUseBillingPortalReturn, type IUseCheckoutReturn, type IUsePlanReturn, type IUsePlansReturn, type IUseSubscriptionReturn, type IUseUsageReturn, type IUseWalletPreferencesReturn, useBillingPortal, useCheckout, usePlan, usePlans, useSubscription, useUsage, useWalletPreferences };
75
+ interface IUseWalletReturn {
76
+ wallet: IWalletDTO | null;
77
+ isLoading: boolean;
78
+ error: FonderieApiError | null;
79
+ refresh: (opts?: {
80
+ force?: boolean;
81
+ }) => Promise<void>;
82
+ }
83
+ declare function useWallet(client?: BillingClient): IUseWalletReturn;
84
+
85
+ interface IUseWalletTransactionsReturn {
86
+ transactions: IWalletTransactionDTO[];
87
+ nextCursor: string | null;
88
+ hasMore: boolean;
89
+ isLoading: boolean;
90
+ error: FonderieApiError | null;
91
+ refresh: (opts?: {
92
+ force?: boolean;
93
+ }) => Promise<void>;
94
+ loadMore: () => Promise<void>;
95
+ }
96
+ declare function useWalletTransactions(client?: BillingClient): IUseWalletTransactionsReturn;
97
+
98
+ interface IUseWalletCheckoutReturn {
99
+ checkout: (input: IWalletCheckoutInput) => Promise<string>;
100
+ isLoading: boolean;
101
+ error: FonderieApiError | null;
102
+ }
103
+ declare function useWalletCheckout(client?: BillingClient): IUseWalletCheckoutReturn;
104
+
105
+ interface IUseCancelSubscriptionReturn {
106
+ cancel: (input?: ICancelSubscriptionInput) => Promise<ISubscriptionChangeResult>;
107
+ isLoading: boolean;
108
+ error: FonderieApiError | null;
109
+ }
110
+ declare function useCancelSubscription(client?: BillingClient): IUseCancelSubscriptionReturn;
111
+
112
+ interface IUseReactivateSubscriptionReturn {
113
+ reactivate: () => Promise<ISubscriptionChangeResult>;
114
+ isLoading: boolean;
115
+ error: FonderieApiError | null;
116
+ }
117
+ declare function useReactivateSubscription(client?: BillingClient): IUseReactivateSubscriptionReturn;
118
+
119
+ interface IUsePaymentMethodReturn {
120
+ paymentMethod: IPaymentMethodDTO | null;
121
+ isLoading: boolean;
122
+ error: FonderieApiError | null;
123
+ refresh: (opts?: {
124
+ force?: boolean;
125
+ }) => Promise<void>;
126
+ }
127
+ declare function usePaymentMethod(client?: BillingClient): IUsePaymentMethodReturn;
128
+
129
+ interface IUseInvoicesReturn {
130
+ invoices: IInvoiceDTO[];
131
+ isLoading: boolean;
132
+ error: FonderieApiError | null;
133
+ refresh: (opts?: {
134
+ force?: boolean;
135
+ }) => Promise<void>;
136
+ }
137
+ declare function useInvoices(client?: BillingClient): IUseInvoicesReturn;
138
+
139
+ export { type IUseBillingPortalReturn, type IUseCancelSubscriptionReturn, type IUseCheckoutReturn, type IUseInvoicesReturn, type IUsePaymentMethodReturn, type IUsePlanReturn, type IUsePlansReturn, type IUseReactivateSubscriptionReturn, type IUseSubscriptionReturn, type IUseUsageReturn, type IUseWalletCheckoutReturn, type IUseWalletPreferencesReturn, type IUseWalletReturn, type IUseWalletTransactionsReturn, useBillingPortal, useCancelSubscription, useCheckout, useInvoices, usePaymentMethod, usePlan, usePlans, useReactivateSubscription, useSubscription, useUsage, useWallet, useWalletCheckout, useWalletPreferences, useWalletTransactions };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/index.ts
2
- import { FonderieApiError as FonderieApiError8 } from "@fonderie/client";
2
+ import { FonderieApiError as FonderieApiError15 } from "@fonderie/client";
3
3
 
4
4
  // src/hooks/useBillingPortal.ts
5
5
  import { FonderieApiError } from "@fonderie/client";
@@ -287,14 +287,252 @@ function useWalletPreferences(client) {
287
287
  }, [refresh]);
288
288
  return { spendPurchased, isLoading, error, refresh, setSpendPurchased };
289
289
  }
290
+
291
+ // src/hooks/useWallet.ts
292
+ import { FonderieApiError as FonderieApiError8 } from "@fonderie/client";
293
+ import { useFonderieSubClient as useFonderieSubClient8 } from "@fonderie/react";
294
+ import { useCallback as useCallback8, useEffect as useEffect6, useState as useState8 } from "react";
295
+ function useWallet(client) {
296
+ const billing = useFonderieSubClient8(client, (c) => c.billing, "useWallet");
297
+ const [wallet, setWallet] = useState8(null);
298
+ const [isLoading, setIsLoading] = useState8(true);
299
+ const [error, setError] = useState8(null);
300
+ const refresh = useCallback8(
301
+ async (opts) => {
302
+ setIsLoading(true);
303
+ setError(null);
304
+ try {
305
+ const { result } = await billing.getWallet({ bust: opts?.force });
306
+ setWallet(result.wallet);
307
+ } catch (err) {
308
+ const apiError = err instanceof FonderieApiError8 ? err : new FonderieApiError8("unknown", String(err), 0);
309
+ setError(apiError);
310
+ setWallet(null);
311
+ } finally {
312
+ setIsLoading(false);
313
+ }
314
+ },
315
+ [billing]
316
+ );
317
+ useEffect6(() => {
318
+ void refresh();
319
+ }, [refresh]);
320
+ return { wallet, isLoading, error, refresh };
321
+ }
322
+
323
+ // src/hooks/useWalletTransactions.ts
324
+ import { FonderieApiError as FonderieApiError9 } from "@fonderie/client";
325
+ import { useFonderieSubClient as useFonderieSubClient9 } from "@fonderie/react";
326
+ import { useCallback as useCallback9, useEffect as useEffect7, useState as useState9 } from "react";
327
+ function useWalletTransactions(client) {
328
+ const billing = useFonderieSubClient9(client, (c) => c.billing, "useWalletTransactions");
329
+ const [transactions, setTransactions] = useState9([]);
330
+ const [nextCursor, setNextCursor] = useState9(null);
331
+ const [isLoading, setIsLoading] = useState9(true);
332
+ const [error, setError] = useState9(null);
333
+ const refresh = useCallback9(
334
+ async (opts) => {
335
+ setIsLoading(true);
336
+ setError(null);
337
+ try {
338
+ const { result } = await billing.getWalletTransactions({ bust: opts?.force });
339
+ setTransactions(result.transactions);
340
+ setNextCursor(result.nextCursor);
341
+ } catch (err) {
342
+ const apiError = err instanceof FonderieApiError9 ? err : new FonderieApiError9("unknown", String(err), 0);
343
+ setError(apiError);
344
+ } finally {
345
+ setIsLoading(false);
346
+ }
347
+ },
348
+ [billing]
349
+ );
350
+ const loadMore = useCallback9(async () => {
351
+ if (!nextCursor) return;
352
+ setError(null);
353
+ try {
354
+ const { result } = await billing.getWalletTransactions({ cursor: nextCursor });
355
+ setTransactions((prev) => [...prev, ...result.transactions]);
356
+ setNextCursor(result.nextCursor);
357
+ } catch (err) {
358
+ const apiError = err instanceof FonderieApiError9 ? err : new FonderieApiError9("unknown", String(err), 0);
359
+ setError(apiError);
360
+ throw apiError;
361
+ }
362
+ }, [billing, nextCursor]);
363
+ useEffect7(() => {
364
+ void refresh();
365
+ }, [refresh]);
366
+ return {
367
+ transactions,
368
+ nextCursor,
369
+ hasMore: nextCursor !== null,
370
+ isLoading,
371
+ error,
372
+ refresh,
373
+ loadMore
374
+ };
375
+ }
376
+
377
+ // src/hooks/useWalletCheckout.ts
378
+ import { FonderieApiError as FonderieApiError10 } from "@fonderie/client";
379
+ import { useFonderieSubClient as useFonderieSubClient10 } from "@fonderie/react";
380
+ import { useCallback as useCallback10, useState as useState10 } from "react";
381
+ function useWalletCheckout(client) {
382
+ const billing = useFonderieSubClient10(client, (c) => c.billing, "useWalletCheckout");
383
+ const [isLoading, setIsLoading] = useState10(false);
384
+ const [error, setError] = useState10(null);
385
+ const checkout = useCallback10(
386
+ async (input) => {
387
+ setIsLoading(true);
388
+ setError(null);
389
+ try {
390
+ const { result } = await billing.createWalletCheckout(input);
391
+ return result.url;
392
+ } catch (err) {
393
+ const apiError = err instanceof FonderieApiError10 ? err : new FonderieApiError10("unknown", String(err), 0);
394
+ setError(apiError);
395
+ throw apiError;
396
+ } finally {
397
+ setIsLoading(false);
398
+ }
399
+ },
400
+ [billing]
401
+ );
402
+ return { checkout, isLoading, error };
403
+ }
404
+
405
+ // src/hooks/useCancelSubscription.ts
406
+ import { FonderieApiError as FonderieApiError11 } from "@fonderie/client";
407
+ import { useFonderieSubClient as useFonderieSubClient11 } from "@fonderie/react";
408
+ import { useCallback as useCallback11, useState as useState11 } from "react";
409
+ function useCancelSubscription(client) {
410
+ const billing = useFonderieSubClient11(client, (c) => c.billing, "useCancelSubscription");
411
+ const [isLoading, setIsLoading] = useState11(false);
412
+ const [error, setError] = useState11(null);
413
+ const cancel = useCallback11(
414
+ async (input) => {
415
+ setIsLoading(true);
416
+ setError(null);
417
+ try {
418
+ const { result } = await billing.cancelSubscription(input);
419
+ return result;
420
+ } catch (err) {
421
+ const apiError = err instanceof FonderieApiError11 ? err : new FonderieApiError11("unknown", String(err), 0);
422
+ setError(apiError);
423
+ throw apiError;
424
+ } finally {
425
+ setIsLoading(false);
426
+ }
427
+ },
428
+ [billing]
429
+ );
430
+ return { cancel, isLoading, error };
431
+ }
432
+
433
+ // src/hooks/useReactivateSubscription.ts
434
+ import { FonderieApiError as FonderieApiError12 } from "@fonderie/client";
435
+ import { useFonderieSubClient as useFonderieSubClient12 } from "@fonderie/react";
436
+ import { useCallback as useCallback12, useState as useState12 } from "react";
437
+ function useReactivateSubscription(client) {
438
+ const billing = useFonderieSubClient12(client, (c) => c.billing, "useReactivateSubscription");
439
+ const [isLoading, setIsLoading] = useState12(false);
440
+ const [error, setError] = useState12(null);
441
+ const reactivate = useCallback12(async () => {
442
+ setIsLoading(true);
443
+ setError(null);
444
+ try {
445
+ const { result } = await billing.reactivateSubscription();
446
+ return result;
447
+ } catch (err) {
448
+ const apiError = err instanceof FonderieApiError12 ? err : new FonderieApiError12("unknown", String(err), 0);
449
+ setError(apiError);
450
+ throw apiError;
451
+ } finally {
452
+ setIsLoading(false);
453
+ }
454
+ }, [billing]);
455
+ return { reactivate, isLoading, error };
456
+ }
457
+
458
+ // src/hooks/usePaymentMethod.ts
459
+ import { FonderieApiError as FonderieApiError13 } from "@fonderie/client";
460
+ import { useFonderieSubClient as useFonderieSubClient13 } from "@fonderie/react";
461
+ import { useCallback as useCallback13, useEffect as useEffect8, useState as useState13 } from "react";
462
+ function usePaymentMethod(client) {
463
+ const billing = useFonderieSubClient13(client, (c) => c.billing, "usePaymentMethod");
464
+ const [paymentMethod, setPaymentMethod] = useState13(null);
465
+ const [isLoading, setIsLoading] = useState13(true);
466
+ const [error, setError] = useState13(null);
467
+ const refresh = useCallback13(
468
+ async (opts) => {
469
+ setIsLoading(true);
470
+ setError(null);
471
+ try {
472
+ const { result } = await billing.getPaymentMethod({ bust: opts?.force });
473
+ setPaymentMethod(result.paymentMethod);
474
+ } catch (err) {
475
+ const apiError = err instanceof FonderieApiError13 ? err : new FonderieApiError13("unknown", String(err), 0);
476
+ if (apiError.status !== 501) setError(apiError);
477
+ setPaymentMethod(null);
478
+ } finally {
479
+ setIsLoading(false);
480
+ }
481
+ },
482
+ [billing]
483
+ );
484
+ useEffect8(() => {
485
+ void refresh();
486
+ }, [refresh]);
487
+ return { paymentMethod, isLoading, error, refresh };
488
+ }
489
+
490
+ // src/hooks/useInvoices.ts
491
+ import { FonderieApiError as FonderieApiError14 } from "@fonderie/client";
492
+ import { useFonderieSubClient as useFonderieSubClient14 } from "@fonderie/react";
493
+ import { useCallback as useCallback14, useEffect as useEffect9, useState as useState14 } from "react";
494
+ function useInvoices(client) {
495
+ const billing = useFonderieSubClient14(client, (c) => c.billing, "useInvoices");
496
+ const [invoices, setInvoices] = useState14([]);
497
+ const [isLoading, setIsLoading] = useState14(true);
498
+ const [error, setError] = useState14(null);
499
+ const refresh = useCallback14(
500
+ async (opts) => {
501
+ setIsLoading(true);
502
+ setError(null);
503
+ try {
504
+ const { result } = await billing.listInvoices({ bust: opts?.force });
505
+ setInvoices(result.invoices);
506
+ } catch (err) {
507
+ const apiError = err instanceof FonderieApiError14 ? err : new FonderieApiError14("unknown", String(err), 0);
508
+ if (apiError.status !== 501) setError(apiError);
509
+ setInvoices([]);
510
+ } finally {
511
+ setIsLoading(false);
512
+ }
513
+ },
514
+ [billing]
515
+ );
516
+ useEffect9(() => {
517
+ void refresh();
518
+ }, [refresh]);
519
+ return { invoices, isLoading, error, refresh };
520
+ }
290
521
  export {
291
- FonderieApiError8 as FonderieApiError,
522
+ FonderieApiError15 as FonderieApiError,
292
523
  useBillingPortal,
524
+ useCancelSubscription,
293
525
  useCheckout,
526
+ useInvoices,
527
+ usePaymentMethod,
294
528
  usePlan,
295
529
  usePlans,
530
+ useReactivateSubscription,
296
531
  useSubscription,
297
532
  useUsage,
298
- useWalletPreferences
533
+ useWallet,
534
+ useWalletCheckout,
535
+ useWalletPreferences,
536
+ useWalletTransactions
299
537
  };
300
538
  //# sourceMappingURL=index.js.map
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/usePlans.ts","../src/hooks/useSubscription.ts","../src/hooks/useUsage.ts","../src/hooks/useWalletPreferences.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\tIUsePlanReturn,\n\tIUsePlansReturn,\n\tIUseSubscriptionReturn,\n\tIUseUsageReturn,\n\tIUseWalletPreferencesReturn,\n} from './hooks';\nexport {\n\tuseBillingPortal,\n\tuseCheckout,\n\tusePlan,\n\tusePlans,\n\tuseSubscription,\n\tuseUsage,\n\tuseWalletPreferences,\n} from './hooks';\n","import type { BillingClient } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useState } from 'react';\n\nexport interface IUseBillingPortalReturn {\n\topenPortal: () => Promise<string>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n}\n\nexport function useBillingPortal(client?: BillingClient): IUseBillingPortalReturn {\n\tconst billing = useFonderieSubClient(client, (c) => c.billing, 'useBillingPortal');\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst openPortal = useCallback(async () => {\n\t\tsetIsLoading(true);\n\t\tsetError(null);\n\t\ttry {\n\t\t\tconst { result } = await billing.createPortalSession();\n\t\t\treturn result.url;\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\tsetError(apiError);\n\t\t\tthrow apiError;\n\t\t} finally {\n\t\t\tsetIsLoading(false);\n\t\t}\n\t}, [billing]);\n\n\treturn { openPortal, isLoading, error };\n}\n","import type { BillingClient, ICheckoutInput } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useState } from 'react';\n\nexport interface IUseCheckoutReturn {\n\tcheckout: (input: ICheckoutInput) => Promise<string>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n}\n\nexport function useCheckout(client?: BillingClient): IUseCheckoutReturn {\n\tconst billing = useFonderieSubClient(client, (c) => c.billing, 'useCheckout');\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst checkout = useCallback(\n\t\tasync (input: ICheckoutInput) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.createCheckoutSession(input);\n\t\t\t\treturn result.url;\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[billing],\n\t);\n\n\treturn { checkout, isLoading, error };\n}\n","import type { IPlanDTO } from '@fonderie/client';\nimport { BillingClient, FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUsePlanReturn {\n\tplan: IPlanDTO | null;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: (opts?: { force?: boolean }) => Promise<void>;\n}\n\nexport function usePlan(planId: string): IUsePlanReturn;\nexport function usePlan(client: BillingClient | undefined, planId: string): IUsePlanReturn;\nexport function usePlan(\n\tclientOrPlanId: BillingClient | string | undefined,\n\tmaybePlanId?: string,\n): IUsePlanReturn {\n\tconst firstIsClient = clientOrPlanId === undefined || clientOrPlanId instanceof BillingClient;\n\tconst explicit = firstIsClient ? (clientOrPlanId as BillingClient | undefined) : undefined;\n\tconst planId = firstIsClient ? (maybePlanId as string) : clientOrPlanId;\n\tconst billing = useFonderieSubClient(explicit, (c) => c.billing, 'usePlan');\n\tconst [plan, setPlan] = useState<IPlanDTO | null>(null);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(\n\t\tasync (opts?: { force?: boolean }) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.getPlan(planId, { bust: opts?.force });\n\t\t\t\tsetPlan(result.plan);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[billing, planId],\n\t);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { plan, isLoading, error, refresh };\n}\n","import type {\n\tBillingClient,\n\tICreatePlanInput,\n\tIPlanDTO,\n\tIUpdatePlanInput,\n} from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUsePlansReturn {\n\tplans: IPlanDTO[];\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: (opts?: { force?: boolean }) => Promise<void>;\n\tcreatePlan: (input: ICreatePlanInput) => Promise<IPlanDTO>;\n\tupdatePlan: (planId: string, input: IUpdatePlanInput) => Promise<IPlanDTO>;\n\tdeletePlan: (planId: string) => Promise<void>;\n}\n\nexport function usePlans(client?: BillingClient): IUsePlansReturn {\n\tconst billing = useFonderieSubClient(client, (c) => c.billing, 'usePlans');\n\tconst [plans, setPlans] = useState<IPlanDTO[]>([]);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(\n\t\tasync (opts?: { force?: boolean }) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.listPlans({ bust: opts?.force });\n\t\t\t\tsetPlans(result.plans);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[billing],\n\t);\n\n\t// These writes are not auth-gated by @fonderie/billing —\n\t// gate the UI that calls them behind your own admin check before shipping it.\n\tconst createPlan = useCallback(\n\t\tasync (input: ICreatePlanInput) => {\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.createPlan(input);\n\t\t\t\tawait refresh();\n\t\t\t\treturn result.plan;\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t}\n\t\t},\n\t\t[billing, refresh],\n\t);\n\n\tconst updatePlan = useCallback(\n\t\tasync (planId: string, input: IUpdatePlanInput) => {\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.updatePlan(planId, input);\n\t\t\t\tawait refresh();\n\t\t\t\treturn result.plan;\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t}\n\t\t},\n\t\t[billing, refresh],\n\t);\n\n\tconst deletePlan = useCallback(\n\t\tasync (planId: string) => {\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tawait billing.deletePlan(planId);\n\t\t\t\tawait refresh();\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t}\n\t\t},\n\t\t[billing, refresh],\n\t);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { plans, isLoading, error, refresh, createPlan, updatePlan, deletePlan };\n}\n","import type { BillingClient, ISubscriptionDTO } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUseSubscriptionReturn {\n\tsubscription: ISubscriptionDTO | null;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: (opts?: { force?: boolean }) => Promise<void>;\n}\n\nexport function useSubscription(client?: BillingClient): IUseSubscriptionReturn {\n\tconst billing = useFonderieSubClient(client, (c) => c.billing, 'useSubscription');\n\tconst [subscription, setSubscription] = useState<ISubscriptionDTO | null>(null);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(\n\t\tasync (opts?: { force?: boolean }) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.getSubscription({ bust: opts?.force });\n\t\t\t\tsetSubscription(result.subscription);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\t// No active subscription is a normal, expected state — not an error banner.\n\t\t\t\tif (apiError.status !== 404) setError(apiError);\n\t\t\t\tsetSubscription(null);\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[billing],\n\t);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { subscription, isLoading, error, refresh };\n}\n","import type { IRecordUsageInput } from '@fonderie/client';\nimport { BillingClient, FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUseUsageReturn {\n\ttotal: number | null;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: (opts?: { force?: boolean }) => Promise<void>;\n\trecordUsage: (input: IRecordUsageInput) => Promise<void>;\n}\n\nexport function useUsage(metric: string): IUseUsageReturn;\nexport function useUsage(client: BillingClient | undefined, metric: string): IUseUsageReturn;\nexport function useUsage(\n\tclientOrMetric: BillingClient | string | undefined,\n\tmaybeMetric?: string,\n): IUseUsageReturn {\n\tconst firstIsClient = clientOrMetric === undefined || clientOrMetric instanceof BillingClient;\n\tconst explicit = firstIsClient ? (clientOrMetric as BillingClient | undefined) : undefined;\n\tconst metric = firstIsClient ? (maybeMetric as string) : clientOrMetric;\n\tconst billing = useFonderieSubClient(explicit, (c) => c.billing, 'useUsage');\n\tconst [total, setTotal] = useState<number | null>(null);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(\n\t\tasync (opts?: { force?: boolean }) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.getUsage(metric, { bust: opts?.force });\n\t\t\t\tsetTotal(result.total);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[billing, metric],\n\t);\n\n\tconst recordUsage = useCallback(\n\t\tasync (input: IRecordUsageInput) => {\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tawait billing.recordUsage(input);\n\t\t\t\tawait refresh();\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t}\n\t\t},\n\t\t[billing, refresh],\n\t);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { total, isLoading, error, refresh, recordUsage };\n}\n","import { BillingClient, FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUseWalletPreferencesReturn {\n\t// Per-subscriber toggle: when false, a debit stops at the free allowance and\n\t// never draws down purchased credits. null until the first read resolves; a\n\t// subscriber with no balance row reads the server default (true).\n\tspendPurchased: boolean | null;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: (opts?: { force?: boolean }) => Promise<void>;\n\tsetSpendPurchased: (spendPurchased: boolean) => Promise<void>;\n}\n\nexport function useWalletPreferences(client?: BillingClient): IUseWalletPreferencesReturn {\n\tconst billing = useFonderieSubClient(client, (c) => c.billing, 'useWalletPreferences');\n\tconst [spendPurchased, setSpend] = useState<boolean | null>(null);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(\n\t\tasync (opts?: { force?: boolean }) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.getWallet({ bust: opts?.force });\n\t\t\t\t// The DTO omits spendPurchased when no balance row exists; surface the\n\t\t\t\t// server default (spend_purchased DEFAULT true) rather than null.\n\t\t\t\tsetSpend(result.wallet.spendPurchased ?? true);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[billing],\n\t);\n\n\tconst setSpendPurchased = useCallback(\n\t\tasync (next: boolean) => {\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\t// The toggle route returns the refreshed wallet, so adopt it directly.\n\t\t\t\tconst { result } = await billing.setWalletPreferences({ spendPurchased: next });\n\t\t\t\tsetSpend(result.wallet.spendPurchased ?? next);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t}\n\t\t},\n\t\t[billing],\n\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M,EAAE,OAAO,IAAI,MAAM,QAAQ,UAAU,EAAE,MAAM,MAAM,MAAM,CAAC;AAGhE,iBAAS,OAAO,OAAO,kBAAkB,IAAI;AAAA,MAC9C,SAAS,KAAK;AACb,cAAM,WACL,eAAeF,oBAAmB,MAAM,IAAIA,kBAAiB,WAAW,OAAO,GAAG,GAAG,CAAC;AACvF,iBAAS,QAAQ;AAAA,MAClB,UAAE;AACD,qBAAa,KAAK;AAAA,MACnB;AAAA,IACD;AAAA,IACA,CAAC,OAAO;AAAA,EACT;AAEA,QAAM,oBAAoBE;AAAA,IACzB,OAAO,SAAkB;AACxB,eAAS,IAAI;AACb,UAAI;AAEH,cAAM,EAAE,OAAO,IAAI,MAAM,QAAQ,qBAAqB,EAAE,gBAAgB,KAAK,CAAC;AAC9E,iBAAS,OAAO,OAAO,kBAAkB,IAAI;AAAA,MAC9C,SAAS,KAAK;AACb,cAAM,WACL,eAAeF,oBAAmB,MAAM,IAAIA,kBAAiB,WAAW,OAAO,GAAG,GAAG,CAAC;AACvF,iBAAS,QAAQ;AACjB,cAAM;AAAA,MACP;AAAA,IACD;AAAA,IACA,CAAC,OAAO;AAAA,EACT;AAEA,EAAAG,WAAU,MAAM;AACf,SAAK,QAAQ;AAAA,EACd,GAAG,CAAC,OAAO,CAAC;AAEZ,SAAO,EAAE,gBAAgB,WAAW,OAAO,SAAS,kBAAkB;AACvE;","names":["FonderieApiError","FonderieApiError","useFonderieSubClient","useCallback","useState","FonderieApiError","useFonderieSubClient","useCallback","useState","FonderieApiError","useFonderieSubClient","useCallback","useEffect","useState","FonderieApiError","useFonderieSubClient","useCallback","useEffect","useState","BillingClient","FonderieApiError","useFonderieSubClient","useCallback","useEffect","useState","FonderieApiError","useFonderieSubClient","useCallback","useEffect","useState"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/hooks/useBillingPortal.ts","../src/hooks/useCheckout.ts","../src/hooks/usePlan.ts","../src/hooks/usePlans.ts","../src/hooks/useSubscription.ts","../src/hooks/useUsage.ts","../src/hooks/useWalletPreferences.ts","../src/hooks/useWallet.ts","../src/hooks/useWalletTransactions.ts","../src/hooks/useWalletCheckout.ts","../src/hooks/useCancelSubscription.ts","../src/hooks/useReactivateSubscription.ts","../src/hooks/usePaymentMethod.ts","../src/hooks/useInvoices.ts"],"sourcesContent":["export type {\n\tBillingClient,\n\tICancelSubscriptionInput,\n\tICheckoutInput,\n\tICreatePlanInput,\n\tIInvoiceDTO,\n\tIPaymentMethodDTO,\n\tIPlanDTO,\n\tIPlanFeature,\n\tIRecordUsageInput,\n\tISubscriptionChangeResult,\n\tISubscriptionDTO,\n\tIUpdatePlanInput,\n\tIWalletCheckoutInput,\n\tIWalletDTO,\n\tIWalletTransactionDTO,\n\tSubscriberType,\n} from '@fonderie/client';\nexport { FonderieApiError } from '@fonderie/client';\nexport type {\n\tIUseBillingPortalReturn,\n\tIUseCancelSubscriptionReturn,\n\tIUseCheckoutReturn,\n\tIUseInvoicesReturn,\n\tIUsePaymentMethodReturn,\n\tIUsePlanReturn,\n\tIUsePlansReturn,\n\tIUseReactivateSubscriptionReturn,\n\tIUseSubscriptionReturn,\n\tIUseUsageReturn,\n\tIUseWalletCheckoutReturn,\n\tIUseWalletPreferencesReturn,\n\tIUseWalletReturn,\n\tIUseWalletTransactionsReturn,\n} from './hooks';\nexport {\n\tuseBillingPortal,\n\tuseCancelSubscription,\n\tuseCheckout,\n\tuseInvoices,\n\tusePaymentMethod,\n\tusePlan,\n\tusePlans,\n\tuseReactivateSubscription,\n\tuseSubscription,\n\tuseUsage,\n\tuseWallet,\n\tuseWalletCheckout,\n\tuseWalletPreferences,\n\tuseWalletTransactions,\n} from './hooks';\n","import type { BillingClient } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useState } from 'react';\n\nexport interface IUseBillingPortalReturn {\n\topenPortal: () => Promise<string>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n}\n\nexport function useBillingPortal(client?: BillingClient): IUseBillingPortalReturn {\n\tconst billing = useFonderieSubClient(client, (c) => c.billing, 'useBillingPortal');\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst openPortal = useCallback(async () => {\n\t\tsetIsLoading(true);\n\t\tsetError(null);\n\t\ttry {\n\t\t\tconst { result } = await billing.createPortalSession();\n\t\t\treturn result.url;\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\tsetError(apiError);\n\t\t\tthrow apiError;\n\t\t} finally {\n\t\t\tsetIsLoading(false);\n\t\t}\n\t}, [billing]);\n\n\treturn { openPortal, isLoading, error };\n}\n","import type { BillingClient, ICheckoutInput } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useState } from 'react';\n\nexport interface IUseCheckoutReturn {\n\tcheckout: (input: ICheckoutInput) => Promise<string>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n}\n\nexport function useCheckout(client?: BillingClient): IUseCheckoutReturn {\n\tconst billing = useFonderieSubClient(client, (c) => c.billing, 'useCheckout');\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst checkout = useCallback(\n\t\tasync (input: ICheckoutInput) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.createCheckoutSession(input);\n\t\t\t\treturn result.url;\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[billing],\n\t);\n\n\treturn { checkout, isLoading, error };\n}\n","import type { IPlanDTO } from '@fonderie/client';\nimport { BillingClient, FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUsePlanReturn {\n\tplan: IPlanDTO | null;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: (opts?: { force?: boolean }) => Promise<void>;\n}\n\nexport function usePlan(planId: string): IUsePlanReturn;\nexport function usePlan(client: BillingClient | undefined, planId: string): IUsePlanReturn;\nexport function usePlan(\n\tclientOrPlanId: BillingClient | string | undefined,\n\tmaybePlanId?: string,\n): IUsePlanReturn {\n\tconst firstIsClient = clientOrPlanId === undefined || clientOrPlanId instanceof BillingClient;\n\tconst explicit = firstIsClient ? (clientOrPlanId as BillingClient | undefined) : undefined;\n\tconst planId = firstIsClient ? (maybePlanId as string) : clientOrPlanId;\n\tconst billing = useFonderieSubClient(explicit, (c) => c.billing, 'usePlan');\n\tconst [plan, setPlan] = useState<IPlanDTO | null>(null);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(\n\t\tasync (opts?: { force?: boolean }) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.getPlan(planId, { bust: opts?.force });\n\t\t\t\tsetPlan(result.plan);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[billing, planId],\n\t);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { plan, isLoading, error, refresh };\n}\n","import type {\n\tBillingClient,\n\tICreatePlanInput,\n\tIPlanDTO,\n\tIUpdatePlanInput,\n} from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUsePlansReturn {\n\tplans: IPlanDTO[];\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: (opts?: { force?: boolean }) => Promise<void>;\n\tcreatePlan: (input: ICreatePlanInput) => Promise<IPlanDTO>;\n\tupdatePlan: (planId: string, input: IUpdatePlanInput) => Promise<IPlanDTO>;\n\tdeletePlan: (planId: string) => Promise<void>;\n}\n\nexport function usePlans(client?: BillingClient): IUsePlansReturn {\n\tconst billing = useFonderieSubClient(client, (c) => c.billing, 'usePlans');\n\tconst [plans, setPlans] = useState<IPlanDTO[]>([]);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(\n\t\tasync (opts?: { force?: boolean }) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.listPlans({ bust: opts?.force });\n\t\t\t\tsetPlans(result.plans);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[billing],\n\t);\n\n\t// These writes are not auth-gated by @fonderie/billing —\n\t// gate the UI that calls them behind your own admin check before shipping it.\n\tconst createPlan = useCallback(\n\t\tasync (input: ICreatePlanInput) => {\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.createPlan(input);\n\t\t\t\tawait refresh();\n\t\t\t\treturn result.plan;\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t}\n\t\t},\n\t\t[billing, refresh],\n\t);\n\n\tconst updatePlan = useCallback(\n\t\tasync (planId: string, input: IUpdatePlanInput) => {\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.updatePlan(planId, input);\n\t\t\t\tawait refresh();\n\t\t\t\treturn result.plan;\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t}\n\t\t},\n\t\t[billing, refresh],\n\t);\n\n\tconst deletePlan = useCallback(\n\t\tasync (planId: string) => {\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tawait billing.deletePlan(planId);\n\t\t\t\tawait refresh();\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t}\n\t\t},\n\t\t[billing, refresh],\n\t);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { plans, isLoading, error, refresh, createPlan, updatePlan, deletePlan };\n}\n","import type { BillingClient, ISubscriptionDTO } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUseSubscriptionReturn {\n\tsubscription: ISubscriptionDTO | null;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: (opts?: { force?: boolean }) => Promise<void>;\n}\n\nexport function useSubscription(client?: BillingClient): IUseSubscriptionReturn {\n\tconst billing = useFonderieSubClient(client, (c) => c.billing, 'useSubscription');\n\tconst [subscription, setSubscription] = useState<ISubscriptionDTO | null>(null);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(\n\t\tasync (opts?: { force?: boolean }) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.getSubscription({ bust: opts?.force });\n\t\t\t\tsetSubscription(result.subscription);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\t// No active subscription is a normal, expected state — not an error banner.\n\t\t\t\tif (apiError.status !== 404) setError(apiError);\n\t\t\t\tsetSubscription(null);\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[billing],\n\t);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { subscription, isLoading, error, refresh };\n}\n","import type { IRecordUsageInput } from '@fonderie/client';\nimport { BillingClient, FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUseUsageReturn {\n\ttotal: number | null;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: (opts?: { force?: boolean }) => Promise<void>;\n\trecordUsage: (input: IRecordUsageInput) => Promise<void>;\n}\n\nexport function useUsage(metric: string): IUseUsageReturn;\nexport function useUsage(client: BillingClient | undefined, metric: string): IUseUsageReturn;\nexport function useUsage(\n\tclientOrMetric: BillingClient | string | undefined,\n\tmaybeMetric?: string,\n): IUseUsageReturn {\n\tconst firstIsClient = clientOrMetric === undefined || clientOrMetric instanceof BillingClient;\n\tconst explicit = firstIsClient ? (clientOrMetric as BillingClient | undefined) : undefined;\n\tconst metric = firstIsClient ? (maybeMetric as string) : clientOrMetric;\n\tconst billing = useFonderieSubClient(explicit, (c) => c.billing, 'useUsage');\n\tconst [total, setTotal] = useState<number | null>(null);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(\n\t\tasync (opts?: { force?: boolean }) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.getUsage(metric, { bust: opts?.force });\n\t\t\t\tsetTotal(result.total);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[billing, metric],\n\t);\n\n\tconst recordUsage = useCallback(\n\t\tasync (input: IRecordUsageInput) => {\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tawait billing.recordUsage(input);\n\t\t\t\tawait refresh();\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t}\n\t\t},\n\t\t[billing, refresh],\n\t);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { total, isLoading, error, refresh, recordUsage };\n}\n","import { BillingClient, FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUseWalletPreferencesReturn {\n\t// Per-subscriber toggle: when false, a debit stops at the free allowance and\n\t// never draws down purchased credits. null until the first read resolves; a\n\t// subscriber with no balance row reads the server default (true).\n\tspendPurchased: boolean | null;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: (opts?: { force?: boolean }) => Promise<void>;\n\tsetSpendPurchased: (spendPurchased: boolean) => Promise<void>;\n}\n\nexport function useWalletPreferences(client?: BillingClient): IUseWalletPreferencesReturn {\n\tconst billing = useFonderieSubClient(client, (c) => c.billing, 'useWalletPreferences');\n\tconst [spendPurchased, setSpend] = useState<boolean | null>(null);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(\n\t\tasync (opts?: { force?: boolean }) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.getWallet({ bust: opts?.force });\n\t\t\t\t// The DTO omits spendPurchased when no balance row exists; surface the\n\t\t\t\t// server default (spend_purchased DEFAULT true) rather than null.\n\t\t\t\tsetSpend(result.wallet.spendPurchased ?? true);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[billing],\n\t);\n\n\tconst setSpendPurchased = useCallback(\n\t\tasync (next: boolean) => {\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\t// The toggle route returns the refreshed wallet, so adopt it directly.\n\t\t\t\tconst { result } = await billing.setWalletPreferences({ spendPurchased: next });\n\t\t\t\tsetSpend(result.wallet.spendPurchased ?? next);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t}\n\t\t},\n\t\t[billing],\n\t);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { spendPurchased, isLoading, error, refresh, setSpendPurchased };\n}\n","import type { BillingClient, IWalletDTO } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUseWalletReturn {\n\t// The balance snapshot. Money fields are digit strings (server bigint →\n\t// string); null until the first read resolves or after a failed read.\n\twallet: IWalletDTO | null;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: (opts?: { force?: boolean }) => Promise<void>;\n}\n\n// The subscriber's stored-value wallet balance. Reads GET /billing/wallet, so\n// it reflects the periodic grant withBilling applies on every authed request.\nexport function useWallet(client?: BillingClient): IUseWalletReturn {\n\tconst billing = useFonderieSubClient(client, (c) => c.billing, 'useWallet');\n\tconst [wallet, setWallet] = useState<IWalletDTO | null>(null);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(\n\t\tasync (opts?: { force?: boolean }) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.getWallet({ bust: opts?.force });\n\t\t\t\tsetWallet(result.wallet);\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\tsetWallet(null);\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[billing],\n\t);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { wallet, isLoading, error, refresh };\n}\n","import type { BillingClient, IWalletTransactionDTO } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUseWalletTransactionsReturn {\n\ttransactions: IWalletTransactionDTO[];\n\t// Opaque cursor for the next page, or null when the ledger is exhausted.\n\tnextCursor: string | null;\n\thasMore: boolean;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: (opts?: { force?: boolean }) => Promise<void>;\n\t// Appends the next page. No-op when there is no further page.\n\tloadMore: () => Promise<void>;\n}\n\n// The wallet ledger, newest first — every credit/debit with a running\n// balanceAfter. Cursor-paginated: `loadMore` appends the next page.\nexport function useWalletTransactions(client?: BillingClient): IUseWalletTransactionsReturn {\n\tconst billing = useFonderieSubClient(client, (c) => c.billing, 'useWalletTransactions');\n\tconst [transactions, setTransactions] = useState<IWalletTransactionDTO[]>([]);\n\tconst [nextCursor, setNextCursor] = useState<string | null>(null);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(\n\t\tasync (opts?: { force?: boolean }) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.getWalletTransactions({ bust: opts?.force });\n\t\t\t\tsetTransactions(result.transactions);\n\t\t\t\tsetNextCursor(result.nextCursor);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[billing],\n\t);\n\n\tconst loadMore = useCallback(async () => {\n\t\tif (!nextCursor) return;\n\t\tsetError(null);\n\t\ttry {\n\t\t\tconst { result } = await billing.getWalletTransactions({ cursor: nextCursor });\n\t\t\tsetTransactions((prev) => [...prev, ...result.transactions]);\n\t\t\tsetNextCursor(result.nextCursor);\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}\n\t}, [billing, nextCursor]);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn {\n\t\ttransactions,\n\t\tnextCursor,\n\t\thasMore: nextCursor !== null,\n\t\tisLoading,\n\t\terror,\n\t\trefresh,\n\t\tloadMore,\n\t};\n}\n","import type { BillingClient, IWalletCheckoutInput } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useState } from 'react';\n\nexport interface IUseWalletCheckoutReturn {\n\t// Starts a one-time credit-pack purchase and resolves to the hosted checkout\n\t// URL to redirect the buyer to; the wallet is credited by the payment webhook.\n\tcheckout: (input: IWalletCheckoutInput) => Promise<string>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n}\n\nexport function useWalletCheckout(client?: BillingClient): IUseWalletCheckoutReturn {\n\tconst billing = useFonderieSubClient(client, (c) => c.billing, 'useWalletCheckout');\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst checkout = useCallback(\n\t\tasync (input: IWalletCheckoutInput) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.createWalletCheckout(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 {\n\tBillingClient,\n\tICancelSubscriptionInput,\n\tISubscriptionChangeResult,\n} from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useState } from 'react';\n\nexport interface IUseCancelSubscriptionReturn {\n\t// First-party cancel — no billing-portal round-trip. Default keeps access\n\t// until the paid-through date; pass { atPeriodEnd: false } to end it now.\n\t// Resolves to the new lifecycle state ({ atPeriodEnd, status, currentPeriodEnd }).\n\tcancel: (input?: ICancelSubscriptionInput) => Promise<ISubscriptionChangeResult>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n}\n\nexport function useCancelSubscription(client?: BillingClient): IUseCancelSubscriptionReturn {\n\tconst billing = useFonderieSubClient(client, (c) => c.billing, 'useCancelSubscription');\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst cancel = useCallback(\n\t\tasync (input?: ICancelSubscriptionInput) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.cancelSubscription(input);\n\t\t\t\treturn result;\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 { cancel, isLoading, error };\n}\n","import type { BillingClient, ISubscriptionChangeResult } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useState } from 'react';\n\nexport interface IUseReactivateSubscriptionReturn {\n\t// Un-cancel a subscription scheduled to cancel at period end. Resolves to the\n\t// new lifecycle state; rejects (409) if the subscription is already fully\n\t// canceled — the caller should start a fresh checkout in that case.\n\treactivate: () => Promise<ISubscriptionChangeResult>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n}\n\nexport function useReactivateSubscription(client?: BillingClient): IUseReactivateSubscriptionReturn {\n\tconst billing = useFonderieSubClient(client, (c) => c.billing, 'useReactivateSubscription');\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst reactivate = useCallback(async () => {\n\t\tsetIsLoading(true);\n\t\tsetError(null);\n\t\ttry {\n\t\t\tconst { result } = await billing.reactivateSubscription();\n\t\t\treturn result;\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 { reactivate, isLoading, error };\n}\n","import type { BillingClient, IPaymentMethodDTO } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUsePaymentMethodReturn {\n\t// The card on file (brand/last4/expiry), or null when none is stored or the\n\t// provider can't retrieve one (a normal \"no card\" state, not an error).\n\tpaymentMethod: IPaymentMethodDTO | null;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: (opts?: { force?: boolean }) => Promise<void>;\n}\n\n// The subscriber's card on file, for a billing page. Reads GET\n// /billing/payment-method.\nexport function usePaymentMethod(client?: BillingClient): IUsePaymentMethodReturn {\n\tconst billing = useFonderieSubClient(client, (c) => c.billing, 'usePaymentMethod');\n\tconst [paymentMethod, setPaymentMethod] = useState<IPaymentMethodDTO | null>(null);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(\n\t\tasync (opts?: { force?: boolean }) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.getPaymentMethod({ bust: opts?.force });\n\t\t\t\tsetPaymentMethod(result.paymentMethod);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\t// 501 = the provider can't retrieve a card — a normal \"no card on\n\t\t\t\t// file\" state for a UI, not an error banner.\n\t\t\t\tif (apiError.status !== 501) setError(apiError);\n\t\t\t\tsetPaymentMethod(null);\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[billing],\n\t);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { paymentMethod, isLoading, error, refresh };\n}\n","import type { BillingClient, IInvoiceDTO } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useEffect, useState } from 'react';\n\nexport interface IUseInvoicesReturn {\n\t// Invoices newest first; each links out via hostedInvoiceUrl/invoicePdf.\n\tinvoices: IInvoiceDTO[];\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\trefresh: (opts?: { force?: boolean }) => Promise<void>;\n}\n\n// The subscriber's invoice history, for a billing page. Reads GET\n// /billing/invoices.\nexport function useInvoices(client?: BillingClient): IUseInvoicesReturn {\n\tconst billing = useFonderieSubClient(client, (c) => c.billing, 'useInvoices');\n\tconst [invoices, setInvoices] = useState<IInvoiceDTO[]>([]);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst refresh = useCallback(\n\t\tasync (opts?: { force?: boolean }) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await billing.listInvoices({ bust: opts?.force });\n\t\t\t\tsetInvoices(result.invoices);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\t// 501 = the provider can't list invoices — a normal \"no invoices\" state.\n\t\t\t\tif (apiError.status !== 501) setError(apiError);\n\t\t\t\tsetInvoices([]);\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[billing],\n\t);\n\n\tuseEffect(() => {\n\t\tvoid refresh();\n\t}, [refresh]);\n\n\treturn { invoices, isLoading, error, refresh };\n}\n"],"mappings":";AAkBA,SAAS,oBAAAA,0BAAwB;;;ACjBjC,SAAS,wBAAwB;AACjC,SAAS,4BAA4B;AACrC,SAAS,aAAa,gBAAgB;AAQ/B,SAAS,iBAAiB,QAAiD;AACjF,QAAM,UA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AE,eAAe,WAAW,OAAO,QAAQ;AACnD;;;AC/CA,SAAS,oBAAAE,0BAAwB;AACjC,SAAS,wBAAAC,8BAA4B;AACrC,SAAS,eAAAC,eAAa,aAAAC,YAAW,YAAAC,kBAAgB;AAY1C,SAAS,YAAY,QAA4C;AACvE,QAAM,UAAUH,uBAAqB,QAAQ,CAAC,MAAM,EAAE,SAAS,aAAa;AAC5E,QAAM,CAAC,UAAU,WAAW,IAAIG,WAAwB,CAAC,CAAC;AAC1D,QAAM,CAAC,WAAW,YAAY,IAAIA,WAAS,IAAI;AAC/C,QAAM,CAAC,OAAO,QAAQ,IAAIA,WAAkC,IAAI;AAEhE,QAAM,UAAUF;AAAA,IACf,OAAO,SAA+B;AACrC,mBAAa,IAAI;AACjB,eAAS,IAAI;AACb,UAAI;AACH,cAAM,EAAE,OAAO,IAAI,MAAM,QAAQ,aAAa,EAAE,MAAM,MAAM,MAAM,CAAC;AACnE,oBAAY,OAAO,QAAQ;AAAA,MAC5B,SAAS,KAAK;AACb,cAAM,WACL,eAAeF,qBAAmB,MAAM,IAAIA,mBAAiB,WAAW,OAAO,GAAG,GAAG,CAAC;AAEvF,YAAI,SAAS,WAAW,IAAK,UAAS,QAAQ;AAC9C,oBAAY,CAAC,CAAC;AAAA,MACf,UAAE;AACD,qBAAa,KAAK;AAAA,MACnB;AAAA,IACD;AAAA,IACA,CAAC,OAAO;AAAA,EACT;AAEA,EAAAG,WAAU,MAAM;AACf,SAAK,QAAQ;AAAA,EACd,GAAG,CAAC,OAAO,CAAC;AAEZ,SAAO,EAAE,UAAU,WAAW,OAAO,QAAQ;AAC9C;","names":["FonderieApiError","FonderieApiError","useFonderieSubClient","useCallback","useState","FonderieApiError","useFonderieSubClient","useCallback","useState","FonderieApiError","useFonderieSubClient","useCallback","useEffect","useState","FonderieApiError","useFonderieSubClient","useCallback","useEffect","useState","BillingClient","FonderieApiError","useFonderieSubClient","useCallback","useEffect","useState","FonderieApiError","useFonderieSubClient","useCallback","useEffect","useState","FonderieApiError","useFonderieSubClient","useCallback","useEffect","useState","FonderieApiError","useFonderieSubClient","useCallback","useEffect","useState","FonderieApiError","useFonderieSubClient","useCallback","useState","FonderieApiError","useFonderieSubClient","useCallback","useState","FonderieApiError","useFonderieSubClient","useCallback","useState","FonderieApiError","useFonderieSubClient","useCallback","useEffect","useState","FonderieApiError","useFonderieSubClient","useCallback","useEffect","useState"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fonderie/react-billing",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "React hooks for Fonderie billing — thin bindings over @fonderie/client.",
5
5
  "keywords": [
6
6
  "fonderiejs",