@nehorai/credits 2.0.0 → 2.2.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/LICENSE +21 -21
- package/README.md +384 -377
- package/dist/adapters/index.cjs +12 -8
- package/dist/adapters/index.cjs.map +1 -1
- package/dist/adapters/index.d.cts +3 -2
- package/dist/adapters/index.d.ts +3 -2
- package/dist/adapters/index.js +12 -8
- package/dist/adapters/index.js.map +1 -1
- package/dist/auth/index.cjs.map +1 -1
- package/dist/auth/index.js.map +1 -1
- package/dist/core/index.cjs +106 -4
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +92 -5
- package/dist/core/index.d.ts +92 -5
- package/dist/core/index.js +96 -4
- package/dist/core/index.js.map +1 -1
- package/dist/index.cjs +282 -45
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -7
- package/dist/index.d.ts +9 -7
- package/dist/index.js +270 -45
- package/dist/index.js.map +1 -1
- package/dist/repository/index.cjs +251 -41
- package/dist/repository/index.cjs.map +1 -1
- package/dist/repository/index.d.cts +34 -6
- package/dist/repository/index.d.ts +34 -6
- package/dist/repository/index.js +248 -40
- package/dist/repository/index.js.map +1 -1
- 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.map +1 -1
- package/dist/service/index.cjs +12 -6
- 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 +12 -6
- package/dist/service/index.js.map +1 -1
- package/dist/{types-BmG5Omzj.d.ts → types-3c-IAwZI.d.ts} +38 -3
- package/dist/{types-DJ8yqaVr.d.cts → types-MaViK5tD.d.cts} +23 -1
- package/dist/{types-DJ8yqaVr.d.ts → types-MaViK5tD.d.ts} +23 -1
- package/dist/{types-C8hZMe8a.d.cts → types-XSjNXO5l.d.cts} +38 -3
- package/package.json +1 -1
package/dist/service/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as PortableUserCredits, g as CreditCheckResult, C as CreditOperationType, a as PortableReservation, d as PortableUsageLog, D as DeductCreditsResult, S as SubscriptionTier, j as UsageHistoryResponse, f as PortableJournalEntry } from '../types-
|
|
2
|
-
import { I as ICreditRepository,
|
|
1
|
+
import { c as PortableUserCredits, g as CreditCheckResult, C as CreditOperationType, a as PortableReservation, d as PortableUsageLog, D as DeductCreditsResult, S as SubscriptionTier, j as UsageHistoryResponse, f as PortableJournalEntry } from '../types-MaViK5tD.cjs';
|
|
2
|
+
import { I as ICreditRepository, o as ReserveOutcome, m as ReservationTransitionOptions, C as CommitOutcome, R as ReleaseOutcome, A as AddCreditsAtomicOptions, a as AddCreditsOutcome, J as JournalEntryQuery } from '../types-XSjNXO5l.cjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Notification callback type for low balance notifications
|
package/dist/service/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as PortableUserCredits, g as CreditCheckResult, C as CreditOperationType, a as PortableReservation, d as PortableUsageLog, D as DeductCreditsResult, S as SubscriptionTier, j as UsageHistoryResponse, f as PortableJournalEntry } from '../types-
|
|
2
|
-
import { I as ICreditRepository,
|
|
1
|
+
import { c as PortableUserCredits, g as CreditCheckResult, C as CreditOperationType, a as PortableReservation, d as PortableUsageLog, D as DeductCreditsResult, S as SubscriptionTier, j as UsageHistoryResponse, f as PortableJournalEntry } from '../types-MaViK5tD.js';
|
|
2
|
+
import { I as ICreditRepository, o as ReserveOutcome, m as ReservationTransitionOptions, C as CommitOutcome, R as ReleaseOutcome, A as AddCreditsAtomicOptions, a as AddCreditsOutcome, J as JournalEntryQuery } from '../types-3c-IAwZI.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Notification callback type for low balance notifications
|
package/dist/service/index.js
CHANGED
|
@@ -199,11 +199,13 @@ var creditSystemConfigSchema = z.object({
|
|
|
199
199
|
/**
|
|
200
200
|
* Operation costs in credits
|
|
201
201
|
* Keys are operation type names (any non-empty string)
|
|
202
|
-
* Values are
|
|
202
|
+
* Values are non-negative numbers representing credit cost. 0 marks a free
|
|
203
|
+
* operation: `withCredits` runs it without touching the ledger. Amounts that
|
|
204
|
+
* move credits stay strictly positive, so `reserveCredits` refuses a 0.
|
|
203
205
|
*/
|
|
204
206
|
operationCosts: z.record(
|
|
205
207
|
z.string().min(1),
|
|
206
|
-
z.number().
|
|
208
|
+
z.number().nonnegative()
|
|
207
209
|
),
|
|
208
210
|
/**
|
|
209
211
|
* Display labels for operation types (English canonical labels).
|
|
@@ -225,9 +227,9 @@ var creditSystemConfigSchema = z.object({
|
|
|
225
227
|
*/
|
|
226
228
|
reservationExpiryMs: z.number().positive().default(5 * 60 * 1e3),
|
|
227
229
|
/**
|
|
228
|
-
* Default credits for new users (free tier)
|
|
230
|
+
* Default credits for new users (free tier). 0 means no signup grant.
|
|
229
231
|
*/
|
|
230
|
-
defaultFreeCredits: z.number().
|
|
232
|
+
defaultFreeCredits: z.number().min(0).default(25),
|
|
231
233
|
/**
|
|
232
234
|
* Grace period in days after subscription expires before downgrade
|
|
233
235
|
*/
|
|
@@ -496,6 +498,8 @@ function toClientUserCredits(credits) {
|
|
|
496
498
|
monthlyUsed: credits.monthlyUsed,
|
|
497
499
|
monthlyResetAt: toISOString(credits.monthlyResetAt),
|
|
498
500
|
subscriptionExpiresAt: credits.subscriptionExpiresAt ? toISOString(credits.subscriptionExpiresAt) : null,
|
|
501
|
+
...credits.expiredHoldBacking !== void 0 ? { expiredHoldBacking: credits.expiredHoldBacking } : {},
|
|
502
|
+
...credits.signupGrant !== void 0 ? { signupGrant: credits.signupGrant } : {},
|
|
499
503
|
createdAt: toISOString(credits.createdAt),
|
|
500
504
|
updatedAt: toISOString(credits.updatedAt)
|
|
501
505
|
};
|
|
@@ -743,9 +747,11 @@ var CreditsService = class {
|
|
|
743
747
|
source: "monthly_reset",
|
|
744
748
|
referenceId: `reset-${Date.now()}`,
|
|
745
749
|
referenceType: "reset",
|
|
746
|
-
|
|
750
|
+
// The tier the reset ran on, which a concurrent downgrade may have
|
|
751
|
+
// changed since `data` was read.
|
|
752
|
+
description: `Monthly credit reset for ${resetResult.credits.tier} tier.`,
|
|
747
753
|
metadata: {
|
|
748
|
-
tier:
|
|
754
|
+
tier: resetResult.credits.tier,
|
|
749
755
|
previousBalance: data.balance,
|
|
750
756
|
newBalance: resetResult.credits.balance
|
|
751
757
|
}
|