@fonderie/billing 5.3.1 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -0
- package/brain/outcomes.md +71 -0
- package/brain/signatures.md +191 -17
- package/dist/{index-Byy5mBE4.d.ts → index-BdNYDuhk.d.ts} +107 -9
- package/dist/{index-DjAGcrSi.d.cts → index-Ca4pXx07.d.cts} +107 -9
- package/dist/index.cjs +1097 -146
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +137 -15
- package/dist/index.d.ts +137 -15
- package/dist/index.js +1076 -145
- package/dist/index.js.map +1 -1
- package/dist/middlewares/index.cjs +180 -0
- package/dist/middlewares/index.cjs.map +1 -1
- package/dist/middlewares/index.d.cts +1 -1
- package/dist/middlewares/index.d.ts +1 -1
- package/dist/middlewares/index.js +180 -0
- package/dist/middlewares/index.js.map +1 -1
- package/dist/migrations/sql/006_wallet.sql +85 -0
- package/dist/types.cjs +17 -3
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +34 -7
- package/dist/types.d.ts +34 -7
- package/dist/types.js +13 -2
- package/dist/types.js.map +1 -1
- package/package.json +4 -4
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { IFonderieModule, IFonderieApp, IFonderieContext, Middleware } from '@fonderie/core';
|
|
2
2
|
import { IStoreAdapter } from '@fonderie/store';
|
|
3
|
-
import { I as IBillingConfig, a as IBillingProvider, b as IResolvedPrice, c as IBillingEvent, d as
|
|
4
|
-
export { B as BillingMessageKey, f as
|
|
5
|
-
import { SubscriberType, IPolicyStatus, IPlanFeature, IPlan, ISubscription
|
|
6
|
-
export { BILLING_INTERVAL, BillingInterval, IBillingContext, LimitStatus, PolicyEntry, SubscriptionStatus } from './types.cjs';
|
|
3
|
+
import { I as IBillingConfig, a as IBillingProvider, b as IResolvedPrice, c as IBillingEvent, d as IBillingPlan, e as ICounterBackend } from './index-Ca4pXx07.cjs';
|
|
4
|
+
export { B as BillingMessageKey, f as IBillingCreditPack, g as IBillingNotificationsConfig, h as IBillingPlanDefaults, i as IBillingPlanPrice, j as IBillingPlanWallet, k as IBillingPricingConfig, l as IBillingWalletConfig, m as INormalizedPayment, M as MESSAGE_KEYS, R as RateLimitBackendConfig, r as requirePlan, w as withBilling } from './index-Ca4pXx07.cjs';
|
|
5
|
+
import { SubscriberType, IWalletRate, IWalletLedgerEntry, WalletLedgerType, IWalletBalance, IPolicyStatus, IWalletContext, IPlanFeature, IPlan, ISubscription } from './types.cjs';
|
|
6
|
+
export { BILLING_INTERVAL, BILLING_INTERVALS, BillingInterval, IBillingContext, LimitStatus, PolicyEntry, SubscriptionStatus, WALLET_LEDGER_TYPES, isBillingInterval } from './types.cjs';
|
|
7
7
|
import { z } from 'zod';
|
|
8
8
|
|
|
9
9
|
declare class BillingModule implements IFonderieModule {
|
|
@@ -40,6 +40,20 @@ declare class StripeProvider implements IBillingProvider {
|
|
|
40
40
|
}): Promise<{
|
|
41
41
|
url: string;
|
|
42
42
|
}>;
|
|
43
|
+
createPaymentCheckoutSession(opts: {
|
|
44
|
+
customerId: string;
|
|
45
|
+
amount: bigint;
|
|
46
|
+
currency: string;
|
|
47
|
+
name: string;
|
|
48
|
+
quantity?: number;
|
|
49
|
+
priceId?: string;
|
|
50
|
+
metadata: Record<string, string>;
|
|
51
|
+
successUrl: string;
|
|
52
|
+
cancelUrl: string;
|
|
53
|
+
}): Promise<{
|
|
54
|
+
url: string;
|
|
55
|
+
sessionId: string;
|
|
56
|
+
}>;
|
|
43
57
|
resolvePriceById(priceId: string): Promise<IResolvedPrice | null>;
|
|
44
58
|
resolvePricesByLookupKey(lookupKeys: string[]): Promise<Map<string, IResolvedPrice>>;
|
|
45
59
|
updateSubscription(opts: {
|
|
@@ -63,9 +77,92 @@ declare class StripeProvider implements IBillingProvider {
|
|
|
63
77
|
}): Promise<IBillingEvent>;
|
|
64
78
|
}
|
|
65
79
|
|
|
80
|
+
declare class InsufficientFundsError extends Error {
|
|
81
|
+
readonly available: bigint;
|
|
82
|
+
readonly required: bigint;
|
|
83
|
+
readonly currency: string;
|
|
84
|
+
constructor(available: bigint, required: bigint, currency: string);
|
|
85
|
+
}
|
|
86
|
+
declare class DuplicateTransactionError extends Error {
|
|
87
|
+
readonly idempotencyKey: string;
|
|
88
|
+
constructor(idempotencyKey: string);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
interface IWalletSubscriber {
|
|
92
|
+
subscriberType: SubscriberType;
|
|
93
|
+
subscriberId: string;
|
|
94
|
+
currency: string;
|
|
95
|
+
}
|
|
96
|
+
interface IWalletMutationResult {
|
|
97
|
+
balance: bigint;
|
|
98
|
+
duplicate: boolean;
|
|
99
|
+
}
|
|
100
|
+
declare function creditWallet(opts: IWalletSubscriber & {
|
|
101
|
+
amount: bigint;
|
|
102
|
+
idempotencyKey: string;
|
|
103
|
+
type?: WalletLedgerType;
|
|
104
|
+
description?: string;
|
|
105
|
+
metadata?: Record<string, unknown>;
|
|
106
|
+
providerTxId?: string;
|
|
107
|
+
}, store: IStoreAdapter): Promise<IWalletMutationResult>;
|
|
108
|
+
declare function debitWallet(opts: IWalletSubscriber & {
|
|
109
|
+
amount: bigint;
|
|
110
|
+
idempotencyKey: string;
|
|
111
|
+
type?: WalletLedgerType;
|
|
112
|
+
overdraftLimit?: bigint;
|
|
113
|
+
description?: string;
|
|
114
|
+
metadata?: Record<string, unknown>;
|
|
115
|
+
}, store: IStoreAdapter): Promise<IWalletMutationResult>;
|
|
116
|
+
declare function getWalletBalance(sub: IWalletSubscriber, store: IStoreAdapter): Promise<IWalletBalance>;
|
|
117
|
+
interface IWalletLedgerPage {
|
|
118
|
+
entries: IWalletLedgerEntry[];
|
|
119
|
+
nextCursor: string | null;
|
|
120
|
+
}
|
|
121
|
+
declare function encodeLedgerCursor(createdAt: string, id: string): string;
|
|
122
|
+
declare function decodeLedgerCursor(cursor: string): {
|
|
123
|
+
createdAt: string;
|
|
124
|
+
id: string;
|
|
125
|
+
} | null;
|
|
126
|
+
declare function getWalletLedger(opts: IWalletSubscriber & {
|
|
127
|
+
limit?: number;
|
|
128
|
+
cursor?: {
|
|
129
|
+
createdAt: string;
|
|
130
|
+
id: string;
|
|
131
|
+
};
|
|
132
|
+
}, store: IStoreAdapter): Promise<IWalletLedgerPage>;
|
|
133
|
+
interface IResolvedPlanWallet {
|
|
134
|
+
currency: string;
|
|
135
|
+
precision: number;
|
|
136
|
+
overdraftLimit: bigint;
|
|
137
|
+
grantAmount: bigint | null;
|
|
138
|
+
grantPeriod: 'month' | 'week' | 'day';
|
|
139
|
+
rates: Record<string, IWalletRate>;
|
|
140
|
+
}
|
|
141
|
+
declare function resolvePlanWallet(plan: IBillingPlan, config: IBillingConfig): IResolvedPlanWallet | null;
|
|
142
|
+
declare function currentGrantPeriod(period: 'month' | 'week' | 'day', now?: Date): string;
|
|
143
|
+
interface IGrantResult {
|
|
144
|
+
granted: boolean;
|
|
145
|
+
balance: bigint | null;
|
|
146
|
+
}
|
|
147
|
+
declare function ensurePeriodicGrant(opts: IWalletSubscriber & {
|
|
148
|
+
amount: bigint;
|
|
149
|
+
period: string;
|
|
150
|
+
description?: string;
|
|
151
|
+
}, store: IStoreAdapter): Promise<IGrantResult>;
|
|
152
|
+
|
|
66
153
|
declare function hasFeature(ctx: IFonderieContext, key: string): boolean;
|
|
67
154
|
declare function getPlanLimit(ctx: IFonderieContext, key: string): number | null;
|
|
68
155
|
declare function getLimitStatus(ctx: IFonderieContext, key: string): IPolicyStatus | null;
|
|
156
|
+
declare function getWalletStatus(ctx: IFonderieContext): IWalletContext | null;
|
|
157
|
+
declare function getWalletRate(ctx: IFonderieContext, metric: string): bigint | null;
|
|
158
|
+
declare function requireWalletBalance(metric: string): Middleware;
|
|
159
|
+
declare function debitWalletForMetric(ctx: IFonderieContext, metric: string, opts: {
|
|
160
|
+
idempotencyKey: string;
|
|
161
|
+
quantity?: number;
|
|
162
|
+
description?: string;
|
|
163
|
+
metadata?: Record<string, unknown>;
|
|
164
|
+
}, store: IStoreAdapter): Promise<IWalletMutationResult | null>;
|
|
165
|
+
declare function insufficientCreditsResponse(err: InsufficientFundsError, metric?: string): Response;
|
|
69
166
|
declare function requireFeature(key: string): Middleware;
|
|
70
167
|
|
|
71
168
|
declare class MemoryCounterBackend implements ICounterBackend {
|
|
@@ -112,17 +209,26 @@ interface ISubscriptionDTO {
|
|
|
112
209
|
trialEndsAt: string | null;
|
|
113
210
|
createdAt: string;
|
|
114
211
|
}
|
|
115
|
-
interface IUsageRecordDTO {
|
|
116
|
-
id: string;
|
|
117
|
-
subscriberType: SubscriberType;
|
|
118
|
-
subscriberId: string;
|
|
119
|
-
metric: string;
|
|
120
|
-
quantity: number;
|
|
121
|
-
recordedAt: string;
|
|
122
|
-
}
|
|
123
212
|
declare function toPlanDTO(plan: IPlan): IPlanDTO;
|
|
124
213
|
declare function toSubscriptionDTO(sub: ISubscription): ISubscriptionDTO;
|
|
125
|
-
|
|
214
|
+
interface IWalletDTO {
|
|
215
|
+
balance: string;
|
|
216
|
+
currency: string;
|
|
217
|
+
precision: number;
|
|
218
|
+
}
|
|
219
|
+
interface IWalletTransactionDTO {
|
|
220
|
+
id: string;
|
|
221
|
+
type: WalletLedgerType;
|
|
222
|
+
amount: string;
|
|
223
|
+
balanceAfter: string;
|
|
224
|
+
currency: string;
|
|
225
|
+
description: string | null;
|
|
226
|
+
providerTxId: string | null;
|
|
227
|
+
metadata: Record<string, unknown>;
|
|
228
|
+
createdAt: string;
|
|
229
|
+
}
|
|
230
|
+
declare function toWalletDTO(balance: bigint, currency: string, precision: number): IWalletDTO;
|
|
231
|
+
declare function toWalletTransactionDTO(entry: IWalletLedgerEntry): IWalletTransactionDTO;
|
|
126
232
|
|
|
127
233
|
declare function recordUsage(opts: {
|
|
128
234
|
subscriberType: SubscriberType;
|
|
@@ -191,13 +297,29 @@ declare const recordUsageSchema: z.ZodObject<{
|
|
|
191
297
|
metric: z.ZodString;
|
|
192
298
|
quantity: z.ZodOptional<z.ZodNumber>;
|
|
193
299
|
}, z.core.$strip>;
|
|
300
|
+
declare const walletCheckoutSchema: z.ZodObject<{
|
|
301
|
+
packId: z.ZodString;
|
|
302
|
+
}, z.core.$strip>;
|
|
303
|
+
declare const grantWalletSchema: z.ZodObject<{
|
|
304
|
+
subscriberType: z.ZodEnum<{
|
|
305
|
+
user: "user";
|
|
306
|
+
workspace: "workspace";
|
|
307
|
+
}>;
|
|
308
|
+
subscriberId: z.ZodString;
|
|
309
|
+
amount: z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodTransform<bigint, string | number>>;
|
|
310
|
+
currency: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>;
|
|
311
|
+
description: z.ZodOptional<z.ZodString>;
|
|
312
|
+
idempotencyKey: z.ZodString;
|
|
313
|
+
}, z.core.$strip>;
|
|
194
314
|
|
|
195
315
|
declare const schemas_checkoutSchema: typeof checkoutSchema;
|
|
196
316
|
declare const schemas_createPlanSchema: typeof createPlanSchema;
|
|
317
|
+
declare const schemas_grantWalletSchema: typeof grantWalletSchema;
|
|
197
318
|
declare const schemas_recordUsageSchema: typeof recordUsageSchema;
|
|
198
319
|
declare const schemas_updatePlanSchema: typeof updatePlanSchema;
|
|
320
|
+
declare const schemas_walletCheckoutSchema: typeof walletCheckoutSchema;
|
|
199
321
|
declare namespace schemas {
|
|
200
|
-
export { schemas_checkoutSchema as checkoutSchema, schemas_createPlanSchema as createPlanSchema, schemas_recordUsageSchema as recordUsageSchema, schemas_updatePlanSchema as updatePlanSchema };
|
|
322
|
+
export { schemas_checkoutSchema as checkoutSchema, schemas_createPlanSchema as createPlanSchema, schemas_grantWalletSchema as grantWalletSchema, schemas_recordUsageSchema as recordUsageSchema, schemas_updatePlanSchema as updatePlanSchema, schemas_walletCheckoutSchema as walletCheckoutSchema };
|
|
201
323
|
}
|
|
202
324
|
|
|
203
|
-
export { BillingModule, DBCounterBackend, IBillingConfig, IBillingEvent, IBillingPlan, IBillingProvider, ICounterBackend, IPlan, type IPlanDTO, IPolicyStatus, IResolvedPrice, ISubscription, type ISubscriptionDTO,
|
|
325
|
+
export { BillingModule, DBCounterBackend, DuplicateTransactionError, IBillingConfig, IBillingEvent, IBillingPlan, IBillingProvider, ICounterBackend, type IGrantResult, IPlan, type IPlanDTO, IPolicyStatus, type IResolvedPlanWallet, IResolvedPrice, ISubscription, type ISubscriptionDTO, IWalletBalance, IWalletContext, type IWalletDTO, IWalletLedgerEntry, type IWalletLedgerPage, type IWalletMutationResult, IWalletRate, type IWalletSubscriber, type IWalletTransactionDTO, InsufficientFundsError, MemoryCounterBackend, StripeProvider, WalletLedgerType, createPlan, creditWallet, currentGrantPeriod, debitWallet, debitWalletForMetric, decodeLedgerCursor, deletePlan, encodeLedgerCursor, ensurePeriodicGrant, getDBPlans, getLimitStatus, getPlanById, getPlanByName, getPlanLimit, getPlans, getSubscription, getUsage, getWalletBalance, getWalletLedger, getWalletRate, getWalletStatus, hasFeature, insufficientCreditsResponse, recordUsage, requireFeature, requireWalletBalance, resolvePlanWallet, schemas, toPlanDTO, toSubscriptionDTO, toWalletDTO, toWalletTransactionDTO, updatePlan };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { IFonderieModule, IFonderieApp, IFonderieContext, Middleware } from '@fonderie/core';
|
|
2
2
|
import { IStoreAdapter } from '@fonderie/store';
|
|
3
|
-
import { I as IBillingConfig, a as IBillingProvider, b as IResolvedPrice, c as IBillingEvent, d as
|
|
4
|
-
export { B as BillingMessageKey, f as
|
|
5
|
-
import { SubscriberType, IPolicyStatus, IPlanFeature, IPlan, ISubscription
|
|
6
|
-
export { BILLING_INTERVAL, BillingInterval, IBillingContext, LimitStatus, PolicyEntry, SubscriptionStatus } from './types.js';
|
|
3
|
+
import { I as IBillingConfig, a as IBillingProvider, b as IResolvedPrice, c as IBillingEvent, d as IBillingPlan, e as ICounterBackend } from './index-BdNYDuhk.js';
|
|
4
|
+
export { B as BillingMessageKey, f as IBillingCreditPack, g as IBillingNotificationsConfig, h as IBillingPlanDefaults, i as IBillingPlanPrice, j as IBillingPlanWallet, k as IBillingPricingConfig, l as IBillingWalletConfig, m as INormalizedPayment, M as MESSAGE_KEYS, R as RateLimitBackendConfig, r as requirePlan, w as withBilling } from './index-BdNYDuhk.js';
|
|
5
|
+
import { SubscriberType, IWalletRate, IWalletLedgerEntry, WalletLedgerType, IWalletBalance, IPolicyStatus, IWalletContext, IPlanFeature, IPlan, ISubscription } from './types.js';
|
|
6
|
+
export { BILLING_INTERVAL, BILLING_INTERVALS, BillingInterval, IBillingContext, LimitStatus, PolicyEntry, SubscriptionStatus, WALLET_LEDGER_TYPES, isBillingInterval } from './types.js';
|
|
7
7
|
import { z } from 'zod';
|
|
8
8
|
|
|
9
9
|
declare class BillingModule implements IFonderieModule {
|
|
@@ -40,6 +40,20 @@ declare class StripeProvider implements IBillingProvider {
|
|
|
40
40
|
}): Promise<{
|
|
41
41
|
url: string;
|
|
42
42
|
}>;
|
|
43
|
+
createPaymentCheckoutSession(opts: {
|
|
44
|
+
customerId: string;
|
|
45
|
+
amount: bigint;
|
|
46
|
+
currency: string;
|
|
47
|
+
name: string;
|
|
48
|
+
quantity?: number;
|
|
49
|
+
priceId?: string;
|
|
50
|
+
metadata: Record<string, string>;
|
|
51
|
+
successUrl: string;
|
|
52
|
+
cancelUrl: string;
|
|
53
|
+
}): Promise<{
|
|
54
|
+
url: string;
|
|
55
|
+
sessionId: string;
|
|
56
|
+
}>;
|
|
43
57
|
resolvePriceById(priceId: string): Promise<IResolvedPrice | null>;
|
|
44
58
|
resolvePricesByLookupKey(lookupKeys: string[]): Promise<Map<string, IResolvedPrice>>;
|
|
45
59
|
updateSubscription(opts: {
|
|
@@ -63,9 +77,92 @@ declare class StripeProvider implements IBillingProvider {
|
|
|
63
77
|
}): Promise<IBillingEvent>;
|
|
64
78
|
}
|
|
65
79
|
|
|
80
|
+
declare class InsufficientFundsError extends Error {
|
|
81
|
+
readonly available: bigint;
|
|
82
|
+
readonly required: bigint;
|
|
83
|
+
readonly currency: string;
|
|
84
|
+
constructor(available: bigint, required: bigint, currency: string);
|
|
85
|
+
}
|
|
86
|
+
declare class DuplicateTransactionError extends Error {
|
|
87
|
+
readonly idempotencyKey: string;
|
|
88
|
+
constructor(idempotencyKey: string);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
interface IWalletSubscriber {
|
|
92
|
+
subscriberType: SubscriberType;
|
|
93
|
+
subscriberId: string;
|
|
94
|
+
currency: string;
|
|
95
|
+
}
|
|
96
|
+
interface IWalletMutationResult {
|
|
97
|
+
balance: bigint;
|
|
98
|
+
duplicate: boolean;
|
|
99
|
+
}
|
|
100
|
+
declare function creditWallet(opts: IWalletSubscriber & {
|
|
101
|
+
amount: bigint;
|
|
102
|
+
idempotencyKey: string;
|
|
103
|
+
type?: WalletLedgerType;
|
|
104
|
+
description?: string;
|
|
105
|
+
metadata?: Record<string, unknown>;
|
|
106
|
+
providerTxId?: string;
|
|
107
|
+
}, store: IStoreAdapter): Promise<IWalletMutationResult>;
|
|
108
|
+
declare function debitWallet(opts: IWalletSubscriber & {
|
|
109
|
+
amount: bigint;
|
|
110
|
+
idempotencyKey: string;
|
|
111
|
+
type?: WalletLedgerType;
|
|
112
|
+
overdraftLimit?: bigint;
|
|
113
|
+
description?: string;
|
|
114
|
+
metadata?: Record<string, unknown>;
|
|
115
|
+
}, store: IStoreAdapter): Promise<IWalletMutationResult>;
|
|
116
|
+
declare function getWalletBalance(sub: IWalletSubscriber, store: IStoreAdapter): Promise<IWalletBalance>;
|
|
117
|
+
interface IWalletLedgerPage {
|
|
118
|
+
entries: IWalletLedgerEntry[];
|
|
119
|
+
nextCursor: string | null;
|
|
120
|
+
}
|
|
121
|
+
declare function encodeLedgerCursor(createdAt: string, id: string): string;
|
|
122
|
+
declare function decodeLedgerCursor(cursor: string): {
|
|
123
|
+
createdAt: string;
|
|
124
|
+
id: string;
|
|
125
|
+
} | null;
|
|
126
|
+
declare function getWalletLedger(opts: IWalletSubscriber & {
|
|
127
|
+
limit?: number;
|
|
128
|
+
cursor?: {
|
|
129
|
+
createdAt: string;
|
|
130
|
+
id: string;
|
|
131
|
+
};
|
|
132
|
+
}, store: IStoreAdapter): Promise<IWalletLedgerPage>;
|
|
133
|
+
interface IResolvedPlanWallet {
|
|
134
|
+
currency: string;
|
|
135
|
+
precision: number;
|
|
136
|
+
overdraftLimit: bigint;
|
|
137
|
+
grantAmount: bigint | null;
|
|
138
|
+
grantPeriod: 'month' | 'week' | 'day';
|
|
139
|
+
rates: Record<string, IWalletRate>;
|
|
140
|
+
}
|
|
141
|
+
declare function resolvePlanWallet(plan: IBillingPlan, config: IBillingConfig): IResolvedPlanWallet | null;
|
|
142
|
+
declare function currentGrantPeriod(period: 'month' | 'week' | 'day', now?: Date): string;
|
|
143
|
+
interface IGrantResult {
|
|
144
|
+
granted: boolean;
|
|
145
|
+
balance: bigint | null;
|
|
146
|
+
}
|
|
147
|
+
declare function ensurePeriodicGrant(opts: IWalletSubscriber & {
|
|
148
|
+
amount: bigint;
|
|
149
|
+
period: string;
|
|
150
|
+
description?: string;
|
|
151
|
+
}, store: IStoreAdapter): Promise<IGrantResult>;
|
|
152
|
+
|
|
66
153
|
declare function hasFeature(ctx: IFonderieContext, key: string): boolean;
|
|
67
154
|
declare function getPlanLimit(ctx: IFonderieContext, key: string): number | null;
|
|
68
155
|
declare function getLimitStatus(ctx: IFonderieContext, key: string): IPolicyStatus | null;
|
|
156
|
+
declare function getWalletStatus(ctx: IFonderieContext): IWalletContext | null;
|
|
157
|
+
declare function getWalletRate(ctx: IFonderieContext, metric: string): bigint | null;
|
|
158
|
+
declare function requireWalletBalance(metric: string): Middleware;
|
|
159
|
+
declare function debitWalletForMetric(ctx: IFonderieContext, metric: string, opts: {
|
|
160
|
+
idempotencyKey: string;
|
|
161
|
+
quantity?: number;
|
|
162
|
+
description?: string;
|
|
163
|
+
metadata?: Record<string, unknown>;
|
|
164
|
+
}, store: IStoreAdapter): Promise<IWalletMutationResult | null>;
|
|
165
|
+
declare function insufficientCreditsResponse(err: InsufficientFundsError, metric?: string): Response;
|
|
69
166
|
declare function requireFeature(key: string): Middleware;
|
|
70
167
|
|
|
71
168
|
declare class MemoryCounterBackend implements ICounterBackend {
|
|
@@ -112,17 +209,26 @@ interface ISubscriptionDTO {
|
|
|
112
209
|
trialEndsAt: string | null;
|
|
113
210
|
createdAt: string;
|
|
114
211
|
}
|
|
115
|
-
interface IUsageRecordDTO {
|
|
116
|
-
id: string;
|
|
117
|
-
subscriberType: SubscriberType;
|
|
118
|
-
subscriberId: string;
|
|
119
|
-
metric: string;
|
|
120
|
-
quantity: number;
|
|
121
|
-
recordedAt: string;
|
|
122
|
-
}
|
|
123
212
|
declare function toPlanDTO(plan: IPlan): IPlanDTO;
|
|
124
213
|
declare function toSubscriptionDTO(sub: ISubscription): ISubscriptionDTO;
|
|
125
|
-
|
|
214
|
+
interface IWalletDTO {
|
|
215
|
+
balance: string;
|
|
216
|
+
currency: string;
|
|
217
|
+
precision: number;
|
|
218
|
+
}
|
|
219
|
+
interface IWalletTransactionDTO {
|
|
220
|
+
id: string;
|
|
221
|
+
type: WalletLedgerType;
|
|
222
|
+
amount: string;
|
|
223
|
+
balanceAfter: string;
|
|
224
|
+
currency: string;
|
|
225
|
+
description: string | null;
|
|
226
|
+
providerTxId: string | null;
|
|
227
|
+
metadata: Record<string, unknown>;
|
|
228
|
+
createdAt: string;
|
|
229
|
+
}
|
|
230
|
+
declare function toWalletDTO(balance: bigint, currency: string, precision: number): IWalletDTO;
|
|
231
|
+
declare function toWalletTransactionDTO(entry: IWalletLedgerEntry): IWalletTransactionDTO;
|
|
126
232
|
|
|
127
233
|
declare function recordUsage(opts: {
|
|
128
234
|
subscriberType: SubscriberType;
|
|
@@ -191,13 +297,29 @@ declare const recordUsageSchema: z.ZodObject<{
|
|
|
191
297
|
metric: z.ZodString;
|
|
192
298
|
quantity: z.ZodOptional<z.ZodNumber>;
|
|
193
299
|
}, z.core.$strip>;
|
|
300
|
+
declare const walletCheckoutSchema: z.ZodObject<{
|
|
301
|
+
packId: z.ZodString;
|
|
302
|
+
}, z.core.$strip>;
|
|
303
|
+
declare const grantWalletSchema: z.ZodObject<{
|
|
304
|
+
subscriberType: z.ZodEnum<{
|
|
305
|
+
user: "user";
|
|
306
|
+
workspace: "workspace";
|
|
307
|
+
}>;
|
|
308
|
+
subscriberId: z.ZodString;
|
|
309
|
+
amount: z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodTransform<bigint, string | number>>;
|
|
310
|
+
currency: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>;
|
|
311
|
+
description: z.ZodOptional<z.ZodString>;
|
|
312
|
+
idempotencyKey: z.ZodString;
|
|
313
|
+
}, z.core.$strip>;
|
|
194
314
|
|
|
195
315
|
declare const schemas_checkoutSchema: typeof checkoutSchema;
|
|
196
316
|
declare const schemas_createPlanSchema: typeof createPlanSchema;
|
|
317
|
+
declare const schemas_grantWalletSchema: typeof grantWalletSchema;
|
|
197
318
|
declare const schemas_recordUsageSchema: typeof recordUsageSchema;
|
|
198
319
|
declare const schemas_updatePlanSchema: typeof updatePlanSchema;
|
|
320
|
+
declare const schemas_walletCheckoutSchema: typeof walletCheckoutSchema;
|
|
199
321
|
declare namespace schemas {
|
|
200
|
-
export { schemas_checkoutSchema as checkoutSchema, schemas_createPlanSchema as createPlanSchema, schemas_recordUsageSchema as recordUsageSchema, schemas_updatePlanSchema as updatePlanSchema };
|
|
322
|
+
export { schemas_checkoutSchema as checkoutSchema, schemas_createPlanSchema as createPlanSchema, schemas_grantWalletSchema as grantWalletSchema, schemas_recordUsageSchema as recordUsageSchema, schemas_updatePlanSchema as updatePlanSchema, schemas_walletCheckoutSchema as walletCheckoutSchema };
|
|
201
323
|
}
|
|
202
324
|
|
|
203
|
-
export { BillingModule, DBCounterBackend, IBillingConfig, IBillingEvent, IBillingPlan, IBillingProvider, ICounterBackend, IPlan, type IPlanDTO, IPolicyStatus, IResolvedPrice, ISubscription, type ISubscriptionDTO,
|
|
325
|
+
export { BillingModule, DBCounterBackend, DuplicateTransactionError, IBillingConfig, IBillingEvent, IBillingPlan, IBillingProvider, ICounterBackend, type IGrantResult, IPlan, type IPlanDTO, IPolicyStatus, type IResolvedPlanWallet, IResolvedPrice, ISubscription, type ISubscriptionDTO, IWalletBalance, IWalletContext, type IWalletDTO, IWalletLedgerEntry, type IWalletLedgerPage, type IWalletMutationResult, IWalletRate, type IWalletSubscriber, type IWalletTransactionDTO, InsufficientFundsError, MemoryCounterBackend, StripeProvider, WalletLedgerType, createPlan, creditWallet, currentGrantPeriod, debitWallet, debitWalletForMetric, decodeLedgerCursor, deletePlan, encodeLedgerCursor, ensurePeriodicGrant, getDBPlans, getLimitStatus, getPlanById, getPlanByName, getPlanLimit, getPlans, getSubscription, getUsage, getWalletBalance, getWalletLedger, getWalletRate, getWalletStatus, hasFeature, insufficientCreditsResponse, recordUsage, requireFeature, requireWalletBalance, resolvePlanWallet, schemas, toPlanDTO, toSubscriptionDTO, toWalletDTO, toWalletTransactionDTO, updatePlan };
|