@nehorai/credits 1.2.0 → 1.3.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.
Files changed (139) hide show
  1. package/LICENSE +21 -0
  2. package/dist/adapters/index.cjs +463 -0
  3. package/dist/adapters/index.cjs.map +1 -0
  4. package/dist/adapters/index.d.cts +66 -0
  5. package/dist/adapters/index.d.ts +66 -3
  6. package/dist/adapters/index.js +435 -1
  7. package/dist/adapters/index.js.map +1 -1
  8. package/dist/auth/index.cjs +96 -0
  9. package/dist/auth/index.cjs.map +1 -0
  10. package/dist/auth/{api-key.d.ts → index.d.cts} +9 -6
  11. package/dist/auth/index.d.ts +37 -5
  12. package/dist/auth/index.js +65 -7
  13. package/dist/auth/index.js.map +1 -1
  14. package/dist/core/index.cjs +522 -0
  15. package/dist/core/index.cjs.map +1 -0
  16. package/dist/core/index.d.cts +119 -0
  17. package/dist/core/index.d.ts +115 -25
  18. package/dist/core/index.js +475 -27
  19. package/dist/core/index.js.map +1 -1
  20. package/dist/{core/deferred.d.ts → deferred-C7rrRfkm.d.cts} +7 -6
  21. package/dist/{core/deferred.js → deferred-C7rrRfkm.d.ts} +23 -29
  22. package/dist/index.cjs +2506 -0
  23. package/dist/index.cjs.map +1 -0
  24. package/dist/index.d.cts +437 -0
  25. package/dist/index.d.ts +429 -50
  26. package/dist/index.js +2399 -63
  27. package/dist/index.js.map +1 -1
  28. package/dist/repository/index.cjs +816 -0
  29. package/dist/repository/index.cjs.map +1 -0
  30. package/dist/repository/{memory/index.d.ts → index.d.cts} +35 -5
  31. package/dist/repository/index.d.ts +97 -7
  32. package/dist/repository/index.js +783 -10
  33. package/dist/repository/index.js.map +1 -1
  34. package/dist/sdk/index.cjs +608 -0
  35. package/dist/sdk/index.cjs.map +1 -0
  36. package/dist/sdk/index.d.cts +495 -0
  37. package/dist/sdk/index.d.ts +491 -9
  38. package/dist/sdk/index.js +568 -12
  39. package/dist/sdk/index.js.map +1 -1
  40. package/dist/service/index.cjs +670 -0
  41. package/dist/service/index.cjs.map +1 -0
  42. package/dist/service/{credits-service.d.ts → index.d.cts} +9 -7
  43. package/dist/service/index.d.ts +141 -3
  44. package/dist/service/index.js +641 -1
  45. package/dist/service/index.js.map +1 -1
  46. package/dist/{core/types.d.ts → types-BBxIWHK2.d.cts} +25 -24
  47. package/dist/types-BBxIWHK2.d.ts +277 -0
  48. package/dist/types-D1vdeBcA.d.cts +305 -0
  49. package/dist/{auth/types.d.ts → types-OZU3I5OM.d.cts} +5 -4
  50. package/dist/types-OZU3I5OM.d.ts +32 -0
  51. package/dist/{repository/types.d.ts → types-aJsyv8df.d.ts} +35 -13
  52. package/package.json +21 -19
  53. package/dist/adapters/generic.d.ts +0 -18
  54. package/dist/adapters/generic.d.ts.map +0 -1
  55. package/dist/adapters/generic.js +0 -151
  56. package/dist/adapters/generic.js.map +0 -1
  57. package/dist/adapters/index.d.ts.map +0 -1
  58. package/dist/adapters/types.d.ts +0 -45
  59. package/dist/adapters/types.d.ts.map +0 -1
  60. package/dist/adapters/types.js +0 -8
  61. package/dist/adapters/types.js.map +0 -1
  62. package/dist/auth/api-key.d.ts.map +0 -1
  63. package/dist/auth/api-key.js +0 -94
  64. package/dist/auth/api-key.js.map +0 -1
  65. package/dist/auth/index.d.ts.map +0 -1
  66. package/dist/auth/types.d.ts.map +0 -1
  67. package/dist/auth/types.js +0 -2
  68. package/dist/auth/types.js.map +0 -1
  69. package/dist/config/costs.d.ts +0 -56
  70. package/dist/config/costs.d.ts.map +0 -1
  71. package/dist/config/costs.js +0 -71
  72. package/dist/config/costs.js.map +0 -1
  73. package/dist/config/index.d.ts +0 -184
  74. package/dist/config/index.d.ts.map +0 -1
  75. package/dist/config/index.js +0 -342
  76. package/dist/config/index.js.map +0 -1
  77. package/dist/config/provider.d.ts +0 -12
  78. package/dist/config/provider.d.ts.map +0 -1
  79. package/dist/config/provider.js +0 -14
  80. package/dist/config/provider.js.map +0 -1
  81. package/dist/core/deferred.d.ts.map +0 -1
  82. package/dist/core/deferred.js.map +0 -1
  83. package/dist/core/errors.d.ts +0 -78
  84. package/dist/core/errors.d.ts.map +0 -1
  85. package/dist/core/errors.js +0 -110
  86. package/dist/core/errors.js.map +0 -1
  87. package/dist/core/index.d.ts.map +0 -1
  88. package/dist/core/operations.d.ts +0 -36
  89. package/dist/core/operations.d.ts.map +0 -1
  90. package/dist/core/operations.js +0 -88
  91. package/dist/core/operations.js.map +0 -1
  92. package/dist/core/types.d.ts.map +0 -1
  93. package/dist/core/types.js +0 -82
  94. package/dist/core/types.js.map +0 -1
  95. package/dist/index.d.ts.map +0 -1
  96. package/dist/notifications/index.d.ts +0 -76
  97. package/dist/notifications/index.d.ts.map +0 -1
  98. package/dist/notifications/index.js +0 -174
  99. package/dist/notifications/index.js.map +0 -1
  100. package/dist/repository/index.d.ts.map +0 -1
  101. package/dist/repository/memory/index.d.ts.map +0 -1
  102. package/dist/repository/memory/index.js +0 -518
  103. package/dist/repository/memory/index.js.map +0 -1
  104. package/dist/repository/types.d.ts.map +0 -1
  105. package/dist/repository/types.js +0 -39
  106. package/dist/repository/types.js.map +0 -1
  107. package/dist/repository/utils.d.ts +0 -22
  108. package/dist/repository/utils.d.ts.map +0 -1
  109. package/dist/repository/utils.js +0 -40
  110. package/dist/repository/utils.js.map +0 -1
  111. package/dist/sdk/admin-client.d.ts +0 -146
  112. package/dist/sdk/admin-client.d.ts.map +0 -1
  113. package/dist/sdk/admin-client.js +0 -196
  114. package/dist/sdk/admin-client.js.map +0 -1
  115. package/dist/sdk/client.d.ts +0 -144
  116. package/dist/sdk/client.d.ts.map +0 -1
  117. package/dist/sdk/client.js +0 -247
  118. package/dist/sdk/client.js.map +0 -1
  119. package/dist/sdk/errors.d.ts +0 -91
  120. package/dist/sdk/errors.d.ts.map +0 -1
  121. package/dist/sdk/errors.js +0 -185
  122. package/dist/sdk/errors.js.map +0 -1
  123. package/dist/sdk/index.d.ts.map +0 -1
  124. package/dist/sdk/types.d.ts +0 -110
  125. package/dist/sdk/types.d.ts.map +0 -1
  126. package/dist/sdk/types.js +0 -20
  127. package/dist/sdk/types.js.map +0 -1
  128. package/dist/service/credits-service.d.ts.map +0 -1
  129. package/dist/service/credits-service.js +0 -368
  130. package/dist/service/credits-service.js.map +0 -1
  131. package/dist/service/index.d.ts.map +0 -1
  132. package/dist/utils/error-utils.d.ts +0 -48
  133. package/dist/utils/error-utils.d.ts.map +0 -1
  134. package/dist/utils/error-utils.js +0 -57
  135. package/dist/utils/error-utils.js.map +0 -1
  136. package/dist/utils/index.d.ts +0 -54
  137. package/dist/utils/index.d.ts.map +0 -1
  138. package/dist/utils/index.js +0 -72
  139. package/dist/utils/index.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAarE;;GAEG;AACH,QAAA,MAAM,wBAAwB;IAC5B;;;;OAIG;;IAMH;;;OAGG;;IAMH;;OAEG;;;;;;;;;;;;;;;;;IAMH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAYH,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAmF1E;;;;;;GAMG;AACH,wBAAgB,iBAAiB,IAAI,OAAO,CAAC,kBAAkB,CAAC,CAuD/D;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,GAAG,kBAAkB,CAsC5F;AAED;;;;GAIG;AACH,wBAAgB,SAAS,IAAI,kBAAkB,CAM9C;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,IAAI,MAAM,EAAE,CAEjD;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE1D;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAQpE;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,gBAAgB,GAAG,UAAU,CAEtE;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,gBAAgB,GAAG,MAAM,CAGpE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,kBAAkB,CAAC,UAAU,CAAC,GAAG,OAAO,CAEvF;AAYD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAM/D;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAQ3D;AAED;;GAEG;AACH,wBAAgB,WAAW,IAAI,IAAI,CAElC"}
