@fonderie/client 0.26.0 → 0.28.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.
@@ -305,6 +305,49 @@ new AuthAdminClient(opts: IAuthAdminClientOptions): AuthAdminClient
305
305
  .suspendUser(id: string): Promise<IApiResponse<IAdminUserDTO>>
306
306
  .unsuspendUser(id: string): Promise<IApiResponse<IAdminUserDTO>>
307
307
 
308
+ interface IBillingAdminClientOptions {
309
+ baseUrl: string;
310
+ adminToken: string;
311
+ prefix?: string;
312
+ actor?: string;
313
+ }
314
+
315
+ interface IAdminLedgerQuery {
316
+ currency?: string;
317
+ limit?: number;
318
+ cursor?: string;
319
+ }
320
+
321
+ new BillingAdminClient(opts: IBillingAdminClientOptions): BillingAdminClient
322
+ .catalog(): Promise<IApiResponse<IAdminCatalog>>
323
+ .createPlan(input: IAdminPlanInput & { name: string; }): Promise<IApiResponse<IPlanDTO>>
324
+ .updatePlan(planId: string, input: IAdminPlanInput): Promise<IApiResponse<IPlanDTO>>
325
+ .deletePlan(planId: string): Promise<IApiResponse<undefined>>
326
+ .subscription(type: SubscriberType, id: string): Promise<IApiResponse<IAdminSubscriptionDTO>>
327
+ .wallet(type: SubscriberType, id: string, currency?: string | undefined): Promise<IApiResponse<IAdminWalletDTO>>
328
+ .walletLedger(type: SubscriberType, id: string, query?: IAdminLedgerQuery): Promise<IApiResponse<IAdminWalletLedgerPage>>
329
+ .grant(input: IAdminGrantInput): Promise<IApiResponse<unknown>>
330
+
331
+ interface IAuditAdminClientOptions {
332
+ baseUrl: string;
333
+ adminToken: string;
334
+ prefix?: string;
335
+ actor?: string;
336
+ }
337
+
338
+ interface IAdminAuditQuery {
339
+ workspaceId?: string;
340
+ type?: string;
341
+ actorId?: string;
342
+ from?: Date;
343
+ to?: Date;
344
+ limit?: number;
345
+ cursor?: string;
346
+ }
347
+
348
+ new AuditAdminClient(opts: IAuditAdminClientOptions): AuditAdminClient
349
+ .listAudit(query?: IAdminAuditQuery): Promise<IApiResponse<IAuditPageResult>>
350
+
308
351
  interface ICourierAdminClientOptions {
309
352
  baseUrl: string;
310
353
  adminToken: string;
@@ -763,6 +806,61 @@ interface IAdminUserDTO extends IUserDTO {
763
806
  deletedAt: string | null;
764
807
  }
765
808
 
809
+ interface IAdminCatalog {
810
+ configured: unknown[];
811
+ stored: IPlanDTO[];
812
+ }
813
+
814
+ interface IAdminSubscriptionDTO {
815
+ id: string;
816
+ subscriberType: SubscriberType;
817
+ subscriberId: string;
818
+ plan: string;
819
+ interval: string;
820
+ status: string;
821
+ providerCustomerId: string | null;
822
+ providerSubscriptionId: string | null;
823
+ currentPeriodStart: string | null;
824
+ currentPeriodEnd: string | null;
825
+ cancelAtPeriodEnd: boolean;
826
+ trialEndsAt: string | null;
827
+ createdAt: string;
828
+ }
829
+
830
+ interface IAdminWalletDTO extends IWalletDTO {
831
+ version: number;
832
+ updatedAt: string | null;
833
+ }
834
+
835
+ interface IAdminWalletLedgerPage {
836
+ currency: string;
837
+ entries: IWalletTransactionDTO[];
838
+ nextCursor: string | null;
839
+ }
840
+
841
+ interface IAdminPlanInput {
842
+ name?: string;
843
+ description?: string | null;
844
+ tier?: number;
845
+ seats?: number | null;
846
+ trialDays?: number;
847
+ monthlyAmount?: number | null;
848
+ monthlyPriceId?: string | null;
849
+ yearlyAmount?: number | null;
850
+ yearlyPriceId?: string | null;
851
+ features?: unknown;
852
+ metadata?: unknown;
853
+ }
854
+
855
+ interface IAdminGrantInput {
856
+ subscriberType: SubscriberType;
857
+ subscriberId: string;
858
+ amount: string | number;
859
+ currency?: string;
860
+ description?: string;
861
+ idempotencyKey: string;
862
+ }
863
+
766
864
  interface IConfigEntry {
767
865
  key: string;
768
866
  value: unknown;
package/dist/index.cjs CHANGED
@@ -21,9 +21,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  AdminClient: () => AdminClient,
24
+ AuditAdminClient: () => AuditAdminClient,
24
25
  AuditClient: () => AuditClient,
25
26
  AuthAdminClient: () => AuthAdminClient,
26
27
  AuthClient: () => AuthClient,
28
+ BillingAdminClient: () => BillingAdminClient,
27
29
  BillingClient: () => BillingClient,
28
30
  ConfigAdminClient: () => ConfigAdminClient,
29
31
  CourierAdminClient: () => CourierAdminClient,
@@ -1836,6 +1838,98 @@ var AuthAdminClient = class {
1836
1838
  }
1837
1839
  };
1838
1840
 
1841
+ // src/modules/billing-admin.ts
1842
+ var BillingAdminClient = class {
1843
+ http;
1844
+ adminToken;
1845
+ prefix;
1846
+ actorHeaders;
1847
+ constructor(opts) {
1848
+ this.http = new HttpClient(opts.baseUrl);
1849
+ this.adminToken = opts.adminToken;
1850
+ this.prefix = (opts.prefix ?? "/_admin").replace(/\/+$/, "");
1851
+ this.actorHeaders = opts.actor ? { "X-Actor": opts.actor } : void 0;
1852
+ }
1853
+ call(method, suffix, body) {
1854
+ return this.http.request({
1855
+ method,
1856
+ path: `${this.prefix}${suffix}`,
1857
+ token: this.adminToken,
1858
+ headers: this.actorHeaders,
1859
+ ...body !== void 0 ? { body } : {}
1860
+ });
1861
+ }
1862
+ sub(type, id) {
1863
+ return `/${type}/${encodeURIComponent(id)}`;
1864
+ }
1865
+ catalog() {
1866
+ return this.call("GET", "/catalog");
1867
+ }
1868
+ createPlan(input) {
1869
+ return this.call("POST", "/plans", input);
1870
+ }
1871
+ updatePlan(planId, input) {
1872
+ return this.call("PUT", `/plans/${encodeURIComponent(planId)}`, input);
1873
+ }
1874
+ deletePlan(planId) {
1875
+ return this.call("DELETE", `/plans/${encodeURIComponent(planId)}`);
1876
+ }
1877
+ subscription(type, id) {
1878
+ return this.call("GET", `/subscriptions${this.sub(type, id)}`);
1879
+ }
1880
+ wallet(type, id, currency) {
1881
+ const qs = currency ? `?currency=${encodeURIComponent(currency)}` : "";
1882
+ return this.call("GET", `/wallet${this.sub(type, id)}${qs}`);
1883
+ }
1884
+ walletLedger(type, id, query = {}) {
1885
+ const q = new URLSearchParams();
1886
+ if (query.currency) q.set("currency", query.currency);
1887
+ if (query.limit) q.set("limit", String(query.limit));
1888
+ if (query.cursor) q.set("cursor", query.cursor);
1889
+ const qs = q.toString();
1890
+ return this.call(
1891
+ "GET",
1892
+ `/wallet${this.sub(type, id)}/ledger${qs ? `?${qs}` : ""}`
1893
+ );
1894
+ }
1895
+ // Manual credit — an idempotency key is required by the server.
1896
+ grant(input) {
1897
+ return this.call("POST", "/wallet/grant", input);
1898
+ }
1899
+ };
1900
+
1901
+ // src/modules/audit-admin.ts
1902
+ var AuditAdminClient = class {
1903
+ http;
1904
+ adminToken;
1905
+ prefix;
1906
+ actorHeaders;
1907
+ constructor(opts) {
1908
+ this.http = new HttpClient(opts.baseUrl);
1909
+ this.adminToken = opts.adminToken;
1910
+ this.prefix = (opts.prefix ?? "/_admin").replace(/\/+$/, "");
1911
+ this.actorHeaders = opts.actor ? { "X-Actor": opts.actor } : void 0;
1912
+ }
1913
+ // Every workspace unless one is named. Newest first, keyset-paged.
1914
+ listAudit(query = {}) {
1915
+ const q = new URLSearchParams();
1916
+ if (query.workspaceId) q.set("workspaceId", query.workspaceId);
1917
+ if (query.type) q.set("type", query.type);
1918
+ if (query.actorId) q.set("actorId", query.actorId);
1919
+ if (query.from) q.set("from", query.from.toISOString());
1920
+ if (query.to) q.set("to", query.to.toISOString());
1921
+ if (query.limit) q.set("limit", String(query.limit));
1922
+ if (query.cursor) q.set("cursor", query.cursor);
1923
+ const qs = q.toString();
1924
+ return this.http.request({
1925
+ method: "GET",
1926
+ path: `${this.prefix}/audit${qs ? `?${qs}` : ""}`,
1927
+ token: this.adminToken,
1928
+ headers: this.actorHeaders
1929
+ });
1930
+ }
1931
+ };
1932
+
1839
1933
  // src/modules/courier-admin.ts
1840
1934
  var CourierAdminClient = class {
1841
1935
  http;
@@ -1927,9 +2021,11 @@ function isMfaRequired(result) {
1927
2021
  // Annotate the CommonJS export names for ESM import in node:
1928
2022
  0 && (module.exports = {
1929
2023
  AdminClient,
2024
+ AuditAdminClient,
1930
2025
  AuditClient,
1931
2026
  AuthAdminClient,
1932
2027
  AuthClient,
2028
+ BillingAdminClient,
1933
2029
  BillingClient,
1934
2030
  ConfigAdminClient,
1935
2031
  CourierAdminClient,