@compilr-dev/sdk 0.9.18 → 0.9.19

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.
@@ -65,7 +65,14 @@ export class EntitlementCache {
65
65
  */
66
66
  checkLimit(field, currentCount) {
67
67
  if (!this.entitlements) {
68
- return { allowed: true }; // No entitlements loaded yet allow (fail open during init)
68
+ // No entitlements loaded — use offline fallback limits (fail closed, not open)
69
+ const fallbackLimit = OFFLINE_FALLBACK_LIMITS[field];
70
+ if (fallbackLimit === UNLIMITED)
71
+ return { allowed: true };
72
+ if (currentCount >= fallbackLimit) {
73
+ return { allowed: false, reason: 'Entitlements not loaded', current: currentCount, limit: fallbackLimit };
74
+ }
75
+ return { allowed: true, current: currentCount, limit: fallbackLimit };
69
76
  }
70
77
  const limit = this.entitlements.limits[field];
71
78
  // Unlimited
@@ -169,7 +176,10 @@ export class EntitlementCache {
169
176
  const age = Date.now() - parsed.fetchedAtWall;
170
177
  if (age < this.offlineGraceMs) {
171
178
  this.entitlements = parsed.response;
172
- this.fetchedAtMonotonic = process.hrtime.bigint(); // Reset monotonic to now
179
+ // Compute monotonic offset from wall-clock age so isWithinOfflineGrace()
180
+ // returns the correct remaining time (not a fresh 24h window on every restart)
181
+ const ageNs = BigInt(age) * 1000000n;
182
+ this.fetchedAtMonotonic = process.hrtime.bigint() - ageNs;
173
183
  this.fetchedAtWall = parsed.fetchedAtWall;
174
184
  return this.entitlements.limits;
175
185
  }
@@ -180,6 +190,20 @@ export class EntitlementCache {
180
190
  }
181
191
  }
182
192
  // 3. Offline grace expired or no store — degrade to minimal fallback
193
+ // MUST set this.entitlements so checkLimit() doesn't fail open
194
+ this.entitlements = {
195
+ tier: 'free',
196
+ beta: false,
197
+ limits: OFFLINE_FALLBACK_LIMITS,
198
+ pendingPayment: false,
199
+ trialEndsAt: null,
200
+ features: {},
201
+ issuedAt: new Date().toISOString(),
202
+ userId: '',
203
+ signature: '',
204
+ };
205
+ this.fetchedAtMonotonic = process.hrtime.bigint();
206
+ this.fetchedAtWall = Date.now();
183
207
  return OFFLINE_FALLBACK_LIMITS;
184
208
  }
185
209
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@compilr-dev/sdk",
3
- "version": "0.9.18",
3
+ "version": "0.9.19",
4
4
  "description": "Universal agent runtime for building AI-powered applications",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",