@uniformdev/next-app-router 20.84.0 → 20.85.0

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,8 +1,8 @@
1
1
  import { RootComponentInstance, ComponentInstance } from '@uniformdev/canvas';
2
2
  import { ComponentProps } from '@uniformdev/next-app-router-shared';
3
3
  import React, { ComponentType } from 'react';
4
- import { D as DataClient } from './client-BElN_CWD.mjs';
5
- import { a as ResolvedRouteResult, R as ResolveRouteFunction } from './resolveRouteFromCode-CuJ4JHeb.mjs';
4
+ import { D as DataClient } from './client-CCXGmvoG.mjs';
5
+ import { a as ResolvedRouteResult, R as ResolveRouteFunction } from './resolveRouteFromCode-Db8UEQfh.mjs';
6
6
  import { ClientContextComponent } from '@uniformdev/next-app-router-client';
7
7
 
8
8
  type CompositionCache = {
@@ -1,8 +1,8 @@
1
1
  import { RootComponentInstance, ComponentInstance } from '@uniformdev/canvas';
2
2
  import { ComponentProps } from '@uniformdev/next-app-router-shared';
3
3
  import React, { ComponentType } from 'react';
4
- import { D as DataClient } from './client-BElN_CWD.js';
5
- import { a as ResolvedRouteResult, R as ResolveRouteFunction } from './resolveRouteFromCode-BOvjIvM2.js';
4
+ import { D as DataClient } from './client-CCXGmvoG.js';
5
+ import { a as ResolvedRouteResult, R as ResolveRouteFunction } from './resolveRouteFromCode-Bmb4yFgF.js';
6
6
  import { ClientContextComponent } from '@uniformdev/next-app-router-client';
7
7
 
8
8
  type CompositionCache = {
package/dist/cache.d.mts CHANGED
@@ -1,7 +1,7 @@
1
- import { R as ResolveRouteFunction } from './resolveRouteFromCode-CuJ4JHeb.mjs';
1
+ import { R as ResolveRouteFunction } from './resolveRouteFromCode-Db8UEQfh.mjs';
2
2
  import '@uniformdev/canvas';
3
3
  import '@uniformdev/next-app-router-shared';
4
- import './client-BElN_CWD.mjs';
4
+ import './client-CCXGmvoG.mjs';
5
5
  import '@uniformdev/context';
6
6
 
7
7
  declare const resolveRouteFromCode: ResolveRouteFunction;
package/dist/cache.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { R as ResolveRouteFunction } from './resolveRouteFromCode-BOvjIvM2.js';
1
+ import { R as ResolveRouteFunction } from './resolveRouteFromCode-Bmb4yFgF.js';
2
2
  import '@uniformdev/canvas';
3
3
  import '@uniformdev/next-app-router-shared';
4
- import './client-BElN_CWD.js';
4
+ import './client-CCXGmvoG.js';
5
5
  import '@uniformdev/context';
6
6
 
7
7
  declare const resolveRouteFromCode: ResolveRouteFunction;
@@ -715,6 +715,7 @@ declare class DefaultDataClient implements DataClient {
715
715
  };
716
716
  workflowId?: string;
717
717
  workflowStageId?: string;
718
+ instanceWorkflowId?: string;
718
719
  workflowDefinition?: {
719
720
  id: string;
720
721
  name: string;
@@ -715,6 +715,7 @@ declare class DefaultDataClient implements DataClient {
715
715
  };
716
716
  workflowId?: string;
717
717
  workflowStageId?: string;
718
+ instanceWorkflowId?: string;
718
719
  workflowDefinition?: {
719
720
  id: string;
720
721
  name: string;
package/dist/compat.d.mts CHANGED
@@ -1,12 +1,12 @@
1
1
  import React, { ComponentType } from 'react';
2
2
  import { ComponentProps as ComponentProps$1, ComponentParameter } from '@uniformdev/next-app-router-shared';
3
3
  import { U as UniformTextProps$1 } from './UniformText-ChMwHBw4.mjs';
4
- import { R as ResolveComponentResult, a as ResolveComponentFunction } from './UniformComposition-le6UEB_r.mjs';
4
+ import { R as ResolveComponentResult, a as ResolveComponentFunction } from './UniformComposition-B2WDS8_Y.mjs';
5
5
  import '@uniformdev/next-app-router-client';
6
6
  import '@uniformdev/canvas';
7
- import './client-BElN_CWD.mjs';
7
+ import './client-CCXGmvoG.mjs';
8
8
  import '@uniformdev/context';
9
- import './resolveRouteFromCode-CuJ4JHeb.mjs';
9
+ import './resolveRouteFromCode-Db8UEQfh.mjs';
10
10
 
11
11
  type ComponentContext = ComponentProps$1['component'] & {
12
12
  parameters: Record<string, ComponentParameter>;
package/dist/compat.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  import React, { ComponentType } from 'react';
2
2
  import { ComponentProps as ComponentProps$1, ComponentParameter } from '@uniformdev/next-app-router-shared';
3
3
  import { U as UniformTextProps$1 } from './UniformText-ChMwHBw4.js';
4
- import { R as ResolveComponentResult, a as ResolveComponentFunction } from './UniformComposition-DBO-oo7J.js';
4
+ import { R as ResolveComponentResult, a as ResolveComponentFunction } from './UniformComposition-CKvhCZV3.js';
5
5
  import '@uniformdev/next-app-router-client';
6
6
  import '@uniformdev/canvas';
7
- import './client-BElN_CWD.js';
7
+ import './client-CCXGmvoG.js';
8
8
  import '@uniformdev/context';
9
- import './resolveRouteFromCode-BOvjIvM2.js';
9
+ import './resolveRouteFromCode-Bmb4yFgF.js';
10
10
 
11
11
  type ComponentContext = ComponentProps$1['component'] & {
12
12
  parameters: Record<string, ComponentParameter>;
package/dist/index.d.mts CHANGED
@@ -2,12 +2,12 @@ import { CanvasClient, CompositionDeliveryClient, RouteClient, ComponentInstance
2
2
  import { CacheMode, CanvasCacheMode, ManifestCacheMode, ProjectMapCacheMode, RewriteRequestPathResult } from '@uniformdev/next-app-router-shared';
3
3
  import { ManifestClient } from '@uniformdev/context/api';
4
4
  import { ProjectMapClient } from '@uniformdev/project-map';
5
- import { U as UniformCompositionProps } from './UniformComposition-le6UEB_r.mjs';
6
- export { C as CompositionCache, a as ResolveComponentFunction, R as ResolveComponentResult, b as UniformComposition, c as createCompositionCache } from './UniformComposition-le6UEB_r.mjs';
5
+ import { U as UniformCompositionProps } from './UniformComposition-B2WDS8_Y.mjs';
6
+ export { C as CompositionCache, a as ResolveComponentFunction, R as ResolveComponentResult, b as UniformComposition, c as createCompositionCache } from './UniformComposition-B2WDS8_Y.mjs';
7
7
  import React from 'react';
8
- export { D as DataClient, a as DefaultDataClient, E as EnhanceRouteOptions, G as GetRouteFromMiddlewareOptions, b as GetRouteFromPageStateOptions, c as GetRouteOptions, R as RewriteRouteOptions, d as RewriteRouteResult, e as expireMiddlewareCacheTag } from './client-BElN_CWD.mjs';
9
- import { a as ResolvedRouteResult } from './resolveRouteFromCode-CuJ4JHeb.mjs';
10
- export { R as ResolveRouteFunction, r as resolveRouteFromCode } from './resolveRouteFromCode-CuJ4JHeb.mjs';
8
+ export { D as DataClient, a as DefaultDataClient, E as EnhanceRouteOptions, G as GetRouteFromMiddlewareOptions, b as GetRouteFromPageStateOptions, c as GetRouteOptions, R as RewriteRouteOptions, d as RewriteRouteResult, e as expireMiddlewareCacheTag } from './client-CCXGmvoG.mjs';
9
+ import { a as ResolvedRouteResult } from './resolveRouteFromCode-Db8UEQfh.mjs';
10
+ export { R as ResolveRouteFunction, r as resolveRouteFromCode } from './resolveRouteFromCode-Db8UEQfh.mjs';
11
11
  import '@uniformdev/next-app-router-client';
12
12
  import '@uniformdev/context';
13
13
 
package/dist/index.d.ts CHANGED
@@ -2,12 +2,12 @@ import { CanvasClient, CompositionDeliveryClient, RouteClient, ComponentInstance
2
2
  import { CacheMode, CanvasCacheMode, ManifestCacheMode, ProjectMapCacheMode, RewriteRequestPathResult } from '@uniformdev/next-app-router-shared';
3
3
  import { ManifestClient } from '@uniformdev/context/api';
4
4
  import { ProjectMapClient } from '@uniformdev/project-map';
5
- import { U as UniformCompositionProps } from './UniformComposition-DBO-oo7J.js';
6
- export { C as CompositionCache, a as ResolveComponentFunction, R as ResolveComponentResult, b as UniformComposition, c as createCompositionCache } from './UniformComposition-DBO-oo7J.js';
5
+ import { U as UniformCompositionProps } from './UniformComposition-CKvhCZV3.js';
6
+ export { C as CompositionCache, a as ResolveComponentFunction, R as ResolveComponentResult, b as UniformComposition, c as createCompositionCache } from './UniformComposition-CKvhCZV3.js';
7
7
  import React from 'react';
8
- export { D as DataClient, a as DefaultDataClient, E as EnhanceRouteOptions, G as GetRouteFromMiddlewareOptions, b as GetRouteFromPageStateOptions, c as GetRouteOptions, R as RewriteRouteOptions, d as RewriteRouteResult, e as expireMiddlewareCacheTag } from './client-BElN_CWD.js';
9
- import { a as ResolvedRouteResult } from './resolveRouteFromCode-BOvjIvM2.js';
10
- export { R as ResolveRouteFunction, r as resolveRouteFromCode } from './resolveRouteFromCode-BOvjIvM2.js';
8
+ export { D as DataClient, a as DefaultDataClient, E as EnhanceRouteOptions, G as GetRouteFromMiddlewareOptions, b as GetRouteFromPageStateOptions, c as GetRouteOptions, R as RewriteRouteOptions, d as RewriteRouteResult, e as expireMiddlewareCacheTag } from './client-CCXGmvoG.js';
9
+ import { a as ResolvedRouteResult } from './resolveRouteFromCode-Bmb4yFgF.js';
10
+ export { R as ResolveRouteFunction, r as resolveRouteFromCode } from './resolveRouteFromCode-Bmb4yFgF.js';
11
11
  import '@uniformdev/next-app-router-client';
12
12
  import '@uniformdev/context';
13
13
 
package/dist/index.esm.js CHANGED
@@ -4510,6 +4510,7 @@ var bton = (base64) => {
4510
4510
  }
4511
4511
  return sign ? -number : number;
4512
4512
  };
4513
+ var isZeroCookieScore = (score) => Math.abs(score) < 1;
4513
4514
  var ssr = typeof document === "undefined";
4514
4515
  var UNIFORM_DEFAULT_COOKIE_NAME = "ufvd";
4515
4516
  var UNIFORM_DEFAULT_QUIRK_COOKIE_NAME = `ufvdqk`;
@@ -4517,6 +4518,7 @@ var _cookieName;
4517
4518
  var _quirkCookieName;
4518
4519
  var _cookieAttributes;
4519
4520
  var _quirksEnabled;
4521
+ var _maxBytes;
4520
4522
  var CookieTransitionDataStore = class extends TransitionDataStore {
4521
4523
  constructor({
4522
4524
  serverCookieValue,
@@ -4524,7 +4526,9 @@ var CookieTransitionDataStore = class extends TransitionDataStore {
4524
4526
  quirkCookieValue,
4525
4527
  quirkCookieName = UNIFORM_DEFAULT_QUIRK_COOKIE_NAME,
4526
4528
  cookieName = UNIFORM_DEFAULT_COOKIE_NAME,
4527
- cookieAttributes = { sameSite: "lax" }
4529
+ cookieAttributes = { sameSite: "lax" },
4530
+ maxBytes,
4531
+ onLogMessage
4528
4532
  }) {
4529
4533
  super({
4530
4534
  initialData: ssr ? parseScoreCookie(serverCookieValue, experimental_quirksEnabled ? quirkCookieValue : void 0) : void 0
@@ -4533,10 +4537,20 @@ var CookieTransitionDataStore = class extends TransitionDataStore {
4533
4537
  __privateAdd5(this, _quirkCookieName);
4534
4538
  __privateAdd5(this, _cookieAttributes);
4535
4539
  __privateAdd5(this, _quirksEnabled);
4540
+ __privateAdd5(this, _maxBytes);
4541
+ __publicField3(this, "onLogMessage");
4536
4542
  __privateSet3(this, _cookieName, cookieName);
4537
4543
  __privateSet3(this, _cookieAttributes, cookieAttributes);
4538
4544
  __privateSet3(this, _quirkCookieName, quirkCookieName);
4539
4545
  __privateSet3(this, _quirksEnabled, experimental_quirksEnabled || false);
4546
+ __privateSet3(this, _maxBytes, maxBytes);
4547
+ this.onLogMessage = onLogMessage;
4548
+ const minimumBytes = minimumCookieBytes(cookieName);
4549
+ if (maxBytes !== void 0 && maxBytes < minimumBytes) {
4550
+ throw new Error(
4551
+ `maxBytes of ${maxBytes} is below the ${minimumBytes} bytes the "${cookieName}" cookie costs when it carries nothing but control group membership, so no visitor could ever meet it.`
4552
+ );
4553
+ }
4540
4554
  }
4541
4555
  handleDelete() {
4542
4556
  if (ssr) return Promise.resolve();
@@ -4546,7 +4560,15 @@ var CookieTransitionDataStore = class extends TransitionDataStore {
4546
4560
  async handleUpdateData(_, computedValue) {
4547
4561
  if (ssr) return;
4548
4562
  if (computedValue.consent) {
4549
- api.set(__privateGet5(this, _cookieName), serializeCookie(computedValue), __privateGet5(this, _cookieAttributes));
4563
+ const cookieValue = serializeCookie(computedValue, {
4564
+ maxBytes: __privateGet5(this, _maxBytes),
4565
+ cookieName: __privateGet5(this, _cookieName),
4566
+ onBudgetExceeded: (dropped, bytes, maxBytes) => {
4567
+ var _a;
4568
+ return (_a = this.onLogMessage) == null ? void 0 : _a.call(this, ["info", 151, { dropped, bytes, maxBytes }]);
4569
+ }
4570
+ });
4571
+ api.set(__privateGet5(this, _cookieName), cookieValue, __privateGet5(this, _cookieAttributes));
4550
4572
  if (__privateGet5(this, _quirksEnabled) && Object.keys(computedValue.quirks || {}).length) {
4551
4573
  const quirkCookieValue = serializeQuirks(computedValue.quirks || {});
4552
4574
  api.set(__privateGet5(this, _quirkCookieName), quirkCookieValue, __privateGet5(this, _cookieAttributes));
@@ -4563,6 +4585,7 @@ _cookieName = /* @__PURE__ */ new WeakMap();
4563
4585
  _quirkCookieName = /* @__PURE__ */ new WeakMap();
4564
4586
  _cookieAttributes = /* @__PURE__ */ new WeakMap();
4565
4587
  _quirksEnabled = /* @__PURE__ */ new WeakMap();
4588
+ _maxBytes = /* @__PURE__ */ new WeakMap();
4566
4589
  var TYPE_SEP = "~";
4567
4590
  var PAIR_SEP = "!";
4568
4591
  var KV_SEP = "-";
@@ -4634,18 +4657,66 @@ function decodeCookieType(type) {
4634
4657
  return acc;
4635
4658
  }, {});
4636
4659
  }
4637
- function serializeCookie(data) {
4660
+ function serializeCookie(data, options = {}) {
4661
+ const { maxBytes, cookieName = UNIFORM_DEFAULT_COOKIE_NAME, onBudgetExceeded } = options;
4662
+ const parts = {
4663
+ tests: { ...data.tests },
4664
+ sessionScores: encodeCookieType(data.sessionScores),
4665
+ scores: encodeCookieType(data.scores),
4666
+ controlGroup: data.controlGroup ? "1" : "0",
4667
+ personalizeVariants: encodePersonalizeVariants(data.personalizeVariants)
4668
+ };
4669
+ let value = serializeCookieParts(parts);
4670
+ if (maxBytes === void 0) {
4671
+ return value;
4672
+ }
4673
+ const overhead = encodeCookieName(cookieName).length + 1;
4674
+ const measure = () => overhead + api.converter.write(value, cookieName).length;
4675
+ if (measure() <= maxBytes) {
4676
+ return value;
4677
+ }
4678
+ const candidates = dropCandidates(parts, data);
4679
+ const dropped = [];
4680
+ for (let i = 0; i < candidates.length && measure() > maxBytes; i++) {
4681
+ const { bucket, key } = candidates[i];
4682
+ delete parts[bucket][key];
4683
+ dropped.push(`${bucket}.${key}`);
4684
+ value = serializeCookieParts(parts);
4685
+ }
4686
+ if (dropped.length) {
4687
+ onBudgetExceeded == null ? void 0 : onBudgetExceeded(dropped, measure(), maxBytes);
4688
+ }
4689
+ return value;
4690
+ }
4691
+ function serializeCookieParts(parts) {
4638
4692
  return [
4639
- serializeCookieType(data.tests),
4640
- serializeCookieType(encodeCookieType(data.sessionScores)),
4641
- serializeCookieType(encodeCookieType(data.scores)),
4642
- data.controlGroup ? "1" : "0",
4643
- serializePersonalizeVariants(data)
4693
+ serializeCookieType(parts.tests),
4694
+ serializeCookieType(parts.sessionScores),
4695
+ serializeCookieType(parts.scores),
4696
+ parts.controlGroup,
4697
+ serializeCookieType(parts.personalizeVariants)
4644
4698
  ].join(TYPE_SEP);
4645
4699
  }
4646
- function serializePersonalizeVariants({
4647
- personalizeVariants
4648
- }) {
4700
+ function dropCandidates(parts, data) {
4701
+ const dimensions = ["sessionScores", "scores"].flatMap(
4702
+ (bucket, order) => Object.keys(parts[bucket]).map((key) => {
4703
+ var _a;
4704
+ return { bucket, key, order, score: (_a = data[bucket][key]) != null ? _a : 0 };
4705
+ })
4706
+ );
4707
+ dimensions.sort(
4708
+ (a, b) => Number(isZeroCookieScore(b.score)) - Number(isZeroCookieScore(a.score)) || a.score - b.score || a.order - b.order || (a.key < b.key ? -1 : 1)
4709
+ );
4710
+ const keysOf = (bucket) => Object.keys(parts[bucket]).sort().map((key) => ({ bucket, key }));
4711
+ return [...dimensions, ...keysOf("personalizeVariants"), ...keysOf("tests")];
4712
+ }
4713
+ function minimumCookieBytes(cookieName) {
4714
+ return encodeCookieName(cookieName).length + 6;
4715
+ }
4716
+ function encodeCookieName(name) {
4717
+ return encodeURIComponent(name).replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent).replace(/\(/g, "%28").replace(/\)/g, "%29");
4718
+ }
4719
+ function encodePersonalizeVariants(personalizeVariants) {
4649
4720
  const data = {};
4650
4721
  if (typeof personalizeVariants === "object") {
4651
4722
  Object.keys(personalizeVariants).forEach((personalizationName) => {
@@ -4657,8 +4728,7 @@ function serializePersonalizeVariants({
4657
4728
  data[personalizationName] = results.join(",");
4658
4729
  });
4659
4730
  }
4660
- const serialized = serializeCookieType(data);
4661
- return serialized;
4731
+ return data;
4662
4732
  }
4663
4733
  function decodePersonalizeVariants(data) {
4664
4734
  const parsed = parseCookieType(data);
@@ -4705,6 +4775,7 @@ fetchData_fn = async function() {
4705
4775
  this.signalAsyncDataUpdate(serviceData);
4706
4776
  }
4707
4777
  };
4778
+ var isSystemDimension = (dimension) => dimension.startsWith("$");
4708
4779
  var emptyVisitorData = () => ({
4709
4780
  quirks: {},
4710
4781
  scores: {},
@@ -4840,6 +4911,9 @@ var replaceData_fn;
4840
4911
  var setVisitTimeout_fn;
4841
4912
  var isExpired_fn;
4842
4913
  var handleCaps_fn;
4914
+ var pruningManifest_get;
4915
+ var handlePruning_fn;
4916
+ var pruneScores_fn;
4843
4917
  var defaultData_fn;
4844
4918
  var VisitorDataStore = class {
4845
4919
  constructor(options) {
@@ -4950,6 +5024,7 @@ replaceData_fn = function(data, quiet = false) {
4950
5024
  sessionScores: data.sessionScores,
4951
5025
  onLogMessage: __privateGet5(this, _options).onLogMessage
4952
5026
  });
5027
+ __privateMethod2(this, _VisitorDataStore_instances, handlePruning_fn).call(this, data);
4953
5028
  const haveScoresChanged = !dequal(oldData == null ? void 0 : oldData.visitorData.scores, data.scores);
4954
5029
  const haveSessionScoresChanged = !dequal(oldData == null ? void 0 : oldData.visitorData.sessionScores, data.sessionScores);
4955
5030
  const haveQuirksChanged = !dequal(oldData == null ? void 0 : oldData.visitorData.quirks, data.quirks);
@@ -5022,6 +5097,48 @@ handleCaps_fn = function(scores) {
5022
5097
  }
5023
5098
  }
5024
5099
  };
5100
+ pruningManifest_get = function() {
5101
+ var _a, _b, _c, _d, _e;
5102
+ const project = (_b = (_a = __privateGet5(this, _options).manifest) == null ? void 0 : _a.data) == null ? void 0 : _b.project;
5103
+ const populated = [(_c = project == null ? void 0 : project.pz) == null ? void 0 : _c.sig, (_d = project == null ? void 0 : project.pz) == null ? void 0 : _d.enr, (_e = project == null ? void 0 : project.pz) == null ? void 0 : _e.agg, project == null ? void 0 : project.test].some(
5104
+ (definitions) => definitions && Object.keys(definitions).length > 0
5105
+ );
5106
+ return populated ? __privateGet5(this, _options).manifest : void 0;
5107
+ };
5108
+ handlePruning_fn = function(data) {
5109
+ var _a, _b;
5110
+ const { pruneUnknownTests, pruneUnknownDimensions } = __privateGet5(this, _options);
5111
+ const manifest = pruneUnknownTests || pruneUnknownDimensions ? __privateGet5(this, _VisitorDataStore_instances, pruningManifest_get) : void 0;
5112
+ const pruned = [];
5113
+ if (pruneUnknownTests && manifest) {
5114
+ for (const test in data.tests) {
5115
+ if (!manifest.getTest(test)) {
5116
+ delete data.tests[test];
5117
+ pruned.push(`tests.${test}`);
5118
+ }
5119
+ }
5120
+ }
5121
+ __privateMethod2(this, _VisitorDataStore_instances, pruneScores_fn).call(this, data.scores, "scores", pruned, manifest);
5122
+ __privateMethod2(this, _VisitorDataStore_instances, pruneScores_fn).call(this, data.sessionScores, "sessionScores", pruned, manifest);
5123
+ if (pruned.length) {
5124
+ (_b = (_a = __privateGet5(this, _options)).onLogMessage) == null ? void 0 : _b.call(_a, ["info", 150, pruned]);
5125
+ }
5126
+ };
5127
+ pruneScores_fn = function(scores, bucket, pruned, manifest) {
5128
+ const { pruneUnknownDimensions, pruneZeroScores } = __privateGet5(this, _options);
5129
+ if (!pruneUnknownDimensions && !pruneZeroScores) {
5130
+ return;
5131
+ }
5132
+ const pruneUnknown = pruneUnknownDimensions && manifest;
5133
+ for (const dim in scores) {
5134
+ const isUnknown = pruneUnknown && !isSystemDimension(dim) && !manifest.getDimensionByKey(dim);
5135
+ const isZero = pruneZeroScores && (pruneZeroScores === "round" ? isZeroCookieScore(scores[dim]) : scores[dim] === 0);
5136
+ if (isUnknown || isZero) {
5137
+ delete scores[dim];
5138
+ pruned.push(`${bucket}.${dim}`);
5139
+ }
5140
+ }
5141
+ };
5025
5142
  defaultData_fn = function() {
5026
5143
  var _a, _b, _c;
5027
5144
  return {
@@ -5555,6 +5672,9 @@ var dc2 = (0, import_rfdc3.default)();
5555
5672
 
5556
5673
  // src/config/helpers.ts
5557
5674
  import config from "@uniformdev/next-app-router/config/resolved";
5675
+ var getServerConfig = () => {
5676
+ return config;
5677
+ };
5558
5678
  var getDisabledDevTools = () => {
5559
5679
  var _a;
5560
5680
  if (typeof ((_a = config.context) == null ? void 0 : _a.disableDevTools) === "boolean") {
@@ -6258,6 +6378,7 @@ var UniformContext = async ({ clientContextComponent, result }) => {
6258
6378
  const disableDevTools = getDisabledDevTools();
6259
6379
  const defaultConsent = (_a = result == null ? void 0 : result.pageState.defaultConsent) != null ? _a : getDefaultConsent();
6260
6380
  const experimentalQuirkSerialization = getQuirkSerialization();
6381
+ const contextConfig = getServerConfig().context;
6261
6382
  return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(
6262
6383
  ContextComponent,
6263
6384
  {
@@ -6265,6 +6386,10 @@ var UniformContext = async ({ clientContextComponent, result }) => {
6265
6386
  disableDevTools,
6266
6387
  defaultConsent,
6267
6388
  experimentalQuirkSerialization,
6389
+ cookieMaxBytes: contextConfig == null ? void 0 : contextConfig.cookieMaxBytes,
6390
+ pruneUnknownTests: contextConfig == null ? void 0 : contextConfig.pruneUnknownTests,
6391
+ pruneUnknownDimensions: contextConfig == null ? void 0 : contextConfig.pruneUnknownDimensions,
6392
+ pruneZeroScores: contextConfig == null ? void 0 : contextConfig.pruneZeroScores,
6268
6393
  compositionMetadata
6269
6394
  }
6270
6395
  ));
package/dist/index.js CHANGED
@@ -4536,6 +4536,7 @@ var bton = (base64) => {
4536
4536
  }
4537
4537
  return sign ? -number : number;
4538
4538
  };
4539
+ var isZeroCookieScore = (score) => Math.abs(score) < 1;
4539
4540
  var ssr = typeof document === "undefined";
4540
4541
  var UNIFORM_DEFAULT_COOKIE_NAME = "ufvd";
4541
4542
  var UNIFORM_DEFAULT_QUIRK_COOKIE_NAME = `ufvdqk`;
@@ -4543,6 +4544,7 @@ var _cookieName;
4543
4544
  var _quirkCookieName;
4544
4545
  var _cookieAttributes;
4545
4546
  var _quirksEnabled;
4547
+ var _maxBytes;
4546
4548
  var CookieTransitionDataStore = class extends TransitionDataStore {
4547
4549
  constructor({
4548
4550
  serverCookieValue,
@@ -4550,7 +4552,9 @@ var CookieTransitionDataStore = class extends TransitionDataStore {
4550
4552
  quirkCookieValue,
4551
4553
  quirkCookieName = UNIFORM_DEFAULT_QUIRK_COOKIE_NAME,
4552
4554
  cookieName = UNIFORM_DEFAULT_COOKIE_NAME,
4553
- cookieAttributes = { sameSite: "lax" }
4555
+ cookieAttributes = { sameSite: "lax" },
4556
+ maxBytes,
4557
+ onLogMessage
4554
4558
  }) {
4555
4559
  super({
4556
4560
  initialData: ssr ? parseScoreCookie(serverCookieValue, experimental_quirksEnabled ? quirkCookieValue : void 0) : void 0
@@ -4559,10 +4563,20 @@ var CookieTransitionDataStore = class extends TransitionDataStore {
4559
4563
  __privateAdd5(this, _quirkCookieName);
4560
4564
  __privateAdd5(this, _cookieAttributes);
4561
4565
  __privateAdd5(this, _quirksEnabled);
4566
+ __privateAdd5(this, _maxBytes);
4567
+ __publicField3(this, "onLogMessage");
4562
4568
  __privateSet3(this, _cookieName, cookieName);
4563
4569
  __privateSet3(this, _cookieAttributes, cookieAttributes);
4564
4570
  __privateSet3(this, _quirkCookieName, quirkCookieName);
4565
4571
  __privateSet3(this, _quirksEnabled, experimental_quirksEnabled || false);
4572
+ __privateSet3(this, _maxBytes, maxBytes);
4573
+ this.onLogMessage = onLogMessage;
4574
+ const minimumBytes = minimumCookieBytes(cookieName);
4575
+ if (maxBytes !== void 0 && maxBytes < minimumBytes) {
4576
+ throw new Error(
4577
+ `maxBytes of ${maxBytes} is below the ${minimumBytes} bytes the "${cookieName}" cookie costs when it carries nothing but control group membership, so no visitor could ever meet it.`
4578
+ );
4579
+ }
4566
4580
  }
4567
4581
  handleDelete() {
4568
4582
  if (ssr) return Promise.resolve();
@@ -4572,7 +4586,15 @@ var CookieTransitionDataStore = class extends TransitionDataStore {
4572
4586
  async handleUpdateData(_, computedValue) {
4573
4587
  if (ssr) return;
4574
4588
  if (computedValue.consent) {
4575
- api.set(__privateGet5(this, _cookieName), serializeCookie(computedValue), __privateGet5(this, _cookieAttributes));
4589
+ const cookieValue = serializeCookie(computedValue, {
4590
+ maxBytes: __privateGet5(this, _maxBytes),
4591
+ cookieName: __privateGet5(this, _cookieName),
4592
+ onBudgetExceeded: (dropped, bytes, maxBytes) => {
4593
+ var _a;
4594
+ return (_a = this.onLogMessage) == null ? void 0 : _a.call(this, ["info", 151, { dropped, bytes, maxBytes }]);
4595
+ }
4596
+ });
4597
+ api.set(__privateGet5(this, _cookieName), cookieValue, __privateGet5(this, _cookieAttributes));
4576
4598
  if (__privateGet5(this, _quirksEnabled) && Object.keys(computedValue.quirks || {}).length) {
4577
4599
  const quirkCookieValue = serializeQuirks(computedValue.quirks || {});
4578
4600
  api.set(__privateGet5(this, _quirkCookieName), quirkCookieValue, __privateGet5(this, _cookieAttributes));
@@ -4589,6 +4611,7 @@ _cookieName = /* @__PURE__ */ new WeakMap();
4589
4611
  _quirkCookieName = /* @__PURE__ */ new WeakMap();
4590
4612
  _cookieAttributes = /* @__PURE__ */ new WeakMap();
4591
4613
  _quirksEnabled = /* @__PURE__ */ new WeakMap();
4614
+ _maxBytes = /* @__PURE__ */ new WeakMap();
4592
4615
  var TYPE_SEP = "~";
4593
4616
  var PAIR_SEP = "!";
4594
4617
  var KV_SEP = "-";
@@ -4660,18 +4683,66 @@ function decodeCookieType(type) {
4660
4683
  return acc;
4661
4684
  }, {});
4662
4685
  }
4663
- function serializeCookie(data) {
4686
+ function serializeCookie(data, options = {}) {
4687
+ const { maxBytes, cookieName = UNIFORM_DEFAULT_COOKIE_NAME, onBudgetExceeded } = options;
4688
+ const parts = {
4689
+ tests: { ...data.tests },
4690
+ sessionScores: encodeCookieType(data.sessionScores),
4691
+ scores: encodeCookieType(data.scores),
4692
+ controlGroup: data.controlGroup ? "1" : "0",
4693
+ personalizeVariants: encodePersonalizeVariants(data.personalizeVariants)
4694
+ };
4695
+ let value = serializeCookieParts(parts);
4696
+ if (maxBytes === void 0) {
4697
+ return value;
4698
+ }
4699
+ const overhead = encodeCookieName(cookieName).length + 1;
4700
+ const measure = () => overhead + api.converter.write(value, cookieName).length;
4701
+ if (measure() <= maxBytes) {
4702
+ return value;
4703
+ }
4704
+ const candidates = dropCandidates(parts, data);
4705
+ const dropped = [];
4706
+ for (let i = 0; i < candidates.length && measure() > maxBytes; i++) {
4707
+ const { bucket, key } = candidates[i];
4708
+ delete parts[bucket][key];
4709
+ dropped.push(`${bucket}.${key}`);
4710
+ value = serializeCookieParts(parts);
4711
+ }
4712
+ if (dropped.length) {
4713
+ onBudgetExceeded == null ? void 0 : onBudgetExceeded(dropped, measure(), maxBytes);
4714
+ }
4715
+ return value;
4716
+ }
4717
+ function serializeCookieParts(parts) {
4664
4718
  return [
4665
- serializeCookieType(data.tests),
4666
- serializeCookieType(encodeCookieType(data.sessionScores)),
4667
- serializeCookieType(encodeCookieType(data.scores)),
4668
- data.controlGroup ? "1" : "0",
4669
- serializePersonalizeVariants(data)
4719
+ serializeCookieType(parts.tests),
4720
+ serializeCookieType(parts.sessionScores),
4721
+ serializeCookieType(parts.scores),
4722
+ parts.controlGroup,
4723
+ serializeCookieType(parts.personalizeVariants)
4670
4724
  ].join(TYPE_SEP);
4671
4725
  }
4672
- function serializePersonalizeVariants({
4673
- personalizeVariants
4674
- }) {
4726
+ function dropCandidates(parts, data) {
4727
+ const dimensions = ["sessionScores", "scores"].flatMap(
4728
+ (bucket, order) => Object.keys(parts[bucket]).map((key) => {
4729
+ var _a;
4730
+ return { bucket, key, order, score: (_a = data[bucket][key]) != null ? _a : 0 };
4731
+ })
4732
+ );
4733
+ dimensions.sort(
4734
+ (a, b) => Number(isZeroCookieScore(b.score)) - Number(isZeroCookieScore(a.score)) || a.score - b.score || a.order - b.order || (a.key < b.key ? -1 : 1)
4735
+ );
4736
+ const keysOf = (bucket) => Object.keys(parts[bucket]).sort().map((key) => ({ bucket, key }));
4737
+ return [...dimensions, ...keysOf("personalizeVariants"), ...keysOf("tests")];
4738
+ }
4739
+ function minimumCookieBytes(cookieName) {
4740
+ return encodeCookieName(cookieName).length + 6;
4741
+ }
4742
+ function encodeCookieName(name) {
4743
+ return encodeURIComponent(name).replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent).replace(/\(/g, "%28").replace(/\)/g, "%29");
4744
+ }
4745
+ function encodePersonalizeVariants(personalizeVariants) {
4675
4746
  const data = {};
4676
4747
  if (typeof personalizeVariants === "object") {
4677
4748
  Object.keys(personalizeVariants).forEach((personalizationName) => {
@@ -4683,8 +4754,7 @@ function serializePersonalizeVariants({
4683
4754
  data[personalizationName] = results.join(",");
4684
4755
  });
4685
4756
  }
4686
- const serialized = serializeCookieType(data);
4687
- return serialized;
4757
+ return data;
4688
4758
  }
4689
4759
  function decodePersonalizeVariants(data) {
4690
4760
  const parsed = parseCookieType(data);
@@ -4731,6 +4801,7 @@ fetchData_fn = async function() {
4731
4801
  this.signalAsyncDataUpdate(serviceData);
4732
4802
  }
4733
4803
  };
4804
+ var isSystemDimension = (dimension) => dimension.startsWith("$");
4734
4805
  var emptyVisitorData = () => ({
4735
4806
  quirks: {},
4736
4807
  scores: {},
@@ -4866,6 +4937,9 @@ var replaceData_fn;
4866
4937
  var setVisitTimeout_fn;
4867
4938
  var isExpired_fn;
4868
4939
  var handleCaps_fn;
4940
+ var pruningManifest_get;
4941
+ var handlePruning_fn;
4942
+ var pruneScores_fn;
4869
4943
  var defaultData_fn;
4870
4944
  var VisitorDataStore = class {
4871
4945
  constructor(options) {
@@ -4976,6 +5050,7 @@ replaceData_fn = function(data, quiet = false) {
4976
5050
  sessionScores: data.sessionScores,
4977
5051
  onLogMessage: __privateGet5(this, _options).onLogMessage
4978
5052
  });
5053
+ __privateMethod2(this, _VisitorDataStore_instances, handlePruning_fn).call(this, data);
4979
5054
  const haveScoresChanged = !dequal(oldData == null ? void 0 : oldData.visitorData.scores, data.scores);
4980
5055
  const haveSessionScoresChanged = !dequal(oldData == null ? void 0 : oldData.visitorData.sessionScores, data.sessionScores);
4981
5056
  const haveQuirksChanged = !dequal(oldData == null ? void 0 : oldData.visitorData.quirks, data.quirks);
@@ -5048,6 +5123,48 @@ handleCaps_fn = function(scores) {
5048
5123
  }
5049
5124
  }
5050
5125
  };
5126
+ pruningManifest_get = function() {
5127
+ var _a, _b, _c, _d, _e;
5128
+ const project = (_b = (_a = __privateGet5(this, _options).manifest) == null ? void 0 : _a.data) == null ? void 0 : _b.project;
5129
+ const populated = [(_c = project == null ? void 0 : project.pz) == null ? void 0 : _c.sig, (_d = project == null ? void 0 : project.pz) == null ? void 0 : _d.enr, (_e = project == null ? void 0 : project.pz) == null ? void 0 : _e.agg, project == null ? void 0 : project.test].some(
5130
+ (definitions) => definitions && Object.keys(definitions).length > 0
5131
+ );
5132
+ return populated ? __privateGet5(this, _options).manifest : void 0;
5133
+ };
5134
+ handlePruning_fn = function(data) {
5135
+ var _a, _b;
5136
+ const { pruneUnknownTests, pruneUnknownDimensions } = __privateGet5(this, _options);
5137
+ const manifest = pruneUnknownTests || pruneUnknownDimensions ? __privateGet5(this, _VisitorDataStore_instances, pruningManifest_get) : void 0;
5138
+ const pruned = [];
5139
+ if (pruneUnknownTests && manifest) {
5140
+ for (const test in data.tests) {
5141
+ if (!manifest.getTest(test)) {
5142
+ delete data.tests[test];
5143
+ pruned.push(`tests.${test}`);
5144
+ }
5145
+ }
5146
+ }
5147
+ __privateMethod2(this, _VisitorDataStore_instances, pruneScores_fn).call(this, data.scores, "scores", pruned, manifest);
5148
+ __privateMethod2(this, _VisitorDataStore_instances, pruneScores_fn).call(this, data.sessionScores, "sessionScores", pruned, manifest);
5149
+ if (pruned.length) {
5150
+ (_b = (_a = __privateGet5(this, _options)).onLogMessage) == null ? void 0 : _b.call(_a, ["info", 150, pruned]);
5151
+ }
5152
+ };
5153
+ pruneScores_fn = function(scores, bucket, pruned, manifest) {
5154
+ const { pruneUnknownDimensions, pruneZeroScores } = __privateGet5(this, _options);
5155
+ if (!pruneUnknownDimensions && !pruneZeroScores) {
5156
+ return;
5157
+ }
5158
+ const pruneUnknown = pruneUnknownDimensions && manifest;
5159
+ for (const dim in scores) {
5160
+ const isUnknown = pruneUnknown && !isSystemDimension(dim) && !manifest.getDimensionByKey(dim);
5161
+ const isZero = pruneZeroScores && (pruneZeroScores === "round" ? isZeroCookieScore(scores[dim]) : scores[dim] === 0);
5162
+ if (isUnknown || isZero) {
5163
+ delete scores[dim];
5164
+ pruned.push(`${bucket}.${dim}`);
5165
+ }
5166
+ }
5167
+ };
5051
5168
  defaultData_fn = function() {
5052
5169
  var _a, _b, _c;
5053
5170
  return {
@@ -5581,6 +5698,9 @@ var dc2 = (0, import_rfdc3.default)();
5581
5698
 
5582
5699
  // src/config/helpers.ts
5583
5700
  var import_resolved = __toESM(require("@uniformdev/next-app-router/config/resolved"));
5701
+ var getServerConfig = () => {
5702
+ return import_resolved.default;
5703
+ };
5584
5704
  var getDisabledDevTools = () => {
5585
5705
  var _a;
5586
5706
  if (typeof ((_a = import_resolved.default.context) == null ? void 0 : _a.disableDevTools) === "boolean") {
@@ -6277,6 +6397,7 @@ var UniformContext = async ({ clientContextComponent, result }) => {
6277
6397
  const disableDevTools = getDisabledDevTools();
6278
6398
  const defaultConsent = (_a = result == null ? void 0 : result.pageState.defaultConsent) != null ? _a : getDefaultConsent();
6279
6399
  const experimentalQuirkSerialization = getQuirkSerialization();
6400
+ const contextConfig = getServerConfig().context;
6280
6401
  return /* @__PURE__ */ import_react3.default.createElement(import_react3.default.Fragment, null, /* @__PURE__ */ import_react3.default.createElement(
6281
6402
  ContextComponent,
6282
6403
  {
@@ -6284,6 +6405,10 @@ var UniformContext = async ({ clientContextComponent, result }) => {
6284
6405
  disableDevTools,
6285
6406
  defaultConsent,
6286
6407
  experimentalQuirkSerialization,
6408
+ cookieMaxBytes: contextConfig == null ? void 0 : contextConfig.cookieMaxBytes,
6409
+ pruneUnknownTests: contextConfig == null ? void 0 : contextConfig.pruneUnknownTests,
6410
+ pruneUnknownDimensions: contextConfig == null ? void 0 : contextConfig.pruneUnknownDimensions,
6411
+ pruneZeroScores: contextConfig == null ? void 0 : contextConfig.pruneZeroScores,
6287
6412
  compositionMetadata
6288
6413
  }
6289
6414
  ));