@peax/consent-core 0.9.2 → 0.9.4

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.
@@ -253,7 +253,7 @@ function createXhrInterceptor(target, rules, permissions, report) {
253
253
  if (args.length < 2) return Reflect.apply(nativeOpen, this, args);
254
254
  const method = domString(args[0]);
255
255
  const urlInput = domString(args[1]);
256
- const rest = args.slice(2, 5).map((value, index) => index === 0 ? value === void 0 || Boolean(value) : value == null ? null : domString(value));
256
+ const rest = args.slice(2, 5).map((value, index) => index === 0 ? Boolean(value) : value == null ? null : domString(value));
257
257
  let url;
258
258
  try {
259
259
  url = new target.URL(urlInput, target.document.baseURI);
package/dist/index.js CHANGED
@@ -145,19 +145,12 @@ function createConsentSubscription() {
145
145
  }
146
146
  //#endregion
147
147
  //#region src/consent/evaluateConsent.ts
148
- /**
149
- * Evaluates one use without mutating inputs or performing enforcement.
150
- * Inputs must be validated, with unique policy use IDs and at most one choice
151
- * per use. Denials remain blocked regardless of their consent version.
152
- * A version mismatch blocks only this use, not other unchanged uses.
153
- */
154
- function evaluateConsent({ currentAppPolicy, state, useId }) {
155
- const use = currentAppPolicy.uses.find((use) => use.id === useId);
148
+ /** Decides one use from its declaration and recorded choice, which callers look up their own way. */
149
+ function decideConsent(use, choice) {
156
150
  if (!use) return {
157
151
  allowed: false,
158
152
  reason: "unknown-use"
159
153
  };
160
- const choice = state.choices.find((choice) => choice.useId === useId);
161
154
  if (!choice) return {
162
155
  allowed: false,
163
156
  reason: "undecided"
@@ -180,12 +173,9 @@ function evaluateConsent({ currentAppPolicy, state, useId }) {
180
173
  * input contract. An empty result is not blanket permission: denials are omitted.
181
174
  */
182
175
  function getMismatchedConsent({ currentAppPolicy, state }) {
176
+ const choices = new Map(state.choices.map((choice) => [choice.useId, choice]));
183
177
  return currentAppPolicy.uses.flatMap((use) => {
184
- const evaluation = evaluateConsent({
185
- currentAppPolicy,
186
- state,
187
- useId: use.id
188
- });
178
+ const evaluation = decideConsent(use, choices.get(use.id));
189
179
  if (evaluation.allowed) return [];
190
180
  if (evaluation.reason !== "undecided" && evaluation.reason !== "consent-version-mismatch") return [];
191
181
  return [{
@@ -357,16 +347,22 @@ function createSnapshot(currentAppPolicy, state) {
357
347
  state
358
348
  });
359
349
  }
350
+ function indexSnapshot({ currentAppPolicy, state }) {
351
+ const uses = new Map(currentAppPolicy.uses.map((use) => [use.id, use]));
352
+ const choices = new Map(state.choices.map((choice) => [choice.useId, choice]));
353
+ return (useId) => decideConsent(uses.get(useId), choices.get(useId));
354
+ }
360
355
  function snapshotRequirements(snapshot) {
361
356
  return Object.freeze(getMismatchedConsent(snapshot).map((requirement) => Object.freeze(requirement)));
362
357
  }
363
- var maxReentrantCommits = 100;
358
+ var maxReentrantCommits = 1e3;
364
359
  /** Creates an isolated runtime from decoded data; invalid input creates no instance. */
365
360
  function createConsent(input) {
366
361
  const result = validateWithSchema(createConsentOptionsSchema, input);
367
362
  if (!result.success) return result;
368
363
  let snapshot = createSnapshot(result.data.currentAppPolicy, result.data.initialState);
369
364
  let requirements = snapshotRequirements(snapshot);
365
+ let evaluate = indexSnapshot(snapshot);
370
366
  const subscriptions = createConsentSubscription();
371
367
  let delivering = false;
372
368
  let reentrantCommits = 0;
@@ -380,6 +376,7 @@ function createConsent(input) {
380
376
  const nextRequirements = snapshotRequirements(next);
381
377
  snapshot = next;
382
378
  requirements = nextRequirements;
379
+ evaluate = indexSnapshot(next);
383
380
  if (delivering) subscriptions.notify();
384
381
  else {
385
382
  delivering = true;
@@ -399,10 +396,7 @@ function createConsent(input) {
399
396
  success: true,
400
397
  data: Object.freeze({
401
398
  getSnapshot: () => snapshot,
402
- evaluate: (useId) => evaluateConsent({
403
- ...snapshot,
404
- useId
405
- }),
399
+ evaluate: (useId) => evaluate(useId),
406
400
  getMismatchedConsent: () => requirements,
407
401
  restoreState(input) {
408
402
  const parsed = validateWithSchema(consentStateSchema, input);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peax/consent-core",
3
- "version": "0.9.2",
3
+ "version": "0.9.4",
4
4
  "description": "Framework-independent consent state and runtime primitives.",
5
5
  "keywords": [
6
6
  "consent-management",