@fonderie/client 0.12.0 → 0.13.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.
@@ -183,12 +183,18 @@ new BillingClient(http: HttpClient, tokens: TokenStore): BillingClient
183
183
  .updatePlan(planId: string, input: Partial<ICreatePlanInput>): Promise<IApiResponse<IPlanResult>>
184
184
  .deletePlan(planId: string): Promise<IApiResponse<undefined>>
185
185
  .getSubscription(opts?: IReadOptions | undefined): Promise<IApiResponse<ISubscriptionResult>>
186
+ .cancelSubscription(input?: ICancelSubscriptionInput | undefined): Promise<IApiResponse<ISubscriptionChangeResult>>
187
+ .reactivateSubscription(): Promise<IApiResponse<ISubscriptionChangeResult>>
186
188
  .createCheckoutSession(input: ICheckoutInput): Promise<IApiResponse<ICheckoutUrlResult>>
187
189
  .createPortalSession(): Promise<IApiResponse<IPortalUrlResult>>
188
190
  .recordUsage(input: IRecordUsageInput): Promise<IApiResponse<undefined>>
189
191
  .getUsage(metric: string, opts?: IReadOptions | undefined): Promise<IApiResponse<IUsageResult>>
190
192
  .getWallet(opts?: IReadOptions | undefined): Promise<IApiResponse<IWalletResult>>
191
193
  .setWalletPreferences(input: IWalletPreferencesInput): Promise<IApiResponse<IWalletResult>>
194
+ .createWalletCheckout(input: IWalletCheckoutInput): Promise<IApiResponse<ICheckoutUrlResult>>
195
+ .getWalletTransactions(opts?: (IReadOptions & { cursor?: string; limit?: number; }) | undefined): Promise<IApiResponse<IWalletTransactionsResult>>
196
+ .getPaymentMethod(opts?: IReadOptions | undefined): Promise<IApiResponse<IPaymentMethodResult>>
197
+ .listInvoices(opts?: IReadOptions | undefined): Promise<IApiResponse<IInvoicesResult>>
192
198
 
193
199
  interface IConfigAdminClientOptions {
194
200
  baseUrl: string;
@@ -516,6 +522,10 @@ interface IAuditPageResult {
516
522
  nextCursor: string | null;
517
523
  }
518
524
 
525
+ interface ICancelSubscriptionInput {
526
+ atPeriodEnd?: boolean;
527
+ }
528
+
519
529
  interface ICheckoutUrlResult {
520
530
  url: string;
521
531
  }
@@ -722,6 +732,22 @@ interface IInviteResult {
722
732
  }>;
723
733
  }
724
734
 
