@pioneer-platform/pioneer-cache 1.1.7 → 1.1.9

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,2 +1 @@
1
-
2
- $ tsc
1
+ $ tsc
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @pioneer-platform/pioneer-cache
2
2
 
3
+ ## 1.1.9
4
+
5
+ ### Patch Changes
6
+
7
+ - fix: Use requested caip/pubkey in cache placeholders instead of empty defaults
8
+
9
+ - When cache miss occurs, use the requested caip and pubkey in the placeholder response instead of empty strings
10
+ - Fixes issue where balance cache returned entries with empty caip/pubkey fields causing SDK crashes
11
+ - Affects getBatchBalances and getBalance methods
12
+ - This was causing production Pioneer API to return balances with empty CAIPs that would crash the vault on startup
13
+
14
+ ## 1.1.8
15
+
16
+ ### Patch Changes
17
+
18
+ - Force republish to ensure no workspace:\* references in published packages
19
+
3
20
  ## 1.1.7
4
21
 
5
22
  ### Patch Changes
@@ -76,14 +76,17 @@ class BaseCache {
76
76
  async get(params, waitForFresh) {
77
77
  const tag = this.TAG + 'get | ';
78
78
  const startTime = Date.now();
79
+ const shouldLogTiming = process.env.LOG_CACHE_TIMING === 'true' || process.env.NODE_ENV !== 'production';
79
80
  try {
80
81
  const t1 = Date.now();
81
82
  const key = this.buildKey(params);
82
- log.info(tag, `⏱️ buildKey took ${Date.now() - t1}ms`);
83
+ if (shouldLogTiming)
84
+ log.debug(tag, `⏱️ buildKey took ${Date.now() - t1}ms`);
83
85
  // Step 1: Try new cache format
84
86
  const t2 = Date.now();
85
87
  const cachedValue = await this.getCached(key);
86
- log.info(tag, `⏱️ getCached took ${Date.now() - t2}ms`);
88
+ if (shouldLogTiming)
89
+ log.debug(tag, `⏱️ getCached took ${Date.now() - t2}ms`);
87
90
  if (cachedValue) {
88
91
  const age = Date.now() - cachedValue.timestamp;
89
92
  const responseTime = Date.now() - startTime;
@@ -127,7 +130,8 @@ class BaseCache {
127
130
  if (this.config.enableLegacyFallback) {
128
131
  const t3 = Date.now();
129
132
  const legacyValue = await this.getLegacyCached(params);
130
- log.info(tag, `⏱️ getLegacyCached took ${Date.now() - t3}ms`);
133
+ if (shouldLogTiming)
134
+ log.debug(tag, `⏱️ getLegacyCached took ${Date.now() - t3}ms`);
131
135
  if (legacyValue) {
132
136
  const responseTime = Date.now() - startTime;
133
137
  log.info(tag, `Legacy cache hit: ${key} (${responseTime}ms)`);
@@ -163,8 +167,10 @@ class BaseCache {
163
167
  // Non-blocking: trigger async refresh and return default
164
168
  const t4 = Date.now();
165
169
  this.triggerAsyncRefresh(params, 'high');
166
- log.info(tag, `⏱️ triggerAsyncRefresh took ${Date.now() - t4}ms`);
167
- log.info(tag, `⏱️ Returning default value after ${Date.now() - startTime}ms TOTAL`);
170
+ if (shouldLogTiming) {
171
+ log.debug(tag, `⏱️ triggerAsyncRefresh took ${Date.now() - t4}ms`);
172
+ log.debug(tag, `⏱️ Returning default value after ${Date.now() - startTime}ms TOTAL`);
173
+ }
168
174
  return {
169
175
  success: true,
170
176
  value: this.config.defaultValue,
@@ -200,7 +200,13 @@ class BalanceCache extends base_cache_1.BaseCache {
200
200
  */
201
201
  async getBalance(caip, pubkey, waitForFresh) {
202
202
  const result = await this.get({ caip, pubkey }, waitForFresh);
203
- return result.value || this.config.defaultValue;
203
+ return result.value || {
204
+ caip,
205
+ pubkey,
206
+ balance: '0',
207
+ fetchedAt: Date.now(),
208
+ fetchedAtISO: new Date().toISOString()
209
+ };
204
210
  }
205
211
  /**
206
212
  * Get balances for multiple assets (batch operation)
@@ -266,7 +272,14 @@ class BalanceCache extends base_cache_1.BaseCache {
266
272
  }
267
273
  // Cache miss - record for fetching
268
274
  missedItems.push({ ...item, index: i });
269
- results[i] = this.config.defaultValue; // Placeholder
275
+ // Use requested caip/pubkey in placeholder, not empty defaults
276
+ results[i] = {
277
+ caip: item.caip,
278
+ pubkey: item.pubkey,
279
+ balance: '0',
280
+ fetchedAt: Date.now(),
281
+ fetchedAtISO: new Date().toISOString()
282
+ };
270
283
  }
271
284
  const responseTime = Date.now() - startTime;
272
285
  const hitRate = ((items.length - missedItems.length) / items.length * 100).toFixed(1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pioneer-platform/pioneer-cache",
3
- "version": "1.1.7",
3
+ "version": "1.1.9",
4
4
  "description": "Unified caching system for Pioneer platform with Redis backend",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -96,16 +96,17 @@ export abstract class BaseCache<T> {
96
96
  async get(params: Record<string, any>, waitForFresh?: boolean): Promise<CacheResult<T>> {
97
97
  const tag = this.TAG + 'get | ';
98
98
  const startTime = Date.now();
99
+ const shouldLogTiming = process.env.LOG_CACHE_TIMING === 'true' || process.env.NODE_ENV !== 'production';
99
100
 
100
101
  try {
101
102
  const t1 = Date.now();
102
103
  const key = this.buildKey(params);
103
- log.info(tag, `⏱️ buildKey took ${Date.now() - t1}ms`);
104
+ if (shouldLogTiming) log.debug(tag, `⏱️ buildKey took ${Date.now() - t1}ms`);
104
105
 
105
106
  // Step 1: Try new cache format
106
107
  const t2 = Date.now();
107
108
  const cachedValue = await this.getCached(key);
108
- log.info(tag, `⏱️ getCached took ${Date.now() - t2}ms`);
109
+ if (shouldLogTiming) log.debug(tag, `⏱️ getCached took ${Date.now() - t2}ms`);
109
110
 
110
111
  if (cachedValue) {
111
112
  const age = Date.now() - cachedValue.timestamp;
@@ -159,7 +160,7 @@ export abstract class BaseCache<T> {
159
160
  if (this.config.enableLegacyFallback) {
160
161
  const t3 = Date.now();
161
162
  const legacyValue = await this.getLegacyCached(params);
162
- log.info(tag, `⏱️ getLegacyCached took ${Date.now() - t3}ms`);
163
+ if (shouldLogTiming) log.debug(tag, `⏱️ getLegacyCached took ${Date.now() - t3}ms`);
163
164
  if (legacyValue) {
164
165
  const responseTime = Date.now() - startTime;
165
166
  log.info(tag, `Legacy cache hit: ${key} (${responseTime}ms)`);
@@ -200,8 +201,10 @@ export abstract class BaseCache<T> {
200
201
  // Non-blocking: trigger async refresh and return default
201
202
  const t4 = Date.now();
202
203
  this.triggerAsyncRefresh(params, 'high');
203
- log.info(tag, `⏱️ triggerAsyncRefresh took ${Date.now() - t4}ms`);
204
- log.info(tag, `⏱️ Returning default value after ${Date.now() - startTime}ms TOTAL`);
204
+ if (shouldLogTiming) {
205
+ log.debug(tag, `⏱️ triggerAsyncRefresh took ${Date.now() - t4}ms`);
206
+ log.debug(tag, `⏱️ Returning default value after ${Date.now() - startTime}ms TOTAL`);
207
+ }
205
208
 
206
209
  return {
207
210
  success: true,
@@ -239,7 +239,13 @@ export class BalanceCache extends BaseCache<BalanceData> {
239
239
  */
240
240
  async getBalance(caip: string, pubkey: string, waitForFresh?: boolean): Promise<BalanceData> {
241
241
  const result = await this.get({ caip, pubkey }, waitForFresh);
242
- return result.value || this.config.defaultValue;
242
+ return result.value || {
243
+ caip,
244
+ pubkey,
245
+ balance: '0',
246
+ fetchedAt: Date.now(),
247
+ fetchedAtISO: new Date().toISOString()
248
+ };
243
249
  }
244
250
 
245
251
  /**
@@ -314,7 +320,14 @@ export class BalanceCache extends BaseCache<BalanceData> {
314
320
 
315
321
  // Cache miss - record for fetching
316
322
  missedItems.push({ ...item, index: i });
317
- results[i] = this.config.defaultValue; // Placeholder
323
+ // Use requested caip/pubkey in placeholder, not empty defaults
324
+ results[i] = {
325
+ caip: item.caip,
326
+ pubkey: item.pubkey,
327
+ balance: '0',
328
+ fetchedAt: Date.now(),
329
+ fetchedAtISO: new Date().toISOString()
330
+ };
318
331
  }
319
332
 
320
333
  const responseTime = Date.now() - startTime;