@nehorai/credits 2.2.0 → 3.1.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/adapters/index.cjs +169 -155
- package/dist/adapters/index.cjs.map +1 -1
- package/dist/adapters/index.d.cts +2 -2
- package/dist/adapters/index.d.ts +2 -2
- package/dist/adapters/index.js +169 -155
- package/dist/adapters/index.js.map +1 -1
- package/dist/core/index.cjs +148 -24
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +113 -22
- package/dist/core/index.d.ts +113 -22
- package/dist/core/index.js +137 -22
- package/dist/core/index.js.map +1 -1
- package/dist/index-BrogG0Gc.d.cts +277 -0
- package/dist/index-DOvJES2m.d.ts +277 -0
- package/dist/index.cjs +324 -71
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +311 -69
- package/dist/index.js.map +1 -1
- package/dist/repository/index.cjs +254 -49
- package/dist/repository/index.cjs.map +1 -1
- package/dist/repository/index.d.cts +3 -254
- package/dist/repository/index.d.ts +3 -254
- package/dist/repository/index.js +254 -49
- package/dist/repository/index.js.map +1 -1
- package/dist/sdk/index.cjs +1 -0
- package/dist/sdk/index.cjs.map +1 -1
- package/dist/sdk/index.d.cts +2 -2
- package/dist/sdk/index.d.ts +2 -2
- package/dist/sdk/index.js +1 -0
- package/dist/sdk/index.js.map +1 -1
- package/dist/service/index.cjs +42 -19
- package/dist/service/index.cjs.map +1 -1
- package/dist/service/index.d.cts +2 -2
- package/dist/service/index.d.ts +2 -2
- package/dist/service/index.js +42 -19
- package/dist/service/index.js.map +1 -1
- package/dist/{types-3c-IAwZI.d.ts → types-BL3YqxUD.d.ts} +28 -6
- package/dist/{types-MaViK5tD.d.cts → types-C3sxDvNb.d.cts} +29 -6
- package/dist/{types-MaViK5tD.d.ts → types-C3sxDvNb.d.ts} +29 -6
- package/dist/{types-XSjNXO5l.d.cts → types-YLAB8bFk.d.cts} +28 -6
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { P as PortableTransaction, a as PortableReservation, R as ReservationStatus, C as CreditOperationType, b as CreditSource, J as JournalReferenceType, A as AIProviderType, S as SubscriptionTier, c as PortableUserCredits, d as PortableUsageLog, M as MonthlyResetResult, e as SubscriptionExpiryResult, f as PortableJournalEntry } from './types-
|
|
1
|
+
import { P as PortableTransaction, a as PortableReservation, R as ReservationStatus, C as CreditOperationType, b as CreditSource, J as JournalReferenceType, A as AIProviderType, S as SubscriptionTier, c as PortableUserCredits, d as PortableUsageLog, M as MonthlyResetResult, e as SubscriptionExpiryResult, f as PortableJournalEntry } from './types-C3sxDvNb.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Typed outcomes for the V2 reservation boundary.
|
|
@@ -326,7 +326,10 @@ interface CreateJournalEntryInput {
|
|
|
326
326
|
userId: string;
|
|
327
327
|
entryType: "debit" | "credit";
|
|
328
328
|
amount: number;
|
|
329
|
+
/** `balance + bonusCredits` after this entry. */
|
|
329
330
|
balanceAfter: number;
|
|
331
|
+
/** `balance + bonusCredits` before this entry. */
|
|
332
|
+
balanceBefore?: number;
|
|
330
333
|
source: CreditSource;
|
|
331
334
|
referenceId: string;
|
|
332
335
|
referenceType: JournalReferenceType;
|
|
@@ -335,6 +338,18 @@ interface CreateJournalEntryInput {
|
|
|
335
338
|
/** Deterministic key making this entry unique per user (V2, optional). */
|
|
336
339
|
idempotencyKey?: string;
|
|
337
340
|
}
|
|
341
|
+
/**
|
|
342
|
+
* The journal entry of a one-shot deduct, written in the deduct's own atomic step.
|
|
343
|
+
*/
|
|
344
|
+
interface DeductJournalInput {
|
|
345
|
+
referenceId: string;
|
|
346
|
+
description: string;
|
|
347
|
+
/** Defaults to `"operation_commit"`. */
|
|
348
|
+
source?: CreditSource;
|
|
349
|
+
/** Defaults to `"adjustment"`. */
|
|
350
|
+
referenceType?: JournalReferenceType;
|
|
351
|
+
metadata?: Record<string, unknown>;
|
|
352
|
+
}
|
|
338
353
|
/**
|
|
339
354
|
* Query options for journal entries
|
|
340
355
|
*/
|
|
@@ -354,6 +369,7 @@ interface CreditBalanceUpdate {
|
|
|
354
369
|
balance?: number;
|
|
355
370
|
bonusCredits?: number;
|
|
356
371
|
reserved?: number;
|
|
372
|
+
/** Writes no journal line. To change a tier, use `updateUserTier`. */
|
|
357
373
|
tier?: SubscriptionTier;
|
|
358
374
|
monthlyLimit?: number;
|
|
359
375
|
monthlyUsed?: number;
|
|
@@ -446,7 +462,9 @@ interface ICreditRepository extends Partial<ICreditRepositoryV2>, Partial<ICredi
|
|
|
446
462
|
*/
|
|
447
463
|
getUserCredits(userId: string): Promise<PortableUserCredits | null>;
|
|
448
464
|
/**
|
|
449
|
-
* Initialize credits for a new user
|
|
465
|
+
* Initialize credits for a new user. Creating an account with a balance above 0
|
|
466
|
+
* writes its journal line (`signupGrantJournalInput`) in the same atomic step, and
|
|
467
|
+
* a call that finds the account writes nothing.
|
|
450
468
|
* @param userId - User ID
|
|
451
469
|
* @param tier - Initial subscription tier
|
|
452
470
|
* @param initialBalance - Initial credit balance
|
|
@@ -454,13 +472,16 @@ interface ICreditRepository extends Partial<ICreditRepositoryV2>, Partial<ICredi
|
|
|
454
472
|
*/
|
|
455
473
|
initializeUserCredits(userId: string, tier: SubscriptionTier, initialBalance: number): Promise<PortableUserCredits>;
|
|
456
474
|
/**
|
|
457
|
-
*
|
|
475
|
+
* Patch fields of the account. This writes no journal line, whatever it changes.
|
|
476
|
+
* A tier change goes through `updateUserTier`, which journals a balance it moves.
|
|
458
477
|
* @param userId - User ID
|
|
459
478
|
* @param updates - Partial updates to apply
|
|
460
479
|
*/
|
|
461
480
|
updateUserCredits(userId: string, updates: CreditBalanceUpdate): Promise<void>;
|
|
462
481
|
/**
|
|
463
|
-
* Update user subscription tier
|
|
482
|
+
* Update user subscription tier. A write that moves the balance writes one journal
|
|
483
|
+
* line (`tierChangeJournalInput`) in the same atomic step, and one that does not
|
|
484
|
+
* writes none.
|
|
464
485
|
* @param userId - User ID
|
|
465
486
|
* @param input - Tier update data
|
|
466
487
|
*/
|
|
@@ -556,9 +577,10 @@ interface ICreditRepository extends Partial<ICreditRepositoryV2>, Partial<ICredi
|
|
|
556
577
|
* @returns Combined totals (balance + bonusCredits) before and after.
|
|
557
578
|
* @throws If user has no credits doc or insufficient credits
|
|
558
579
|
*/
|
|
559
|
-
deductCreditsAtomic(userId: string, amount: number): Promise<{
|
|
580
|
+
deductCreditsAtomic(userId: string, amount: number, journal?: DeductJournalInput): Promise<{
|
|
560
581
|
previousBalance: number;
|
|
561
582
|
newBalance: number;
|
|
583
|
+
journalEntryId?: string;
|
|
562
584
|
}>;
|
|
563
585
|
/**
|
|
564
586
|
* Create a credit transaction *record* — no balance moves.
|
|
@@ -678,4 +700,4 @@ declare function supportsIdempotentCredit(repository: ICreditRepository): reposi
|
|
|
678
700
|
*/
|
|
679
701
|
declare function toClientUserCredits(credits: PortableUserCredits): PortableUserCredits;
|
|
680
702
|
|
|
681
|
-
export { type AddCreditsAtomicOptions as A, type CommitOutcome as C, type ExpireOutcome as E, type ICreditRepository as I, type JournalEntryQuery as J, type ReleaseOutcome as R, type TerminalReservationStatus as T, type UsageLogQuery as U, type AddCreditsOutcome as a, type AddCreditsV2Input as b, type CreateJournalEntryInput as c, type CreateReservationInput as d, type CreateTransactionInput as e, type CreateUsageLogInput as f, type CreditBalanceUpdate as g, type CreditPolicyOptions as h, type CreditRepositoryFactory as i, type ExpireReservationV2Options as j, type ICreditRepositoryCreditsV2 as k, type ICreditRepositoryV2 as l, type ReservationTransitionOptions as m, type ReserveCreditsV2Input as n, type ReserveOutcome as o, type TierUpdateInput as p, isCreditedOutcome as q, isReservedOutcome as r, isWinningOutcome as s, reservationJournalKey as t, supportsCreditsV2 as u, supportsIdempotentCredit as v, toClientUserCredits as w };
|
|
703
|
+
export { type AddCreditsAtomicOptions as A, type CommitOutcome as C, type DeductJournalInput as D, type ExpireOutcome as E, type ICreditRepository as I, type JournalEntryQuery as J, type ReleaseOutcome as R, type TerminalReservationStatus as T, type UsageLogQuery as U, type AddCreditsOutcome as a, type AddCreditsV2Input as b, type CreateJournalEntryInput as c, type CreateReservationInput as d, type CreateTransactionInput as e, type CreateUsageLogInput as f, type CreditBalanceUpdate as g, type CreditPolicyOptions as h, type CreditRepositoryFactory as i, type ExpireReservationV2Options as j, type ICreditRepositoryCreditsV2 as k, type ICreditRepositoryV2 as l, type ReservationTransitionOptions as m, type ReserveCreditsV2Input as n, type ReserveOutcome as o, type TierUpdateInput as p, isCreditedOutcome as q, isReservedOutcome as r, isWinningOutcome as s, reservationJournalKey as t, supportsCreditsV2 as u, supportsIdempotentCredit as v, toClientUserCredits as w };
|
|
@@ -99,6 +99,11 @@ interface PortableUserCredits {
|
|
|
99
99
|
* Absent means 0. See `planBalanceCap`.
|
|
100
100
|
*/
|
|
101
101
|
expiredHoldBacking?: number;
|
|
102
|
+
/**
|
|
103
|
+
* Where those credits end among the open holds, so a hold's share needs no write
|
|
104
|
+
* to the hold. Internal to the repositories: `toClientUserCredits` drops it.
|
|
105
|
+
*/
|
|
106
|
+
expiredBackingFrontier?: ExpiredBackingFrontier | null;
|
|
102
107
|
/**
|
|
103
108
|
* Set when the account was created with a signup-grant claim: the amount
|
|
104
109
|
* granted, 0 when the claim was already taken. Absent on any other account.
|
|
@@ -109,6 +114,21 @@ interface PortableUserCredits {
|
|
|
109
114
|
/** Last update timestamp - ISO 8601 */
|
|
110
115
|
updatedAt: string;
|
|
111
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* The newest open hold carrying marked credits (`expiredHoldBacking`).
|
|
119
|
+
*
|
|
120
|
+
* Credits are marked oldest hold first, so a single point describes every share:
|
|
121
|
+
* a hold older than this carries its full amount, this hold carries `share`, and a
|
|
122
|
+
* newer one carries nothing. A marked credit leaves the balance when its hold closes,
|
|
123
|
+
* however it closes. See `allocateExpiredBacking` and `holdExpiredBacking`.
|
|
124
|
+
*/
|
|
125
|
+
interface ExpiredBackingFrontier {
|
|
126
|
+
/** The hold's `holdPlacedAt`. */
|
|
127
|
+
holdPlacedAt: string;
|
|
128
|
+
/** The hold's id, which orders holds placed in the same millisecond. */
|
|
129
|
+
id: string;
|
|
130
|
+
share: number;
|
|
131
|
+
}
|
|
112
132
|
/**
|
|
113
133
|
* Credit reservation status for two-phase commit
|
|
114
134
|
*/
|
|
@@ -148,10 +168,8 @@ interface PortableReservation {
|
|
|
148
168
|
*/
|
|
149
169
|
holdPlacedAt?: string;
|
|
150
170
|
/**
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
* hold placed after the expiry. Open holds' shares sum to the account's
|
|
154
|
-
* `expiredHoldBacking`.
|
|
171
|
+
* This hold's share of the marked credits, stored by 2.2.0. A hold placed since carries
|
|
172
|
+
* none and takes its share from the account's frontier. See `holdExpiredBacking`.
|
|
155
173
|
*/
|
|
156
174
|
expiredBacking?: number;
|
|
157
175
|
}
|
|
@@ -268,8 +286,13 @@ interface PortableJournalEntry {
|
|
|
268
286
|
entryType: "debit" | "credit";
|
|
269
287
|
/** Amount of credits involved */
|
|
270
288
|
amount: number;
|
|
271
|
-
/**
|
|
289
|
+
/** `balance + bonusCredits` after this entry */
|
|
272
290
|
balanceAfter: number;
|
|
291
|
+
/**
|
|
292
|
+
* `balance + bonusCredits` before this entry, read in the same atomic step.
|
|
293
|
+
* Absent on entries written before 3.0.0.
|
|
294
|
+
*/
|
|
295
|
+
balanceBefore?: number;
|
|
273
296
|
/** Source of the credit change */
|
|
274
297
|
source: CreditSource;
|
|
275
298
|
/** Reference ID (e.g., reservationId, transactionId) */
|
|
@@ -368,4 +391,4 @@ interface WithCreditsOptions {
|
|
|
368
391
|
resourceType?: ResourceType;
|
|
369
392
|
}
|
|
370
393
|
|
|
371
|
-
export { type AIProviderType as A, type BuiltinTier as B, type CreditOperationType as C, type DeductCreditsResult as D, type JournalReferenceType as J, type MonthlyResetResult as M, type PortableTransaction as P, type ReservationStatus as R, type SubscriptionTier as S, type TierConfig as T, type UsageHistoryEntry as U, type WithCreditsOptions as W, type PortableReservation as a, type CreditSource as b, type PortableUserCredits as c, type PortableUsageLog as d, type SubscriptionExpiryResult as e, type PortableJournalEntry as f, type CreditCheckResult as g, type ResourceType as h, type TransactionType as i, type UsageHistoryResponse as j, calculateAvailableCredits as k, toPortableTimestamp as l, toDate as t };
|
|
394
|
+
export { type AIProviderType as A, type BuiltinTier as B, type CreditOperationType as C, type DeductCreditsResult as D, type ExpiredBackingFrontier as E, type JournalReferenceType as J, type MonthlyResetResult as M, type PortableTransaction as P, type ReservationStatus as R, type SubscriptionTier as S, type TierConfig as T, type UsageHistoryEntry as U, type WithCreditsOptions as W, type PortableReservation as a, type CreditSource as b, type PortableUserCredits as c, type PortableUsageLog as d, type SubscriptionExpiryResult as e, type PortableJournalEntry as f, type CreditCheckResult as g, type ResourceType as h, type TransactionType as i, type UsageHistoryResponse as j, calculateAvailableCredits as k, toPortableTimestamp as l, toDate as t };
|
|
@@ -99,6 +99,11 @@ interface PortableUserCredits {
|
|
|
99
99
|
* Absent means 0. See `planBalanceCap`.
|
|
100
100
|
*/
|
|
101
101
|
expiredHoldBacking?: number;
|
|
102
|
+
/**
|
|
103
|
+
* Where those credits end among the open holds, so a hold's share needs no write
|
|
104
|
+
* to the hold. Internal to the repositories: `toClientUserCredits` drops it.
|
|
105
|
+
*/
|
|
106
|
+
expiredBackingFrontier?: ExpiredBackingFrontier | null;
|
|
102
107
|
/**
|
|
103
108
|
* Set when the account was created with a signup-grant claim: the amount
|
|
104
109
|
* granted, 0 when the claim was already taken. Absent on any other account.
|
|
@@ -109,6 +114,21 @@ interface PortableUserCredits {
|
|
|
109
114
|
/** Last update timestamp - ISO 8601 */
|
|
110
115
|
updatedAt: string;
|
|
111
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* The newest open hold carrying marked credits (`expiredHoldBacking`).
|
|
119
|
+
*
|
|
120
|
+
* Credits are marked oldest hold first, so a single point describes every share:
|
|
121
|
+
* a hold older than this carries its full amount, this hold carries `share`, and a
|
|
122
|
+
* newer one carries nothing. A marked credit leaves the balance when its hold closes,
|
|
123
|
+
* however it closes. See `allocateExpiredBacking` and `holdExpiredBacking`.
|
|
124
|
+
*/
|
|
125
|
+
interface ExpiredBackingFrontier {
|
|
126
|
+
/** The hold's `holdPlacedAt`. */
|
|
127
|
+
holdPlacedAt: string;
|
|
128
|
+
/** The hold's id, which orders holds placed in the same millisecond. */
|
|
129
|
+
id: string;
|
|
130
|
+
share: number;
|
|
131
|
+
}
|
|
112
132
|
/**
|
|
113
133
|
* Credit reservation status for two-phase commit
|
|
114
134
|
*/
|
|
@@ -148,10 +168,8 @@ interface PortableReservation {
|
|
|
148
168
|
*/
|
|
149
169
|
holdPlacedAt?: string;
|
|
150
170
|
/**
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
* hold placed after the expiry. Open holds' shares sum to the account's
|
|
154
|
-
* `expiredHoldBacking`.
|
|
171
|
+
* This hold's share of the marked credits, stored by 2.2.0. A hold placed since carries
|
|
172
|
+
* none and takes its share from the account's frontier. See `holdExpiredBacking`.
|
|
155
173
|
*/
|
|
156
174
|
expiredBacking?: number;
|
|
157
175
|
}
|
|
@@ -268,8 +286,13 @@ interface PortableJournalEntry {
|
|
|
268
286
|
entryType: "debit" | "credit";
|
|
269
287
|
/** Amount of credits involved */
|
|
270
288
|
amount: number;
|
|
271
|
-
/**
|
|
289
|
+
/** `balance + bonusCredits` after this entry */
|
|
272
290
|
balanceAfter: number;
|
|
291
|
+
/**
|
|
292
|
+
* `balance + bonusCredits` before this entry, read in the same atomic step.
|
|
293
|
+
* Absent on entries written before 3.0.0.
|
|
294
|
+
*/
|
|
295
|
+
balanceBefore?: number;
|
|
273
296
|
/** Source of the credit change */
|
|
274
297
|
source: CreditSource;
|
|
275
298
|
/** Reference ID (e.g., reservationId, transactionId) */
|
|
@@ -368,4 +391,4 @@ interface WithCreditsOptions {
|
|
|
368
391
|
resourceType?: ResourceType;
|
|
369
392
|
}
|
|
370
393
|
|
|
371
|
-
export { type AIProviderType as A, type BuiltinTier as B, type CreditOperationType as C, type DeductCreditsResult as D, type JournalReferenceType as J, type MonthlyResetResult as M, type PortableTransaction as P, type ReservationStatus as R, type SubscriptionTier as S, type TierConfig as T, type UsageHistoryEntry as U, type WithCreditsOptions as W, type PortableReservation as a, type CreditSource as b, type PortableUserCredits as c, type PortableUsageLog as d, type SubscriptionExpiryResult as e, type PortableJournalEntry as f, type CreditCheckResult as g, type ResourceType as h, type TransactionType as i, type UsageHistoryResponse as j, calculateAvailableCredits as k, toPortableTimestamp as l, toDate as t };
|
|
394
|
+
export { type AIProviderType as A, type BuiltinTier as B, type CreditOperationType as C, type DeductCreditsResult as D, type ExpiredBackingFrontier as E, type JournalReferenceType as J, type MonthlyResetResult as M, type PortableTransaction as P, type ReservationStatus as R, type SubscriptionTier as S, type TierConfig as T, type UsageHistoryEntry as U, type WithCreditsOptions as W, type PortableReservation as a, type CreditSource as b, type PortableUserCredits as c, type PortableUsageLog as d, type SubscriptionExpiryResult as e, type PortableJournalEntry as f, type CreditCheckResult as g, type ResourceType as h, type TransactionType as i, type UsageHistoryResponse as j, calculateAvailableCredits as k, toPortableTimestamp as l, toDate as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { P as PortableTransaction, a as PortableReservation, R as ReservationStatus, C as CreditOperationType, b as CreditSource, J as JournalReferenceType, A as AIProviderType, S as SubscriptionTier, c as PortableUserCredits, d as PortableUsageLog, M as MonthlyResetResult, e as SubscriptionExpiryResult, f as PortableJournalEntry } from './types-
|
|
1
|
+
import { P as PortableTransaction, a as PortableReservation, R as ReservationStatus, C as CreditOperationType, b as CreditSource, J as JournalReferenceType, A as AIProviderType, S as SubscriptionTier, c as PortableUserCredits, d as PortableUsageLog, M as MonthlyResetResult, e as SubscriptionExpiryResult, f as PortableJournalEntry } from './types-C3sxDvNb.cjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Typed outcomes for the V2 reservation boundary.
|
|
@@ -326,7 +326,10 @@ interface CreateJournalEntryInput {
|
|
|
326
326
|
userId: string;
|
|
327
327
|
entryType: "debit" | "credit";
|
|
328
328
|
amount: number;
|
|
329
|
+
/** `balance + bonusCredits` after this entry. */
|
|
329
330
|
balanceAfter: number;
|
|
331
|
+
/** `balance + bonusCredits` before this entry. */
|
|
332
|
+
balanceBefore?: number;
|
|
330
333
|
source: CreditSource;
|
|
331
334
|
referenceId: string;
|
|
332
335
|
referenceType: JournalReferenceType;
|
|
@@ -335,6 +338,18 @@ interface CreateJournalEntryInput {
|
|
|
335
338
|
/** Deterministic key making this entry unique per user (V2, optional). */
|
|
336
339
|
idempotencyKey?: string;
|
|
337
340
|
}
|
|
341
|
+
/**
|
|
342
|
+
* The journal entry of a one-shot deduct, written in the deduct's own atomic step.
|
|
343
|
+
*/
|
|
344
|
+
interface DeductJournalInput {
|
|
345
|
+
referenceId: string;
|
|
346
|
+
description: string;
|
|
347
|
+
/** Defaults to `"operation_commit"`. */
|
|
348
|
+
source?: CreditSource;
|
|
349
|
+
/** Defaults to `"adjustment"`. */
|
|
350
|
+
referenceType?: JournalReferenceType;
|
|
351
|
+
metadata?: Record<string, unknown>;
|
|
352
|
+
}
|
|
338
353
|
/**
|
|
339
354
|
* Query options for journal entries
|
|
340
355
|
*/
|
|
@@ -354,6 +369,7 @@ interface CreditBalanceUpdate {
|
|
|
354
369
|
balance?: number;
|
|
355
370
|
bonusCredits?: number;
|
|
356
371
|
reserved?: number;
|
|
372
|
+
/** Writes no journal line. To change a tier, use `updateUserTier`. */
|
|
357
373
|
tier?: SubscriptionTier;
|
|
358
374
|
monthlyLimit?: number;
|
|
359
375
|
monthlyUsed?: number;
|
|
@@ -446,7 +462,9 @@ interface ICreditRepository extends Partial<ICreditRepositoryV2>, Partial<ICredi
|
|
|
446
462
|
*/
|
|
447
463
|
getUserCredits(userId: string): Promise<PortableUserCredits | null>;
|
|
448
464
|
/**
|
|
449
|
-
* Initialize credits for a new user
|
|
465
|
+
* Initialize credits for a new user. Creating an account with a balance above 0
|
|
466
|
+
* writes its journal line (`signupGrantJournalInput`) in the same atomic step, and
|
|
467
|
+
* a call that finds the account writes nothing.
|
|
450
468
|
* @param userId - User ID
|
|
451
469
|
* @param tier - Initial subscription tier
|
|
452
470
|
* @param initialBalance - Initial credit balance
|
|
@@ -454,13 +472,16 @@ interface ICreditRepository extends Partial<ICreditRepositoryV2>, Partial<ICredi
|
|
|
454
472
|
*/
|
|
455
473
|
initializeUserCredits(userId: string, tier: SubscriptionTier, initialBalance: number): Promise<PortableUserCredits>;
|
|
456
474
|
/**
|
|
457
|
-
*
|
|
475
|
+
* Patch fields of the account. This writes no journal line, whatever it changes.
|
|
476
|
+
* A tier change goes through `updateUserTier`, which journals a balance it moves.
|
|
458
477
|
* @param userId - User ID
|
|
459
478
|
* @param updates - Partial updates to apply
|
|
460
479
|
*/
|
|
461
480
|
updateUserCredits(userId: string, updates: CreditBalanceUpdate): Promise<void>;
|
|
462
481
|
/**
|
|
463
|
-
* Update user subscription tier
|
|
482
|
+
* Update user subscription tier. A write that moves the balance writes one journal
|
|
483
|
+
* line (`tierChangeJournalInput`) in the same atomic step, and one that does not
|
|
484
|
+
* writes none.
|
|
464
485
|
* @param userId - User ID
|
|
465
486
|
* @param input - Tier update data
|
|
466
487
|
*/
|
|
@@ -556,9 +577,10 @@ interface ICreditRepository extends Partial<ICreditRepositoryV2>, Partial<ICredi
|
|
|
556
577
|
* @returns Combined totals (balance + bonusCredits) before and after.
|
|
557
578
|
* @throws If user has no credits doc or insufficient credits
|
|
558
579
|
*/
|
|
559
|
-
deductCreditsAtomic(userId: string, amount: number): Promise<{
|
|
580
|
+
deductCreditsAtomic(userId: string, amount: number, journal?: DeductJournalInput): Promise<{
|
|
560
581
|
previousBalance: number;
|
|
561
582
|
newBalance: number;
|
|
583
|
+
journalEntryId?: string;
|
|
562
584
|
}>;
|
|
563
585
|
/**
|
|
564
586
|
* Create a credit transaction *record* — no balance moves.
|
|
@@ -678,4 +700,4 @@ declare function supportsIdempotentCredit(repository: ICreditRepository): reposi
|
|
|
678
700
|
*/
|
|
679
701
|
declare function toClientUserCredits(credits: PortableUserCredits): PortableUserCredits;
|
|
680
702
|
|
|
681
|
-
export { type AddCreditsAtomicOptions as A, type CommitOutcome as C, type ExpireOutcome as E, type ICreditRepository as I, type JournalEntryQuery as J, type ReleaseOutcome as R, type TerminalReservationStatus as T, type UsageLogQuery as U, type AddCreditsOutcome as a, type AddCreditsV2Input as b, type CreateJournalEntryInput as c, type CreateReservationInput as d, type CreateTransactionInput as e, type CreateUsageLogInput as f, type CreditBalanceUpdate as g, type CreditPolicyOptions as h, type CreditRepositoryFactory as i, type ExpireReservationV2Options as j, type ICreditRepositoryCreditsV2 as k, type ICreditRepositoryV2 as l, type ReservationTransitionOptions as m, type ReserveCreditsV2Input as n, type ReserveOutcome as o, type TierUpdateInput as p, isCreditedOutcome as q, isReservedOutcome as r, isWinningOutcome as s, reservationJournalKey as t, supportsCreditsV2 as u, supportsIdempotentCredit as v, toClientUserCredits as w };
|
|
703
|
+
export { type AddCreditsAtomicOptions as A, type CommitOutcome as C, type DeductJournalInput as D, type ExpireOutcome as E, type ICreditRepository as I, type JournalEntryQuery as J, type ReleaseOutcome as R, type TerminalReservationStatus as T, type UsageLogQuery as U, type AddCreditsOutcome as a, type AddCreditsV2Input as b, type CreateJournalEntryInput as c, type CreateReservationInput as d, type CreateTransactionInput as e, type CreateUsageLogInput as f, type CreditBalanceUpdate as g, type CreditPolicyOptions as h, type CreditRepositoryFactory as i, type ExpireReservationV2Options as j, type ICreditRepositoryCreditsV2 as k, type ICreditRepositoryV2 as l, type ReservationTransitionOptions as m, type ReserveCreditsV2Input as n, type ReserveOutcome as o, type TierUpdateInput as p, isCreditedOutcome as q, isReservedOutcome as r, isWinningOutcome as s, reservationJournalKey as t, supportsCreditsV2 as u, supportsIdempotentCredit as v, toClientUserCredits as w };
|