735
+ interface IInvoiceDTO {
736
+ id: string;
737
+ number: string | null;
738
+ amountDue: string;
739
+ amountPaid: string;
740
+ currency: string;
741
+ status: string;
742
+ created: string;
743
+ hostedInvoiceUrl: string | null;
744
+ invoicePdf: string | null;
745
+ }
746
+
747
+ interface IInvoicesResult {
748
+ invoices: IInvoiceDTO[];
749
+ }
750
+
725
751
  interface ILoginResult {
726
752
  tokens: ITokens;
727
753
  user: IUserDTO;
@@ -762,6 +788,17 @@ interface IMfaSetupResult {
762
788
  backupCodes: string[];
763
789
  }
764
790
 
791
+ interface IPaymentMethodDTO {
792
+ brand: string;
793
+ last4: string;
794
+ expMonth: number;
795
+ expYear: number;
796
+ }
797
+
798
+ interface IPaymentMethodResult {
799
+ paymentMethod: IPaymentMethodDTO | null;
800
+ }
801
+
765
802
  interface IPlanDTO {
766
803
  id: string;
767
804
  planId: string;
@@ -857,6 +894,12 @@ interface ISecretRevision {
857
894
  createdAt: string;
858
895
  }
859
896
 
897
+ interface ISubscriptionChangeResult {
898
+ atPeriodEnd: boolean;
899
+ status: string;
900
+ currentPeriodEnd: string | null;
901
+ }
902
+
860
903
  interface ISubscriptionDTO {
861
904
  id: string;
862
905
  subscriberType: SubscriberType;
@@ -954,6 +997,10 @@ interface IVerifyEmailResult {
954
997
  email: string;
955
998
  }
956
999
 
1000
+ interface IWalletCheckoutInput {
1001
+ packId: string;
1002
+ }
1003
+
957
1004
  interface IWalletDTO {
958
1005
  balance: string;
959
1006
  currency: string;
@@ -968,6 +1015,23 @@ interface IWalletResult {
968
1015
  wallet: IWalletDTO;
969
1016
  }
970
1017
 
1018
+ interface IWalletTransactionDTO {
1019
+ id: string;
1020
+ type: string;
1021
+ amount: string;
1022
+ balanceAfter: string;
1023
+ currency: string;
1024
+ description: string | null;
1025
+ providerTxId: string | null;
1026
+ metadata: Record<string, unknown>;
1027
+ createdAt: string;
1028
+ }
1029
+
1030
+ interface IWalletTransactionsResult {
1031
+ transactions: IWalletTransactionDTO[];
1032
+ nextCursor: string | null;
1033
+ }
1034
+
971
1035
  interface IWebhookDeliveryDTO {
972
1036
  id: string;
973
1037
  eventId: string;
package/dist/index.cjs CHANGED
@@ -456,6 +456,28 @@ var BillingClient = class {
456
456
  bust: opts?.bust
457
457
  });
458
458
  }
459
+ // First-party cancel — no portal round-trip. Default keeps access until the
460
+ // paid-through date; pass { atPeriodEnd: false } to end it immediately. 501
461
+ // when the provider has no first-party cancel (the portal remains a fallback).
462
+ cancelSubscription(input) {
463
+ return this.http.request({
464
+ method: "POST",
465
+ path: "/billing/subscription/cancel",
466
+ body: input ?? {},
467
+ token: this.tokens.get(),
468
+ workspaceId: this.workspaceId
469
+ });
470
+ }
471
+ // Un-cancel a subscription scheduled to cancel at period end. Idempotent; 409
472
+ // when the subscription is already fully canceled (start a new checkout).
473
+ reactivateSubscription() {
474
+ return this.http.request({
475
+ method: "POST",
476
+ path: "/billing/subscription/reactivate",
477
+ token: this.tokens.get(),
478
+ workspaceId: this.workspaceId
479
+ });
480
+ }
459
481
  // ── Checkout / portal ────────────────────────────────────────────────────────
460
482
  createCheckoutSession(input) {
461
483
  return this.http.request({
@@ -512,6 +534,55 @@ var BillingClient = class {
512
534
  workspaceId: this.workspaceId
513
535
  });
514
536
  }
537
+ // Start a one-time credit-pack purchase. Returns a hosted checkout URL to
538
+ // redirect the buyer to; the wallet is credited by the payment webhook.
539
+ createWalletCheckout(input) {
540
+ return this.http.request({
541
+ method: "POST",
542
+ path: "/billing/wallet/checkout",
543
+ body: input,
544
+ token: this.tokens.get(),
545
+ workspaceId: this.workspaceId
546
+ });
547
+ }
548
+ // The wallet ledger, newest first — every credit/debit with a running
549
+ // balanceAfter. Cursor-paginated: pass the previous result's `nextCursor`.
550
+ getWalletTransactions(opts) {
551
+ const params = new URLSearchParams();
552
+ if (opts?.cursor) params.set("cursor", opts.cursor);
553
+ if (opts?.limit !== void 0) params.set("limit", String(opts.limit));
554
+ const qs = params.toString();
555
+ return this.http.request({
556
+ method: "GET",
557
+ path: `/billing/wallet/transactions${qs ? "?" + qs : ""}`,
558
+ token: this.tokens.get(),
559
+ workspaceId: this.workspaceId,
560
+ bust: opts?.bust
561
+ });
562
+ }
563
+ // ── Account ──────────────────────────────────────────────────────────────────
564
+ // The customer's card on file (brand/last4/expiry), or { paymentMethod: null }
565
+ // when none is stored. 501 when the provider can't retrieve it.
566
+ getPaymentMethod(opts) {
567
+ return this.http.request({
568
+ method: "GET",
569
+ path: "/billing/payment-method",
570
+ token: this.tokens.get(),
571
+ workspaceId: this.workspaceId,
572
+ bust: opts?.bust
573
+ });
574
+ }
575
+ // The customer's invoices, newest first — each links out to the hosted
576
+ // invoice / PDF. 501 when the provider can't list them.
577
+ listInvoices(opts) {
578
+ return this.http.request({
579
+ method: "GET",
580
+ path: "/billing/invoices",
581
+ token: this.tokens.get(),
582
+ workspaceId: this.workspaceId,
583
+ bust: opts?.bust
584
+ });
585
+ }
515
586
  };
516
587
 
517
588
  // src/modules/customers.ts