@peax/consent-core 0.6.0 → 0.9.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.
|
@@ -109,7 +109,7 @@ function createConsentMarkupGuard({ consent, root, onIssue }) {
|
|
|
109
109
|
const asyncValue = read(template, "async");
|
|
110
110
|
if (asyncValue !== void 0 && asyncValue !== "true" && asyncValue !== "false") throw new TypeError("Invalid data-peax-async value.");
|
|
111
111
|
const { nonce, integrity, crossOrigin, referrerPolicy } = {
|
|
112
|
-
nonce:
|
|
112
|
+
nonce: template.nonce || void 0,
|
|
113
113
|
integrity: read(template, "integrity"),
|
|
114
114
|
crossOrigin: read(template, "crossOrigin"),
|
|
115
115
|
referrerPolicy: read(template, "referrerPolicy")
|
|
@@ -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 ? Boolean(value) : value == null ? null : domString(value));
|
|
256
|
+
const rest = args.slice(2, 5).map((value, index) => index === 0 ? value === void 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
|
@@ -360,6 +360,7 @@ function createSnapshot(currentAppPolicy, state) {
|
|
|
360
360
|
function snapshotRequirements(snapshot) {
|
|
361
361
|
return Object.freeze(getMismatchedConsent(snapshot).map((requirement) => Object.freeze(requirement)));
|
|
362
362
|
}
|
|
363
|
+
var maxReentrantCommits = 100;
|
|
363
364
|
/** Creates an isolated runtime from decoded data; invalid input creates no instance. */
|
|
364
365
|
function createConsent(input) {
|
|
365
366
|
const result = validateWithSchema(createConsentOptionsSchema, input);
|
|
@@ -367,16 +368,28 @@ function createConsent(input) {
|
|
|
367
368
|
let snapshot = createSnapshot(result.data.currentAppPolicy, result.data.initialState);
|
|
368
369
|
let requirements = snapshotRequirements(snapshot);
|
|
369
370
|
const subscriptions = createConsentSubscription();
|
|
371
|
+
let delivering = false;
|
|
372
|
+
let reentrantCommits = 0;
|
|
370
373
|
function commit(currentAppPolicy, state) {
|
|
371
374
|
if (snapshot.currentAppPolicy === currentAppPolicy && snapshot.state === state) return {
|
|
372
375
|
success: true,
|
|
373
376
|
data: snapshot
|
|
374
377
|
};
|
|
378
|
+
if (delivering && ++reentrantCommits > maxReentrantCommits) throw new RangeError("Consent subscribers kept committing changes on every notification.");
|
|
375
379
|
const next = createSnapshot(currentAppPolicy, state);
|
|
376
380
|
const nextRequirements = snapshotRequirements(next);
|
|
377
381
|
snapshot = next;
|
|
378
382
|
requirements = nextRequirements;
|
|
379
|
-
subscriptions.notify();
|
|
383
|
+
if (delivering) subscriptions.notify();
|
|
384
|
+
else {
|
|
385
|
+
delivering = true;
|
|
386
|
+
reentrantCommits = 0;
|
|
387
|
+
try {
|
|
388
|
+
subscriptions.notify();
|
|
389
|
+
} finally {
|
|
390
|
+
delivering = false;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
380
393
|
return {
|
|
381
394
|
success: true,
|
|
382
395
|
data: next
|