@@ -1,342 +0,0 @@
1
- import { z } from "zod";
2
- import { getConfigProvider } from "./provider.js";
3
- /**
4
- * Schema for tier configuration
5
- */
6
- const tierConfigSchema = z.object({
7
- tier: z.enum(["free", "basic", "premium", "unlimited"]),
8
- monthlyCredits: z.number().min(0),
9
- priceUsd: z.number().min(0),
10
- features: z.array(z.string()),
11
- });
12
- /**
13
- * Schema for credit system configuration
14
- */
15
- const creditSystemConfigSchema = z.object({
16
- /**
17
- * Operation costs in credits
18
- * Keys are operation type names (any non-empty string)
19
- * Values are positive numbers representing credit cost
20
- */
21
- operationCosts: z.record(z.string().min(1), z.number().positive()),
22
- /**
23
- * Display labels for operation types (English canonical labels).
24
- * Falls back to auto-generating from snake_case keys if not provided.
25
- */
26
- operationLabels: z.record(z.string().min(1), z.string().min(1)).optional().default({}),
27
- /**
28
- * Tier configurations
29
- */
30
- tierConfigs: z.record(z.enum(["free", "basic", "premium", "unlimited"]), tierConfigSchema),
31
- /**
32
- * Reservation expiry time in milliseconds
33
- */
34
- reservationExpiryMs: z.number().positive().default(5 * 60 * 1000),
35
- /**
36
- * Default credits for new users (free tier)
37
- */
38
- defaultFreeCredits: z.number().positive().default(25),
39
- /**
40
- * Grace period in days after subscription expires before downgrade
41
- */
42
- subscriptionGracePeriodDays: z.number().min(0).default(3),
43
- /**
44
- * Low balance notification threshold
45
- */
46
- lowBalanceThreshold: z.number().min(0).default(10),
47
- /**
48
- * Cooldown in hours between low balance notifications
49
- */
50
- lowBalanceNotificationCooldownHours: z.number().positive().default(24),
51
- /**
52
- * Feature flags for optional features
53
- */
54
- features: z.object({
55
- journalEntries: z.boolean().default(true),
56
- notifications: z.boolean().default(true),
57
- subscriptionExpiry: z.boolean().default(true),
58
- usageHistory: z.boolean().default(true),
59
- }).default({
60
- journalEntries: true,
61
- notifications: true,
62
- subscriptionExpiry: true,
63
- usageHistory: true,
64
- }),
65
- });
66
- /**
67
- * Default configuration
68
- */
69
- const DEFAULT_CONFIG = {
70
- operationCosts: {
71
- story_generation: 5,
72
- conversation: 2,
73
- image_generation: 10,
74
- template_generation: 10,
75
- },
76
- operationLabels: {
77
- story_generation: "Story generation",
78
- conversation: "Conversation",
79
- image_generation: "Image generation",
80
- template_generation: "Template generation",
81
- },
82
- tierConfigs: {
83
- free: {
84
- tier: "free",
85
- monthlyCredits: 25,
86
- priceUsd: 0,
87
- features: [
88
- "25 credits per month",
89
- "Basic story generation",
90
- "Standard image quality",
91
- ],
92
- },
93
- basic: {
94
- tier: "basic",
95
- monthlyCredits: 200,
96
- priceUsd: 9.99,
97
- features: [
98
- "200 credits per month",
99
- "All story features",
100
- "High quality images",
101
- "Priority support",
102
- ],
103
- },
104
- premium: {
105
- tier: "premium",
106
- monthlyCredits: 500,
107
- priceUsd: 19.99,
108
- features: [
109
- "500 credits per month",
110
- "All features",
111
- "Highest quality images",
112
- "Early access to new features",
113
- "Priority support",
114
- ],
115
- },
116
- unlimited: {
117
- tier: "unlimited",
118
- monthlyCredits: 0, // 0 = unlimited
119
- priceUsd: 49.99,
120
- features: [
121
- "Unlimited credits",
122
- "All features",
123
- "Highest quality images",
124
- "Early access to new features",
125
- "Dedicated support",
126
- ],
127
- },
128
- },
129
- reservationExpiryMs: 5 * 60 * 1000, // 5 minutes
130
- defaultFreeCredits: 25,
131
- subscriptionGracePeriodDays: 3,
132
- lowBalanceThreshold: 10,
133
- lowBalanceNotificationCooldownHours: 24,
134
- features: {
135
- journalEntries: true,
136
- notifications: true,
137
- subscriptionExpiry: true,
138
- usageHistory: true,
139
- },
140
- };
141
- /**
142
- * Current configuration (can be overridden)
143
- */
144
- let currentConfig = DEFAULT_CONFIG;
145
- /**
146
- * Load configuration from environment variables
147
- * Can be extended to load from other sources (file, remote config, etc.)
148
- *
149
- * Operation costs are loaded from CREDITS_OPERATION_COSTS as JSON:
150
- * CREDITS_OPERATION_COSTS={"story_generation":5,"image_generation":10}
151
- */
152
- export function loadConfigFromEnv() {
153
- const envConfig = {};
154
- // Load operation costs from env as JSON
155
- const operationCostsEnv = process.env.CREDITS_OPERATION_COSTS;
156
- if (operationCostsEnv) {
157
- try {
158
- const parsed = JSON.parse(operationCostsEnv);
159
- if (typeof parsed === "object" && parsed !== null) {
160
- envConfig.operationCosts = {
161
- ...DEFAULT_CONFIG.operationCosts,
162
- ...parsed,
163
- };
164
- }
165
- }
166
- catch {
167
- console.warn("[Credits Config] Failed to parse CREDITS_OPERATION_COSTS env var as JSON");
168
- }
169
- }
170
- // Load other settings from env
171
- const reservationExpiry = process.env.CREDITS_RESERVATION_EXPIRY_MS;
172
- if (reservationExpiry) {
173
- envConfig.reservationExpiryMs = parseInt(reservationExpiry, 10);
174
- }
175
- const defaultCredits = process.env.CREDITS_DEFAULT_FREE;
176
- if (defaultCredits) {
177
- envConfig.defaultFreeCredits = parseInt(defaultCredits, 10);
178
- }
179
- const gracePeriod = process.env.CREDITS_GRACE_PERIOD_DAYS;
180
- if (gracePeriod) {
181
- envConfig.subscriptionGracePeriodDays = parseInt(gracePeriod, 10);
182
- }
183
- const lowBalanceThreshold = process.env.CREDITS_LOW_BALANCE_THRESHOLD;
184
- if (lowBalanceThreshold) {
185
- envConfig.lowBalanceThreshold = parseInt(lowBalanceThreshold, 10);
186
- }
187
- // Load feature flags
188
- const featuresEnv = process.env.CREDITS_FEATURES;
189
- if (featuresEnv) {
190
- try {
191
- const features = JSON.parse(featuresEnv);
192
- envConfig.features = {
193
- ...DEFAULT_CONFIG.features,
194
- ...features,
195
- };
196
- }
197
- catch {
198
- console.warn("[Credits Config] Failed to parse CREDITS_FEATURES env var");
199
- }
200
- }
201
- return envConfig;
202
- }
203
- /**
204
- * Initialize configuration
205
- * Merges default config with environment overrides
206
- */
207
- export function initializeConfig(overrides) {
208
- const envConfig = loadConfigFromEnv();
209
- const mergedConfig = {
210
- ...DEFAULT_CONFIG,
211
- ...envConfig,
212
- ...overrides,
213
- operationCosts: {
214
- ...DEFAULT_CONFIG.operationCosts,
215
- ...envConfig.operationCosts,
216
- ...overrides?.operationCosts,
217
- },
218
- operationLabels: {
219
- ...DEFAULT_CONFIG.operationLabels,
220
- ...envConfig.operationLabels,
221
- ...overrides?.operationLabels,
222
- },
223
- tierConfigs: {
224
- ...DEFAULT_CONFIG.tierConfigs,
225
- ...envConfig.tierConfigs,
226
- ...overrides?.tierConfigs,
227
- },
228
- features: {
229
- ...DEFAULT_CONFIG.features,
230
- ...envConfig.features,
231
- ...overrides?.features,
232
- },
233
- };
234
- // Validate configuration
235
- const result = creditSystemConfigSchema.safeParse(mergedConfig);
236
- if (!result.success) {
237
- console.error("[Credits Config] Invalid configuration:", result.error.issues);
238
- throw new Error("Invalid credit system configuration");
239
- }
240
- currentConfig = result.data;
241
- return currentConfig;
242
- }
243
- /**
244
- * Get the current configuration.
245
- * If an external provider is registered, delegates to it.
246
- * Otherwise falls back to the local currentConfig.
247
- */
248
- export function getConfig() {
249
- const provider = getConfigProvider();
250
- if (provider) {
251
- return provider.getConfig();
252
- }
253
- return currentConfig;
254
- }
255
- /**
256
- * Get all valid operation types from configuration
257
- * Returns the keys of the operationCosts object
258
- */
259
- export function getValidOperationTypes() {
260
- return Object.keys(getConfig().operationCosts);
261
- }
262
- /**
263
- * Check if an operation type is valid (configured in the system)
264
- * @param type - The operation type to check
265
- * @returns true if the operation type is configured
266
- */
267
- export function isValidOperationType(type) {
268
- return type in getConfig().operationCosts;
269
- }
270
- /**
271
- * Get operation cost from configuration
272
- * @throws Error if the operation type is not configured
273
- */
274
- export function getConfigOperationCost(operationType) {
275
- const cost = getConfig().operationCosts[operationType];
276
- if (cost === undefined) {
277
- throw new Error(`Unknown operation type: ${operationType}. Valid types: ${getValidOperationTypes().join(", ")}`);
278
- }
279
- return cost;
280
- }
281
- /**
282
- * Get tier configuration from configuration
283
- */
284
- export function getConfigTierConfig(tier) {
285
- return getConfig().tierConfigs[tier];
286
- }
287
- /**
288
- * Get monthly limit for a tier from configuration
289
- * Returns Infinity for unlimited tier
290
- */
291
- export function getConfigMonthlyLimit(tier) {
292
- const config = getConfig().tierConfigs[tier];
293
- return config.monthlyCredits === 0 ? Infinity : config.monthlyCredits;
294
- }
295
- /**
296
- * Check if a feature is enabled
297
- */
298
- export function isFeatureEnabled(feature) {
299
- return getConfig().features[feature];
300
- }
301
- /**
302
- * Convert a snake_case string to Title Case.
303
- * E.g., "story_generation" -> "Story Generation"
304
- */
305
- function snakeCaseToTitleCase(str) {
306
- return str
307
- .replace(/_/g, " ")
308
- .replace(/\b\w/g, (c) => c.toUpperCase());
309
- }
310
- /**
311
- * Get the display label for an operation type.
312
- * Falls back to converting snake_case to Title Case if no label is configured.
313
- */
314
- export function getOperationLabel(operationType) {
315
- const labels = getConfig().operationLabels;
316
- if (labels && operationType in labels) {
317
- return labels[operationType];
318
- }
319
- return snakeCaseToTitleCase(operationType);
320
- }
321
- /**
322
- * Get all operation labels as a record.
323
- * For any operation in operationCosts that lacks a label, generates one from the key.
324
- */
325
- export function getOperationLabels() {
326
- const config = getConfig();
327
- const result = {};
328
- for (const key of Object.keys(config.operationCosts)) {
329
- result[key] = config.operationLabels?.[key]
330
- ?? snakeCaseToTitleCase(key);
331
- }
332
- return result;
333
- }
334
- /**
335
- * Reset configuration to defaults (for testing)
336
- */
337
- export function resetConfig() {
338
- currentConfig = DEFAULT_CONFIG;
339
- }
340
- // Initialize configuration on module load
341
- initializeConfig();
342
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAElD;;GAEG;AACH,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC;IACvD,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACjC,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC3B,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;CAC9B,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,wBAAwB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC;;;;OAIG;IACH,cAAc,EAAE,CAAC,CAAC,MAAM,CACtB,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EACjB,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CACtB;IAED;;;OAGG;IACH,eAAe,EAAE,CAAC,CAAC,MAAM,CACvB,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAA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,EAAE,CAAC;IAC1C,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,EAAE,CAAC;QACrD,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC,GAAG,CAAC;eACtC,oBAAoB,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW;IACzB,aAAa,GAAG,cAAc,CAAC;AACjC,CAAC;AAED,0CAA0C;AAC1C,gBAAgB,EAAE,CAAC"}
@@ -1,12 +0,0 @@
1
- import type { CreditSystemConfig } from "./index.js";
2
- /** Interface for external config providers (e.g. Firestore-backed) */
3
- export interface ICreditConfigProvider {
4
- getConfig(): CreditSystemConfig;
5
- }
6
- /** Register an external config provider. Called once at app startup. */
7
- export declare function registerConfigProvider(provider: ICreditConfigProvider): void;
8
- /** Get the registered provider, or null if none registered. */
9
- export declare function getConfigProvider(): ICreditConfigProvider | null;
10
- /** Clear registered provider (for testing). */
11
- export declare function clearConfigProvider(): void;
12
- //# sourceMappingURL=provider.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/config/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD,sEAAsE;AACtE,MAAM,WAAW,qBAAqB;IACpC,SAAS,IAAI,kBAAkB,CAAC;CACjC;AAID,wEAAwE;AACxE,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,qBAAqB,GAAG,IAAI,CAE5E;AAED,+DAA+D;AAC/D,wBAAgB,iBAAiB,IAAI,qBAAqB,GAAG,IAAI,CAEhE;AAED,+CAA+C;AAC/C,wBAAgB,mBAAmB,IAAI,IAAI,CAE1C"}
@@ -1,14 +0,0 @@
1
- let configProvider = null;
2
- /** Register an external config provider. Called once at app startup. */
3
- export function registerConfigProvider(provider) {
4
- configProvider = provider;
5
- }
6
- /** Get the registered provider, or null if none registered. */
7
- export function getConfigProvider() {
8
- return configProvider;
9
- }
10
- /** Clear registered provider (for testing). */
11
- export function clearConfigProvider() {
12
- configProvider = null;
13
- }
14
- //# sourceMappingURL=provider.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/config/provider.ts"],"names":[],"mappings":"AAOA,IAAI,cAAc,GAAiC,IAAI,CAAC;AAExD,wEAAwE;AACxE,MAAM,UAAU,sBAAsB,CAAC,QAA+B;IACpE,cAAc,GAAG,QAAQ,CAAC;AAC5B,CAAC;AAED,+DAA+D;AAC/D,MAAM,UAAU,iBAAiB;IAC/B,OAAO,cAAc,CAAC;AACxB,CAAC;AAED,+CAA+C;AAC/C,MAAM,UAAU,mBAAmB;IACjC,cAAc,GAAG,IAAI,CAAC;AACxB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"deferred.d.ts","sourceRoot":"","sources":["../../src/core/deferred.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;;;;OAOG;IACH,KAAK,CAAC,EAAE,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CACtC;AAED;;;;;GAKG;AACH,eAAO,MAAM,eAAe,EAAE,gBAU7B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,EAAE,gBAMjC,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,CAAC,EAAE,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,KAAK,IAAI,GAC1C,gBAAgB,CAIlB;AAED;;;;;GAKG;AACH,eAAO,MAAM,YAAY,EAAE,gBAI1B,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"deferred.js","sourceRoot":"","sources":["../../src/core/deferred.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAoBH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAqB;IAC/C,KAAK,CAAC,EAAuB;QAC3B,sDAAsD;QACtD,MAAM,SAAS,GAAG,OAAO,YAAY,KAAK,WAAW,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,UAAU,CAAC;QAClF,SAAS,CAAC,GAAG,EAAE;YACb,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;gBACnB,OAAO,CAAC,KAAK,CAAC,gCAAgC,EAAE,KAAK,CAAC,CAAC;YACzD,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAqB;IACnD,KAAK,CAAC,EAAuB;QAC3B,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YACnB,OAAO,CAAC,KAAK,CAAC,gCAAgC,EAAE,KAAK,CAAC,CAAC;QACzD,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,sBAAsB,CACpC,QAA2C;IAE3C,OAAO;QACL,KAAK,EAAE,QAAQ;KAChB,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,YAAY,GAAqB;IAC5C,KAAK,CAAC,GAAwB;QAC5B,2BAA2B;IAC7B,CAAC;CACF,CAAC"}
@@ -1,78 +0,0 @@
1
- /**
2
- * Credit system error classes - framework agnostic
3
- *
4
- * Provides typed error handling for credit operations.
5
- * These errors can be used across different environments.
6
- */
7
- /**
8
- * Error codes for credit operations
9
- */
10
- export declare const CreditErrorCode: {
11
- readonly INSUFFICIENT_CREDITS: "INSUFFICIENT_CREDITS";
12
- readonly RESERVATION_NOT_FOUND: "RESERVATION_NOT_FOUND";
13
- readonly RESERVATION_EXPIRED: "RESERVATION_EXPIRED";
14
- readonly RESERVATION_ALREADY_PROCESSED: "RESERVATION_ALREADY_PROCESSED";
15
- readonly USER_NOT_FOUND: "USER_NOT_FOUND";
16
- readonly INVALID_OPERATION_TYPE: "INVALID_OPERATION_TYPE";
17
- readonly CONFIGURATION_ERROR: "CONFIGURATION_ERROR";
18
- readonly DATABASE_ERROR: "DATABASE_ERROR";
19
- };
20
- export type CreditErrorCodeType = (typeof CreditErrorCode)[keyof typeof CreditErrorCode];
21
- /**
22
- * Custom error class for credit operations
23
- *
24
- * Provides structured error information including:
25
- * - Error code for programmatic handling
26
- * - Human-readable message
27
- * - Optional details for debugging
28
- */
29
- export declare class CreditError extends Error {
30
- readonly code: CreditErrorCodeType;
31
- readonly details?: Record<string, unknown>;
32
- constructor(message: string, code: CreditErrorCodeType, details?: Record<string, unknown>);
33
- /**
34
- * Convert to JSON-serializable object
35
- */
36
- toJSON(): {
37
- name: string;
38
- code: string;
39
- message: string;
40
- details?: Record<string, unknown>;
41
- };
42
- }
43
- /**
44
- * Type guard to check if an error is a CreditError
45
- */
46
- export declare function isCreditError(error: unknown): error is CreditError;
47
- /**
48
- * Check if an error represents insufficient credits
49
- *
50
- * Works with both CreditError and regular Error instances.
51
- * Useful for handling errors from different sources.
52
- */
53
- export declare function isInsufficientCreditsError(error: unknown): boolean;
54
- /**
55
- * Create an insufficient credits error
56
- */
57
- export declare function createInsufficientCreditsError(required: number, available: number): CreditError;
58
- /**
59
- * Create a reservation not found error
60
- */
61
- export declare function createReservationNotFoundError(reservationId: string): CreditError;
62
- /**
63
- * Create a reservation expired error
64
- */
65
- export declare function createReservationExpiredError(reservationId: string): CreditError;
66
- /**
67
- * Create a reservation already processed error
68
- */
69
- export declare function createReservationAlreadyProcessedError(reservationId: string, status: string): CreditError;
70
- /**
71
- * Create a user not found error
72
- */
73
- export declare function createUserNotFoundError(userId: string): CreditError;
74
- /**
75
- * Create an invalid operation type error
76
- */
77
- export declare function createInvalidOperationTypeError(operationType: string, validTypes: string[]): CreditError;
78
- //# sourceMappingURL=errors.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/core/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,eAAO,MAAM,eAAe;;;;;;;;;CASlB,CAAC;AAEX,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,OAAO,eAAe,CAAC,CAAC;AAEzF;;;;;;;GAOG;AACH,qBAAa,WAAY,SAAQ,KAAK;IACpC,SAAgB,IAAI,EAAE,mBAAmB,CAAC;IAC1C,SAAgB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBAGhD,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,mBAAmB,EACzB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAanC;;OAEG;IACH,MAAM,IAAI;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE;CAQ7F;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAElE;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAUlE;AAED;;GAEG;AACH,wBAAgB,8BAA8B,CAC5C,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,GAChB,WAAW,CAMb;AAED;;GAEG;AACH,wBAAgB,8BAA8B,CAAC,aAAa,EAAE,MAAM,GAAG,WAAW,CAMjF;AAED;;GAEG;AACH,wBAAgB,6BAA6B,CAAC,aAAa,EAAE,MAAM,GAAG,WAAW,CAMhF;AAED;;GAEG;AACH,wBAAgB,sCAAsC,CACpD,aAAa,EAAE,MAAM,EACrB,MAAM,EAAE,MAAM,GACb,WAAW,CAMb;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,CAMnE;AAED;;GAEG;AACH,wBAAgB,+BAA+B,CAC7C,aAAa,EAAE,MAAM,EACrB,UAAU,EAAE,MAAM,EAAE,GACnB,WAAW,CAMb"}
@@ -1,110 +0,0 @@
1
- /**
2
- * Credit system error classes - framework agnostic
3
- *
4
- * Provides typed error handling for credit operations.
5
- * These errors can be used across different environments.
6
- */
7
- /**
8
- * Error codes for credit operations
9
- */
10
- export const CreditErrorCode = {
11
- INSUFFICIENT_CREDITS: "INSUFFICIENT_CREDITS",
12
- RESERVATION_NOT_FOUND: "RESERVATION_NOT_FOUND",
13
- RESERVATION_EXPIRED: "RESERVATION_EXPIRED",
14
- RESERVATION_ALREADY_PROCESSED: "RESERVATION_ALREADY_PROCESSED",
15
- USER_NOT_FOUND: "USER_NOT_FOUND",
16
- INVALID_OPERATION_TYPE: "INVALID_OPERATION_TYPE",
17
- CONFIGURATION_ERROR: "CONFIGURATION_ERROR",
18
- DATABASE_ERROR: "DATABASE_ERROR",
19
- };
20
- /**
21
- * Custom error class for credit operations
22
- *
23
- * Provides structured error information including:
24
- * - Error code for programmatic handling
25
- * - Human-readable message
26
- * - Optional details for debugging
27
- */
28
- export class CreditError extends Error {
29
- code;
30
- details;
31
- constructor(message, code, details) {
32
- super(message);
33
- this.name = "CreditError";
34
- this.code = code;
35
- this.details = details;
36
- // Maintains proper stack trace for where error was thrown
37
- if (Error.captureStackTrace) {
38
- Error.captureStackTrace(this, CreditError);
39
- }
40
- }
41
- /**
42
- * Convert to JSON-serializable object
43
- */
44
- toJSON() {
45
- return {
46
- name: this.name,
47
- code: this.code,
48
- message: this.message,
49
- ...(this.details && { details: this.details }),
50
- };
51
- }
52
- }
53
- /**
54
- * Type guard to check if an error is a CreditError
55
- */
56
- export function isCreditError(error) {
57
- return error instanceof CreditError;
58
- }
59
- /**
60
- * Check if an error represents insufficient credits
61
- *
62
- * Works with both CreditError and regular Error instances.
63
- * Useful for handling errors from different sources.
64
- */
65
- export function isInsufficientCreditsError(error) {
66
- if (isCreditError(error)) {
67
- return error.code === CreditErrorCode.INSUFFICIENT_CREDITS;
68
- }
69
- if (error instanceof Error) {
70
- return error.message.toLowerCase().includes("insufficient credits");
71
- }
72
- return false;
73
- }
74
- /**
75
- * Create an insufficient credits error
76
- */
77
- export function createInsufficientCreditsError(required, available) {
78
- return new CreditError(`Insufficient credits: available ${available}, required ${required}`, CreditErrorCode.INSUFFICIENT_CREDITS, { required, available, shortfall: required - available });
79
- }
80
- /**
81
- * Create a reservation not found error
82
- */
83
- export function createReservationNotFoundError(reservationId) {
84
- return new CreditError(`Reservation ${reservationId} not found`, CreditErrorCode.RESERVATION_NOT_FOUND, { reservationId });
85
- }
86
- /**
87
- * Create a reservation expired error
88
- */
89
- export function createReservationExpiredError(reservationId) {
90
- return new CreditError(`Reservation ${reservationId} has expired`, CreditErrorCode.RESERVATION_EXPIRED, { reservationId });
91
- }
92
- /**
93
- * Create a reservation already processed error
94
- */
95
- export function createReservationAlreadyProcessedError(reservationId, status) {
96
- return new CreditError(`Reservation ${reservationId} has already been ${status}`, CreditErrorCode.RESERVATION_ALREADY_PROCESSED, { reservationId, status });
97
- }
98
- /**
99
- * Create a user not found error
100
- */
101
- export function createUserNotFoundError(userId) {
102
- return new CreditError(`User ${userId} not found`, CreditErrorCode.USER_NOT_FOUND, { userId });
103
- }
104
- /**
105
- * Create an invalid operation type error
106
- */
107
- export function createInvalidOperationTypeError(operationType, validTypes) {
108
- return new CreditError(`Invalid operation type: ${operationType}. Valid types: ${validTypes.join(", ")}`, CreditErrorCode.INVALID_OPERATION_TYPE, { operationType, validTypes });
109
- }
110
- //# sourceMappingURL=errors.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/core/errors.ts"],"names":[],"mappings":"AAAA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;AACH,MAAM,UAAU,+BAA+B,CAC7C,aAAqB,EACrB,UAAoB;IAEpB,OAAO,IAAI,WAAW,CACpB,2BAA2B,aAAa,kBAAkB,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EACjF,eAAe,CAAC,sBAAsB,EACtC,EAAE,aAAa,EAAE,UAAU,EAAE,CAC9B,CAAC;AACJ,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,YAAY,EACV,gBAAgB,EAChB,mBAAmB,EACnB,cAAc,EACd,YAAY,EACZ,iBAAiB,EACjB,eAAe,EACf,YAAY,EACZ,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,wBAAwB,EACxB,iBAAiB,EACjB,oBAAoB,EACpB,UAAU,EACV,kBAAkB,GACnB,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,yBAAyB,EACzB,mBAAmB,EACnB,MAAM,GACP,MAAM,YAAY,CAAC;AAGpB,YAAY,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEvD,OAAO,EACL,WAAW,EACX,eAAe,EACf,aAAa,EACb,0BAA0B,EAC1B,8BAA8B,EAC9B,8BAA8B,EAC9B,6BAA6B,EAC7B,sCAAsC,EACtC,uBAAuB,EACvB,+BAA+B,GAChC,MAAM,aAAa,CAAC;AAGrB,YAAY,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEtD,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,YAAY,EACZ,sBAAsB,GACvB,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,4BAA4B,EAC5B,6BAA6B,EAC7B,0BAA0B,GAC3B,MAAM,iBAAiB,CAAC"}
@@ -1,36 +0,0 @@
1
- /**
2
- * Core credit operations - framework agnostic
3
- *
4
- * Contains the business logic for credit operations that can be
5
- * used by any adapter or service implementation.
6
- */
7
- import type { ICreditRepository } from "../repository/types.js";
8
- import type { PortableReservation } from "./types.js";
9
- /**
10
- * Commit a reservation with journal entry
11
- *
12
- * @param repository - The credit repository
13
- * @param userId - User ID
14
- * @param reservationId - Reservation to commit
15
- */
16
- export declare function commitReservationWithJournal(repository: ICreditRepository, userId: string, reservationId: string): Promise<void>;
17
- /**
18
- * Release a reservation with journal entry
19
- *
20
- * @param repository - The credit repository
21
- * @param userId - User ID
22
- * @param reservationId - Reservation to release
23
- */
24
- export declare function releaseReservationWithJournal(repository: ICreditRepository, userId: string, reservationId: string): Promise<void>;
25
- /**
26
- * Reserve credits for an operation
27
- *
28
- * @param repository - The credit repository
29
- * @param userId - User ID
30
- * @param amount - Credits to reserve
31
- * @param operationType - Type of operation
32
- * @param expiryMs - Reservation expiry time in milliseconds
33
- * @returns The reservation
34
- */
35
- export declare function reserveCreditsForOperation(repository: ICreditRepository, userId: string, amount: number, operationType: string, expiryMs?: number): Promise<PortableReservation>;
36
- //# sourceMappingURL=operations.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"operations.d.ts","sourceRoot":"","sources":["../../src/core/operations.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAGtD;;;;;;GAMG;AACH,wBAAsB,4BAA4B,CAChD,UAAU,EAAE,iBAAiB,EAC7B,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,IAAI,CAAC,CA2Bf;AAED;;;;;;GAMG;AACH,wBAAsB,6BAA6B,CACjD,UAAU,EAAE,iBAAiB,EAC7B,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,IAAI,CAAC,CA2Bf;AAED;;;;;;;;;GASG;AACH,wBAAsB,0BAA0B,CAC9C,UAAU,EAAE,iBAAiB,EAC7B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,MAAM,EACrB,QAAQ,GAAE,MAAsB,GAC/B,OAAO,CAAC,mBAAmB,CAAC,CAG9B"}