@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.cjs
CHANGED
|
@@ -226,11 +226,13 @@ var creditSystemConfigSchema = import_zod.z.object({
|
|
|
226
226
|
/**
|
|
227
227
|
* Operation costs in credits
|
|
228
228
|
* Keys are operation type names (any non-empty string)
|
|
229
|
-
* Values are
|
|
229
|
+
* Values are non-negative numbers representing credit cost. 0 marks a free
|
|
230
|
+
* operation: `withCredits` runs it without touching the ledger. Amounts that
|
|
231
|
+
* move credits stay strictly positive, so `reserveCredits` refuses a 0.
|
|
230
232
|
*/
|
|
231
233
|
operationCosts: import_zod.z.record(
|
|
232
234
|
import_zod.z.string().min(1),
|
|
233
|
-
import_zod.z.number().
|
|
235
|
+
import_zod.z.number().nonnegative()
|
|
234
236
|
),
|
|
235
237
|
/**
|
|
236
238
|
* Display labels for operation types (English canonical labels).
|
|
@@ -252,9 +254,9 @@ var creditSystemConfigSchema = import_zod.z.object({
|
|
|
252
254
|
*/
|
|
253
255
|
reservationExpiryMs: import_zod.z.number().positive().default(5 * 60 * 1e3),
|
|
254
256
|
/**
|
|
255
|
-
* Default credits for new users (free tier)
|
|
257
|
+
* Default credits for new users (free tier). 0 means no signup grant.
|
|
256
258
|
*/
|
|
257
|
-
defaultFreeCredits: import_zod.z.number().
|
|
259
|
+
defaultFreeCredits: import_zod.z.number().min(0).default(25),
|
|
258
260
|
/**
|
|
259
261
|
* Grace period in days after subscription expires before downgrade
|
|
260
262
|
*/
|
|
@@ -523,6 +525,8 @@ function toClientUserCredits(credits) {
|
|
|
523
525
|
monthlyUsed: credits.monthlyUsed,
|
|
524
526
|
monthlyResetAt: toISOString(credits.monthlyResetAt),
|
|
525
527
|
subscriptionExpiresAt: credits.subscriptionExpiresAt ? toISOString(credits.subscriptionExpiresAt) : null,
|
|
528
|
+
...credits.expiredHoldBacking !== void 0 ? { expiredHoldBacking: credits.expiredHoldBacking } : {},
|
|
529
|
+
...credits.signupGrant !== void 0 ? { signupGrant: credits.signupGrant } : {},
|
|
526
530
|
createdAt: toISOString(credits.createdAt),
|
|
527
531
|
updatedAt: toISOString(credits.updatedAt)
|
|
528
532
|
};
|
|
@@ -770,9 +774,11 @@ var CreditsService = class {
|
|
|
770
774
|
source: "monthly_reset",
|
|
771
775
|
referenceId: `reset-${Date.now()}`,
|
|
772
776
|
referenceType: "reset",
|
|
773
|
-
|
|
777
|
+
// The tier the reset ran on, which a concurrent downgrade may have
|
|
778
|
+
// changed since `data` was read.
|
|
779
|
+
description: `Monthly credit reset for ${resetResult.credits.tier} tier.`,
|
|
774
780
|
metadata: {
|
|
775
|
-
tier:
|
|
781
|
+
tier: resetResult.credits.tier,
|
|
776
782
|
previousBalance: data.balance,
|
|
777
783
|
newBalance: resetResult.credits.balance
|
|
778
784
|
}
|