@nehorai/credits 3.0.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.
@@ -1,7 +1,7 @@
1
1
  import { R as ReservationStatus, a as PortableReservation, P as PortableTransaction, b as CreditSource, J as JournalReferenceType, E as ExpiredBackingFrontier } from '../types-C3sxDvNb.cjs';
2
2
  export { A as AIProviderType, B as BuiltinTier, g as CreditCheckResult, C as CreditOperationType, D as DeductCreditsResult, M as MonthlyResetResult, f as PortableJournalEntry, d as PortableUsageLog, c as PortableUserCredits, h as ResourceType, e as SubscriptionExpiryResult, S as SubscriptionTier, T as TierConfig, i as TransactionType, U as UsageHistoryEntry, j as UsageHistoryResponse, W as WithCreditsOptions, k as calculateAvailableCredits, t as toDate, l as toPortableTimestamp } from '../types-C3sxDvNb.cjs';
3
- import { T as TerminalReservationStatus, I as ICreditRepository } from '../types-DOjguhEX.cjs';
4
- export { a as AddCreditsOutcome, C as CommitOutcome, E as ExpireOutcome, R as ReleaseOutcome, o as ReserveOutcome, q as isCreditedOutcome, r as isReservedOutcome, s as isWinningOutcome } from '../types-DOjguhEX.cjs';
3
+ import { T as TerminalReservationStatus, I as ICreditRepository } from '../types-YLAB8bFk.cjs';
4
+ export { a as AddCreditsOutcome, C as CommitOutcome, E as ExpireOutcome, R as ReleaseOutcome, o as ReserveOutcome, q as isCreditedOutcome, r as isReservedOutcome, s as isWinningOutcome } from '../types-YLAB8bFk.cjs';
5
5
  export { D as DeferredExecutor, c as createDeferredExecutor, g as genericDeferred, n as noopDeferred, s as synchronousDeferred } from '../deferred-C7rrRfkm.cjs';
6
6
 
7
7
  /**
@@ -1,7 +1,7 @@
1
1
  import { R as ReservationStatus, a as PortableReservation, P as PortableTransaction, b as CreditSource, J as JournalReferenceType, E as ExpiredBackingFrontier } from '../types-C3sxDvNb.js';
2
2
  export { A as AIProviderType, B as BuiltinTier, g as CreditCheckResult, C as CreditOperationType, D as DeductCreditsResult, M as MonthlyResetResult, f as PortableJournalEntry, d as PortableUsageLog, c as PortableUserCredits, h as ResourceType, e as SubscriptionExpiryResult, S as SubscriptionTier, T as TierConfig, i as TransactionType, U as UsageHistoryEntry, j as UsageHistoryResponse, W as WithCreditsOptions, k as calculateAvailableCredits, t as toDate, l as toPortableTimestamp } from '../types-C3sxDvNb.js';
3
- import { T as TerminalReservationStatus, I as ICreditRepository } from '../types-CY-oHIMA.js';
4
- export { a as AddCreditsOutcome, C as CommitOutcome, E as ExpireOutcome, R as ReleaseOutcome, o as ReserveOutcome, q as isCreditedOutcome, r as isReservedOutcome, s as isWinningOutcome } from '../types-CY-oHIMA.js';
3
+ import { T as TerminalReservationStatus, I as ICreditRepository } from '../types-BL3YqxUD.js';
4
+ export { a as AddCreditsOutcome, C as CommitOutcome, E as ExpireOutcome, R as ReleaseOutcome, o as ReserveOutcome, q as isCreditedOutcome, r as isReservedOutcome, s as isWinningOutcome } from '../types-BL3YqxUD.js';
5
5
  export { D as DeferredExecutor, c as createDeferredExecutor, g as genericDeferred, n as noopDeferred, s as synchronousDeferred } from '../deferred-C7rrRfkm.js';
6
6
 
7
7
  /**
@@ -907,17 +907,25 @@ var DEFAULT_CONFIG = {
907
907
  }
908
908
  };
909
909
  var currentConfig = DEFAULT_CONFIG;
910
+ function isOperationCostMap(value) {
911
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
912
+ return Object.values(value).every((cost) => isRepresentableAmount(cost) && cost >= 0);
913
+ }
910
914
  function loadConfigFromEnv() {
911
915
  const envConfig = {};
912
916
  const operationCostsEnv = process.env.CREDITS_OPERATION_COSTS;
913
917
  if (operationCostsEnv) {
914
918
  try {
915
919
  const parsed = JSON.parse(operationCostsEnv);
916
- if (typeof parsed === "object" && parsed !== null) {
920
+ if (isOperationCostMap(parsed)) {
917
921
  envConfig.operationCosts = {
918
922
  ...DEFAULT_CONFIG.operationCosts,
919
923
  ...parsed
920
924
  };
925
+ } else {
926
+ console.warn(
927
+ "[Credits Config] Ignoring CREDITS_OPERATION_COSTS: it must be a JSON object whose costs are numbers >= 0, exact to the cent"
928
+ );
921
929
  }
922
930
  } catch {
923
931
  console.warn("[Credits Config] Failed to parse CREDITS_OPERATION_COSTS env var as JSON");