@i4e/invest4edu-access-core 0.17.1 → 0.17.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@i4e/invest4edu-access-core",
3
- "version": "0.17.1",
3
+ "version": "0.17.2",
4
4
  "description": "Shared access-control primitives for NeoFindesk: tenant keystone, role capabilities, reportee tree, feature flags, and the unified access engine (registry schema, snapshot resolver, visibleWhen).",
5
5
  "type": "module",
6
6
  "exports": {
@@ -155,8 +155,20 @@ export function createEntitlementStore({ getDb, toObjectId = (v) => v, logger =
155
155
  subscription, entitlementRows: rows, featureCode, feature, used, credits, identity, bypass, now,
156
156
  });
157
157
 
158
- // Carry what consume() needs, so it cannot recompute the period key and count against a
159
- // different bucket than the one that was just checked.
158
+ /**
159
+ * Carry what consume() needs, so it cannot recompute the period key and count against a
160
+ * different bucket than the one that was just checked.
161
+ *
162
+ * The carried row takes its ceiling from the RESOLVED result, not from the raw plan row —
163
+ * because a per-subject override changes the decision without changing the row it came
164
+ * from. Carrying the raw row meant consume guarded on the plan's quota while the check had
165
+ * already passed on the overridden one: a subject granted 5 was refused at 2, and it
166
+ * surfaced as a counter that had simply stopped moving.
167
+ */
168
+ const effectiveRow = row
169
+ ? { ...row, quota: result.quota, overage_policy: result.overage_policy || row.overage_policy }
170
+ : null;
171
+
160
172
  return {
161
173
  ...result,
162
174
  carriedSubjectType: subjectType,
@@ -164,7 +176,7 @@ export function createEntitlementStore({ getDb, toObjectId = (v) => v, logger =
164
176
  carriedSubscriptionId: subscription._id,
165
177
  carriedPeriodStart: subscription.period_start || null,
166
178
  carriedIdentity: identity,
167
- carriedRow: row,
179
+ carriedRow: effectiveRow,
168
180
  };
169
181
  } catch (e) {
170
182
  logger.warn(`[entitlement] resolve failed for ${featureCode}, allowing through: ${e.message}`);