@uniformdev/canvas-next-rsc-client 19.79.1-alpha.11 → 19.79.1-alpha.18

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/LICENSE.txt CHANGED
@@ -1,2 +1,2 @@
1
- © 2023 Uniform Systems, Inc. All Rights Reserved.
1
+ © 2024 Uniform Systems, Inc. All Rights Reserved.
2
2
  See details of Uniform Systems, Inc. Master Subscription Agreement here: https://uniform.dev/eula
package/dist/index.d.mts CHANGED
@@ -1,4 +1,5 @@
1
- import { ManifestV2, ContextOptions } from '@uniformdev/context';
1
+ import { ManifestV2, TestEvent, ContextOptions } from '@uniformdev/context';
2
+ import { PersonalizationEvent } from '@uniformdev/context/*';
2
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
3
4
  import { PureContextualEditingComponentWrapperProps } from '@uniformdev/canvas-react/core';
4
5
  import * as react from 'react';
@@ -18,6 +19,16 @@ type ClientContextComponentProps = {
18
19
  };
19
20
  type ClientContextComponent = (props: ClientContextComponentProps) => JSX.Element | null;
20
21
 
22
+ declare const ClientContextPersonalizationTransfer: ({ event, ts, }: {
23
+ event: PersonalizationEvent;
24
+ ts: number;
25
+ }) => null;
26
+
27
+ declare const ClientContextTestTransfer: ({ event, ts }: {
28
+ event: TestEvent;
29
+ ts: number;
30
+ }) => null;
31
+
21
32
  declare const ClientContextualEditingComponentWrapper: (props: PropsWithChildren<PureContextualEditingComponentWrapperProps>) => react_jsx_runtime.JSX.Element;
22
33
 
23
34
  declare const ClientContextUpdate: () => react_jsx_runtime.JSX.Element;
@@ -56,4 +67,4 @@ declare const useUniformContext: () => {
56
67
  context: AppDirectoryContext | undefined;
57
68
  };
58
69
 
59
- export { ClientContextComponent, ClientContextComponentProps, ClientContextUpdate, ClientContextualEditingComponentWrapper, ContextUpdateTransferClient, CreateClientUniformContextOptions, DefaultUniformClientContext, PersonalizeClient, PersonalizeClientProps, TestClient, UniformScript, createClientUniformContext, useInitUniformContext, useUniformContext };
70
+ export { type ClientContextComponent, type ClientContextComponentProps, ClientContextPersonalizationTransfer, ClientContextTestTransfer, ClientContextUpdate, ClientContextualEditingComponentWrapper, ContextUpdateTransferClient, type CreateClientUniformContextOptions, DefaultUniformClientContext, PersonalizeClient, type PersonalizeClientProps, TestClient, UniformScript, createClientUniformContext, useInitUniformContext, useUniformContext };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { ManifestV2, ContextOptions } from '@uniformdev/context';
1
+ import { ManifestV2, TestEvent, ContextOptions } from '@uniformdev/context';
2
+ import { PersonalizationEvent } from '@uniformdev/context/*';
2
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
3
4
  import { PureContextualEditingComponentWrapperProps } from '@uniformdev/canvas-react/core';
4
5
  import * as react from 'react';
@@ -18,6 +19,16 @@ type ClientContextComponentProps = {
18
19
  };
19
20
  type ClientContextComponent = (props: ClientContextComponentProps) => JSX.Element | null;
20
21
 
22
+ declare const ClientContextPersonalizationTransfer: ({ event, ts, }: {
23
+ event: PersonalizationEvent;
24
+ ts: number;
25
+ }) => null;
26
+
27
+ declare const ClientContextTestTransfer: ({ event, ts }: {
28
+ event: TestEvent;
29
+ ts: number;
30
+ }) => null;
31
+
21
32
  declare const ClientContextualEditingComponentWrapper: (props: PropsWithChildren<PureContextualEditingComponentWrapperProps>) => react_jsx_runtime.JSX.Element;
22
33
 
23
34
  declare const ClientContextUpdate: () => react_jsx_runtime.JSX.Element;
@@ -56,4 +67,4 @@ declare const useUniformContext: () => {
56
67
  context: AppDirectoryContext | undefined;
57
68
  };
58
69
 
59
- export { ClientContextComponent, ClientContextComponentProps, ClientContextUpdate, ClientContextualEditingComponentWrapper, ContextUpdateTransferClient, CreateClientUniformContextOptions, DefaultUniformClientContext, PersonalizeClient, PersonalizeClientProps, TestClient, UniformScript, createClientUniformContext, useInitUniformContext, useUniformContext };
70
+ export { type ClientContextComponent, type ClientContextComponentProps, ClientContextPersonalizationTransfer, ClientContextTestTransfer, ClientContextUpdate, ClientContextualEditingComponentWrapper, ContextUpdateTransferClient, type CreateClientUniformContextOptions, DefaultUniformClientContext, PersonalizeClient, type PersonalizeClientProps, TestClient, UniformScript, createClientUniformContext, useInitUniformContext, useUniformContext };
package/dist/index.esm.js CHANGED
@@ -233,6 +233,63 @@ var require_rfdc = __commonJS({
233
233
  }
234
234
  });
235
235
 
236
+ // src/components/ClientContextPersonalizationTransfer.tsx
237
+ import { useEffect as useEffect2, useState as useState2 } from "react";
238
+
239
+ // src/hooks/useUniformContext.ts
240
+ import { useEffect, useState } from "react";
241
+ var useUniformContext = () => {
242
+ const [context, setContext] = useState(
243
+ typeof window !== "undefined" ? window.__UNIFORM_CONTEXT__ : void 0
244
+ );
245
+ useEffect(() => {
246
+ const listener = () => {
247
+ setContext(window.__UNIFORM_CONTEXT__);
248
+ };
249
+ window.addEventListener("uniform.context.loaded", listener);
250
+ return () => {
251
+ window.removeEventListener("uniform.context.loaded", listener);
252
+ };
253
+ }, []);
254
+ return {
255
+ context
256
+ };
257
+ };
258
+
259
+ // src/components/ClientContextPersonalizationTransfer.tsx
260
+ var ClientContextPersonalizationTransfer = ({
261
+ event,
262
+ ts
263
+ }) => {
264
+ const { context } = useUniformContext();
265
+ const [lastLogged, setLastLogged] = useState2(void 0);
266
+ useEffect2(() => {
267
+ const shouldBeLogged = !ts || lastLogged !== ts;
268
+ const hasContext = typeof context !== "undefined";
269
+ if (shouldBeLogged && hasContext) {
270
+ setLastLogged(ts);
271
+ context.internal_processPersonalizationEvent(event);
272
+ }
273
+ }, [context, event, lastLogged, ts]);
274
+ return null;
275
+ };
276
+
277
+ // src/components/ClientContextTestTransfer.tsx
278
+ import { useEffect as useEffect3, useState as useState3 } from "react";
279
+ var ClientContextTestTransfer = ({ event, ts }) => {
280
+ const { context } = useUniformContext();
281
+ const [lastLogged, setLastLogged] = useState3(void 0);
282
+ useEffect3(() => {
283
+ const shouldBeLogged = !ts || lastLogged !== ts;
284
+ const hasContext = typeof context !== "undefined";
285
+ if (shouldBeLogged && hasContext && event.variantId) {
286
+ setLastLogged(ts);
287
+ context.internal_processTestEvent(event);
288
+ }
289
+ }, [context, event, lastLogged, ts]);
290
+ return null;
291
+ };
292
+
236
293
  // src/components/ClientContextualEditingComponentWrapper.tsx
237
294
  import { IN_CONTEXT_EDITOR_QUERY_STRING_PARAM } from "@uniformdev/canvas";
238
295
  import {
@@ -258,29 +315,7 @@ var ClientContextualEditingComponentWrapperInner = ({
258
315
 
259
316
  // src/components/ClientContextUpdate.tsx
260
317
  import { useParams, useSearchParams as useSearchParams2 } from "next/navigation";
261
- import { Suspense as Suspense2, useEffect as useEffect2 } from "react";
262
-
263
- // src/hooks/useUniformContext.ts
264
- import { useEffect, useState } from "react";
265
- var useUniformContext = () => {
266
- const [context, setContext] = useState(
267
- typeof window !== "undefined" ? window.__UNIFORM_CONTEXT__ : void 0
268
- );
269
- useEffect(() => {
270
- const listener = () => {
271
- setContext(window.__UNIFORM_CONTEXT__);
272
- };
273
- window.addEventListener("uniform.context.loaded", listener);
274
- return () => {
275
- window.removeEventListener("uniform.context.loaded", listener);
276
- };
277
- }, []);
278
- return {
279
- context
280
- };
281
- };
282
-
283
- // src/components/ClientContextUpdate.tsx
318
+ import { Suspense as Suspense2, useEffect as useEffect4 } from "react";
284
319
  import { Fragment as Fragment2, jsx as jsx2 } from "react/jsx-runtime";
285
320
  var ClientContextUpdate = () => {
286
321
  return /* @__PURE__ */ jsx2(Suspense2, { children: /* @__PURE__ */ jsx2(ClientContextUpdateInner, {}) });
@@ -289,7 +324,7 @@ var ClientContextUpdateInner = () => {
289
324
  const params = useParams();
290
325
  const searchParams = useSearchParams2();
291
326
  const { context } = useUniformContext();
292
- useEffect2(() => {
327
+ useEffect4(() => {
293
328
  if (!context || typeof window === "undefined") {
294
329
  return;
295
330
  }
@@ -303,14 +338,14 @@ var ClientContextUpdateInner = () => {
303
338
  };
304
339
 
305
340
  // src/components/ContextUpdateTransferClient.tsx
306
- import { useEffect as useEffect3, useState as useState2 } from "react";
341
+ import { useEffect as useEffect5, useState as useState4 } from "react";
307
342
  var ContextUpdateTransferClient = ({
308
343
  update,
309
344
  ts
310
345
  }) => {
311
346
  const { context } = useUniformContext();
312
- const [lastLogged, setLastLogged] = useState2(void 0);
313
- useEffect3(() => {
347
+ const [lastLogged, setLastLogged] = useState4(void 0);
348
+ useEffect5(() => {
314
349
  const shouldBeLogged = (!ts || lastLogged !== ts) && Object.keys(update).length > 0;
315
350
  const hasContext = typeof context !== "undefined";
316
351
  if (shouldBeLogged && hasContext) {
@@ -473,19 +508,6 @@ var __privateMethod = (obj, member, method) => {
473
508
  return method;
474
509
  };
475
510
  var ENR_SEPARATOR = "_";
476
- var _evaluator;
477
- var _onLogMessage;
478
- _evaluator = /* @__PURE__ */ new WeakMap();
479
- _onLogMessage = /* @__PURE__ */ new WeakMap();
480
- var _mf;
481
- var _signalInstances;
482
- var _onLogMessage2;
483
- _mf = /* @__PURE__ */ new WeakMap();
484
- _signalInstances = /* @__PURE__ */ new WeakMap();
485
- _onLogMessage2 = /* @__PURE__ */ new WeakMap();
486
- function getEnrichmentVectorKey(category, value) {
487
- return `${category}${ENR_SEPARATOR}${value}`;
488
- }
489
511
  function isNumberMatch(lhs, match) {
490
512
  var _a;
491
513
  if (typeof lhs === "undefined" || lhs === null) {
@@ -515,6 +537,13 @@ function explainNumberMatch(lhs, match) {
515
537
  function explainNumberMatchCriteria(match) {
516
538
  return `${match.op} ${match.rhs}`;
517
539
  }
540
+ function getEnrichmentVectorKey(category, value) {
541
+ return `${category}${ENR_SEPARATOR}${value}`;
542
+ }
543
+ var _goal;
544
+ var _id;
545
+ _goal = /* @__PURE__ */ new WeakMap();
546
+ _id = /* @__PURE__ */ new WeakMap();
518
547
  var pageViewCountDimension = getEnrichmentVectorKey("$pvc", "v");
519
548
  var pageViewCountEvaluator = ({ update, criteria, commands, onLogMessage }) => {
520
549
  var _a, _b;
@@ -552,6 +581,26 @@ var pageViewCountEvaluator = ({ update, criteria, commands, onLogMessage }) => {
552
581
  pageViewCountEvaluator.alwaysExecute = true;
553
582
  var _evaluators;
554
583
  _evaluators = /* @__PURE__ */ new WeakMap();
584
+ var _goal2;
585
+ var _id2;
586
+ _goal2 = /* @__PURE__ */ new WeakMap();
587
+ _id2 = /* @__PURE__ */ new WeakMap();
588
+ var _goal3;
589
+ var _id3;
590
+ _goal3 = /* @__PURE__ */ new WeakMap();
591
+ _id3 = /* @__PURE__ */ new WeakMap();
592
+ var _evaluator;
593
+ var _onLogMessage;
594
+ _evaluator = /* @__PURE__ */ new WeakMap();
595
+ _onLogMessage = /* @__PURE__ */ new WeakMap();
596
+ var _mf;
597
+ var _signalInstances;
598
+ var _goalEvaluators;
599
+ var _onLogMessage2;
600
+ _mf = /* @__PURE__ */ new WeakMap();
601
+ _signalInstances = /* @__PURE__ */ new WeakMap();
602
+ _goalEvaluators = /* @__PURE__ */ new WeakMap();
603
+ _onLogMessage2 = /* @__PURE__ */ new WeakMap();
555
604
  var _data;
556
605
  var _initialData;
557
606
  var _mitt;
@@ -586,6 +635,7 @@ var emptyVisitorData = () => ({
586
635
  scores: {},
587
636
  sessionScores: {},
588
637
  tests: {},
638
+ goals: {},
589
639
  consent: false,
590
640
  controlGroup: false
591
641
  });
@@ -617,7 +667,7 @@ currentData_get = function() {
617
667
  };
618
668
  _replaceData = /* @__PURE__ */ new WeakSet();
619
669
  replaceData_fn = function(data, quiet = false) {
620
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
670
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
621
671
  const oldData = __privateGet(this, _currentData, currentData_get);
622
672
  const now = Date.now();
623
673
  if (data.controlGroup) {
@@ -638,6 +688,7 @@ replaceData_fn = function(data, quiet = false) {
638
688
  const haveSessionScoresChanged = !dequal(oldData == null ? void 0 : oldData.visitorData.sessionScores, data.sessionScores);
639
689
  const haveQuirksChanged = !dequal(oldData == null ? void 0 : oldData.visitorData.quirks, data.quirks);
640
690
  const haveTestsChanged = !dequal(oldData == null ? void 0 : oldData.visitorData.tests, data.tests);
691
+ const haveGoalsChanged = !dequal(oldData == null ? void 0 : oldData.visitorData.goals, data.goals);
641
692
  const updatedData = {
642
693
  updated: now,
643
694
  visitorData: data
@@ -662,6 +713,15 @@ replaceData_fn = function(data, quiet = false) {
662
713
  __privateGet(this, _mitt2).emit("controlGroupUpdated", data);
663
714
  (_i = (_h = __privateGet(this, _options)).onLogMessage) == null ? void 0 : _i.call(_h, ["debug", 104, (_g = data.controlGroup) != null ? _g : false]);
664
715
  }
716
+ if (haveGoalsChanged) {
717
+ const newGoalKeys = Object.keys((_j = data.goals) != null ? _j : {});
718
+ for (let i = 0; i < newGoalKeys.length; i++) {
719
+ const key = newGoalKeys[i];
720
+ if (!((_k = oldData == null ? void 0 : oldData.visitorData.goals) == null ? void 0 : _k[key])) {
721
+ __privateGet(this, _mitt2).emit("goalConverted", { goalId: key });
722
+ }
723
+ }
724
+ }
665
725
  }
666
726
  };
667
727
  _setVisitTimeout = /* @__PURE__ */ new WeakSet();
@@ -712,9 +772,12 @@ var _serverTransitionState;
712
772
  var _scores;
713
773
  var _state;
714
774
  var _pzCache;
775
+ var _plugins;
715
776
  var _mitt3;
716
777
  var _emitTest;
717
778
  var emitTest_fn;
779
+ var _updateGoals;
780
+ var updateGoals_fn;
718
781
  var _updateComputedScores;
719
782
  var updateComputedScores_fn;
720
783
  var _calculateScores;
@@ -723,17 +786,29 @@ _serverTransitionState = /* @__PURE__ */ new WeakMap();
723
786
  _scores = /* @__PURE__ */ new WeakMap();
724
787
  _state = /* @__PURE__ */ new WeakMap();
725
788
  _pzCache = /* @__PURE__ */ new WeakMap();
789
+ _plugins = /* @__PURE__ */ new WeakMap();
726
790
  _mitt3 = /* @__PURE__ */ new WeakMap();
727
791
  _emitTest = /* @__PURE__ */ new WeakSet();
728
792
  emitTest_fn = function(event) {
729
793
  __privateGet(this, _mitt3).emit("testResult", event);
730
794
  };
795
+ _updateGoals = /* @__PURE__ */ new WeakSet();
796
+ updateGoals_fn = async function(data) {
797
+ const goalCommands = this.manifest.computeGoals(data);
798
+ if (goalCommands.length !== 0) {
799
+ await this.storage.updateData(goalCommands);
800
+ }
801
+ };
731
802
  _updateComputedScores = /* @__PURE__ */ new WeakSet();
732
803
  updateComputedScores_fn = function(newData) {
733
804
  const newScores = __privateMethod(this, _calculateScores, calculateScores_fn).call(this, newData);
734
805
  const newScoresHaveChanged = !dequal(newScores, __privateGet(this, _scores));
735
806
  if (newScoresHaveChanged) {
736
807
  __privateSet(this, _scores, newScores);
808
+ __privateMethod(this, _updateGoals, updateGoals_fn).call(this, {
809
+ scores: __privateGet(this, _scores),
810
+ quirks: void 0
811
+ });
737
812
  __privateGet(this, _mitt3).emit("scoresUpdated", newScores);
738
813
  __privateGet(this, _mitt3).emit("log", ["info", 3, newScores]);
739
814
  }
@@ -826,10 +901,8 @@ function enableContextDevTools(options) {
826
901
  context.events.on("personalizationResult", onPersonalizationResult);
827
902
  context.events.on("testResult", onTestResult);
828
903
  context.events.on("scoresUpdated", onContextDataUpdated);
829
- context.storage.events.on("*", onContextDataUpdated);
830
904
  return () => {
831
905
  context.events.off("scoresUpdated", onContextDataUpdated);
832
- context.storage.events.off("*", onContextDataUpdated);
833
906
  context.events.off("personalizationResult", onPersonalizationResult);
834
907
  context.events.off("testResult", onTestResult);
835
908
  };
@@ -874,10 +947,10 @@ var createClientUniformContext = (options) => {
874
947
  };
875
948
 
876
949
  // src/hooks/useInitUniformContext.ts
877
- import { useEffect as useEffect4, useState as useState3 } from "react";
950
+ import { useEffect as useEffect6, useState as useState5 } from "react";
878
951
  var useInitUniformContext = (callback) => {
879
- const [called, setCalled] = useState3(false);
880
- useEffect4(() => {
952
+ const [called, setCalled] = useState5(false);
953
+ useEffect6(() => {
881
954
  if (typeof window === "undefined" || called || typeof window.__UNIFORM_CONTEXT__ !== "undefined") {
882
955
  return;
883
956
  }
@@ -913,12 +986,12 @@ var DefaultUniformClientContext = ({ manifest, disableDevTools }) => {
913
986
  // src/components/PersonalizeClient.ts
914
987
  import { CANVAS_PERSONALIZE_SLOT } from "@uniformdev/canvas";
915
988
  import { runPersonalization } from "@uniformdev/canvas-next-rsc-shared";
916
- import { createElement, Fragment as Fragment3, useEffect as useEffect5, useState as useState4 } from "react";
989
+ import { createElement, Fragment as Fragment3, useEffect as useEffect7, useState as useState6 } from "react";
917
990
  var PersonalizeClient = (props) => {
918
991
  const { slots } = props;
919
992
  const { context } = useUniformContext();
920
- const [indexesToShow, setIndexesToShow] = useState4(props.indexes);
921
- useEffect5(() => {
993
+ const [indexesToShow, setIndexesToShow] = useState6(props.indexes);
994
+ useEffect7(() => {
922
995
  const result = runPersonalization({
923
996
  ...props,
924
997
  contextInstance: context
@@ -935,13 +1008,13 @@ var PersonalizeClient = (props) => {
935
1008
  // src/components/TestClient.ts
936
1009
  import { CANVAS_TEST_SLOT } from "@uniformdev/canvas";
937
1010
  import { runTest } from "@uniformdev/canvas-next-rsc-shared";
938
- import { createElement as createElement2, Fragment as Fragment4, useEffect as useEffect6, useState as useState5 } from "react";
1011
+ import { createElement as createElement2, Fragment as Fragment4, useEffect as useEffect8, useState as useState7 } from "react";
939
1012
  var TestClient = (props) => {
940
1013
  var _a;
941
1014
  const { slots } = props;
942
1015
  const { context } = useUniformContext();
943
- const [index, setIndex] = useState5(0);
944
- useEffect6(() => {
1016
+ const [index, setIndex] = useState7(0);
1017
+ useEffect8(() => {
945
1018
  const result = runTest({
946
1019
  ...props,
947
1020
  contextInstance: context
@@ -961,7 +1034,7 @@ import {
961
1034
  isAllowedReferrer
962
1035
  } from "@uniformdev/canvas";
963
1036
  import { useRouter as useRouter2, useSearchParams as useSearchParams3 } from "next/navigation";
964
- import { useEffect as useEffect7, useMemo, useRef } from "react";
1037
+ import { useEffect as useEffect9, useMemo, useRef } from "react";
965
1038
  import { Fragment as Fragment5, jsx as jsx3 } from "react/jsx-runtime";
966
1039
  var UniformScript = () => {
967
1040
  const router = useRouter2();
@@ -979,7 +1052,7 @@ var UniformScript = () => {
979
1052
  });
980
1053
  return instance;
981
1054
  }, []);
982
- useEffect7(() => {
1055
+ useEffect9(() => {
983
1056
  if (!channel) {
984
1057
  return;
985
1058
  }
@@ -996,7 +1069,7 @@ var UniformScript = () => {
996
1069
  unsubscribeFromEditorUpdates();
997
1070
  };
998
1071
  }, [channel, router]);
999
- useEffect7(() => {
1072
+ useEffect9(() => {
1000
1073
  if (typeof window === "undefined") {
1001
1074
  return;
1002
1075
  }
@@ -1017,7 +1090,7 @@ var UniformScript = () => {
1017
1090
  existing.remove();
1018
1091
  }
1019
1092
  }, [enabled]);
1020
- useEffect7(() => {
1093
+ useEffect9(() => {
1021
1094
  const handleBlurChange = () => {
1022
1095
  if (needsToRefreshRef.current) {
1023
1096
  router.refresh();
@@ -1032,6 +1105,8 @@ var UniformScript = () => {
1032
1105
  return /* @__PURE__ */ jsx3(Fragment5, {});
1033
1106
  };
1034
1107
  export {
1108
+ ClientContextPersonalizationTransfer,
1109
+ ClientContextTestTransfer,
1035
1110
  ClientContextUpdate,
1036
1111
  ClientContextualEditingComponentWrapper,
1037
1112
  ContextUpdateTransferClient,
package/dist/index.js CHANGED
@@ -33,7 +33,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
33
33
 
34
34
  // ../../node_modules/.pnpm/rfdc@1.3.0/node_modules/rfdc/index.js
35
35
  var require_rfdc = __commonJS({
36
- "../../node_modules/.pnpm/rfdc@1.3.0/node_modules/rfdc/index.js"(exports, module2) {
36
+ "../../node_modules/.pnpm/rfdc@1.3.0/node_modules/rfdc/index.js"(exports2, module2) {
37
37
  "use strict";
38
38
  module2.exports = rfdc4;
39
39
  function copyBuffer(cur) {
@@ -242,6 +242,8 @@ var require_rfdc = __commonJS({
242
242
  // src/index.ts
243
243
  var src_exports = {};
244
244
  __export(src_exports, {
245
+ ClientContextPersonalizationTransfer: () => ClientContextPersonalizationTransfer,
246
+ ClientContextTestTransfer: () => ClientContextTestTransfer,
245
247
  ClientContextUpdate: () => ClientContextUpdate,
246
248
  ClientContextualEditingComponentWrapper: () => ClientContextualEditingComponentWrapper,
247
249
  ContextUpdateTransferClient: () => ContextUpdateTransferClient,
@@ -255,14 +257,71 @@ __export(src_exports, {
255
257
  });
256
258
  module.exports = __toCommonJS(src_exports);
257
259
 
260
+ // src/components/ClientContextPersonalizationTransfer.tsx
261
+ var import_react2 = require("react");
262
+
263
+ // src/hooks/useUniformContext.ts
264
+ var import_react = require("react");
265
+ var useUniformContext = () => {
266
+ const [context, setContext] = (0, import_react.useState)(
267
+ typeof window !== "undefined" ? window.__UNIFORM_CONTEXT__ : void 0
268
+ );
269
+ (0, import_react.useEffect)(() => {
270
+ const listener = () => {
271
+ setContext(window.__UNIFORM_CONTEXT__);
272
+ };
273
+ window.addEventListener("uniform.context.loaded", listener);
274
+ return () => {
275
+ window.removeEventListener("uniform.context.loaded", listener);
276
+ };
277
+ }, []);
278
+ return {
279
+ context
280
+ };
281
+ };
282
+
283
+ // src/components/ClientContextPersonalizationTransfer.tsx
284
+ var ClientContextPersonalizationTransfer = ({
285
+ event,
286
+ ts
287
+ }) => {
288
+ const { context } = useUniformContext();
289
+ const [lastLogged, setLastLogged] = (0, import_react2.useState)(void 0);
290
+ (0, import_react2.useEffect)(() => {
291
+ const shouldBeLogged = !ts || lastLogged !== ts;
292
+ const hasContext = typeof context !== "undefined";
293
+ if (shouldBeLogged && hasContext) {
294
+ setLastLogged(ts);
295
+ context.internal_processPersonalizationEvent(event);
296
+ }
297
+ }, [context, event, lastLogged, ts]);
298
+ return null;
299
+ };
300
+
301
+ // src/components/ClientContextTestTransfer.tsx
302
+ var import_react3 = require("react");
303
+ var ClientContextTestTransfer = ({ event, ts }) => {
304
+ const { context } = useUniformContext();
305
+ const [lastLogged, setLastLogged] = (0, import_react3.useState)(void 0);
306
+ (0, import_react3.useEffect)(() => {
307
+ const shouldBeLogged = !ts || lastLogged !== ts;
308
+ const hasContext = typeof context !== "undefined";
309
+ if (shouldBeLogged && hasContext && event.variantId) {
310
+ setLastLogged(ts);
311
+ context.internal_processTestEvent(event);
312
+ }
313
+ }, [context, event, lastLogged, ts]);
314
+ return null;
315
+ };
316
+
258
317
  // src/components/ClientContextualEditingComponentWrapper.tsx
259
318
  var import_canvas = require("@uniformdev/canvas");
260
319
  var import_core = require("@uniformdev/canvas-react/core");
261
320
  var import_navigation = require("next/navigation");
262
- var import_react = require("react");
321
+ var import_react4 = require("react");
263
322
  var import_jsx_runtime = require("react/jsx-runtime");
264
323
  var ClientContextualEditingComponentWrapper = (props) => {
265
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ClientContextualEditingComponentWrapperInner, { ...props }) });
324
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react4.Suspense, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ClientContextualEditingComponentWrapperInner, { ...props }) });
266
325
  };
267
326
  var ClientContextualEditingComponentWrapperInner = ({
268
327
  children,
@@ -278,38 +337,16 @@ var ClientContextualEditingComponentWrapperInner = ({
278
337
 
279
338
  // src/components/ClientContextUpdate.tsx
280
339
  var import_navigation2 = require("next/navigation");
281
- var import_react3 = require("react");
282
-
283
- // src/hooks/useUniformContext.ts
284
- var import_react2 = require("react");
285
- var useUniformContext = () => {
286
- const [context, setContext] = (0, import_react2.useState)(
287
- typeof window !== "undefined" ? window.__UNIFORM_CONTEXT__ : void 0
288
- );
289
- (0, import_react2.useEffect)(() => {
290
- const listener = () => {
291
- setContext(window.__UNIFORM_CONTEXT__);
292
- };
293
- window.addEventListener("uniform.context.loaded", listener);
294
- return () => {
295
- window.removeEventListener("uniform.context.loaded", listener);
296
- };
297
- }, []);
298
- return {
299
- context
300
- };
301
- };
302
-
303
- // src/components/ClientContextUpdate.tsx
340
+ var import_react5 = require("react");
304
341
  var import_jsx_runtime2 = require("react/jsx-runtime");
305
342
  var ClientContextUpdate = () => {
306
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react3.Suspense, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ClientContextUpdateInner, {}) });
343
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react5.Suspense, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ClientContextUpdateInner, {}) });
307
344
  };
308
345
  var ClientContextUpdateInner = () => {
309
346
  const params = (0, import_navigation2.useParams)();
310
347
  const searchParams = (0, import_navigation2.useSearchParams)();
311
348
  const { context } = useUniformContext();
312
- (0, import_react3.useEffect)(() => {
349
+ (0, import_react5.useEffect)(() => {
313
350
  if (!context || typeof window === "undefined") {
314
351
  return;
315
352
  }
@@ -323,14 +360,14 @@ var ClientContextUpdateInner = () => {
323
360
  };
324
361
 
325
362
  // src/components/ContextUpdateTransferClient.tsx
326
- var import_react4 = require("react");
363
+ var import_react6 = require("react");
327
364
  var ContextUpdateTransferClient = ({
328
365
  update,
329
366
  ts
330
367
  }) => {
331
368
  const { context } = useUniformContext();
332
- const [lastLogged, setLastLogged] = (0, import_react4.useState)(void 0);
333
- (0, import_react4.useEffect)(() => {
369
+ const [lastLogged, setLastLogged] = (0, import_react6.useState)(void 0);
370
+ (0, import_react6.useEffect)(() => {
334
371
  const shouldBeLogged = (!ts || lastLogged !== ts) && Object.keys(update).length > 0;
335
372
  const hasContext = typeof context !== "undefined";
336
373
  if (shouldBeLogged && hasContext) {
@@ -493,19 +530,6 @@ var __privateMethod = (obj, member, method) => {
493
530
  return method;
494
531
  };
495
532
  var ENR_SEPARATOR = "_";
496
- var _evaluator;
497
- var _onLogMessage;
498
- _evaluator = /* @__PURE__ */ new WeakMap();
499
- _onLogMessage = /* @__PURE__ */ new WeakMap();
500
- var _mf;
501
- var _signalInstances;
502
- var _onLogMessage2;
503
- _mf = /* @__PURE__ */ new WeakMap();
504
- _signalInstances = /* @__PURE__ */ new WeakMap();
505
- _onLogMessage2 = /* @__PURE__ */ new WeakMap();
506
- function getEnrichmentVectorKey(category, value) {
507
- return `${category}${ENR_SEPARATOR}${value}`;
508
- }
509
533
  function isNumberMatch(lhs, match) {
510
534
  var _a;
511
535
  if (typeof lhs === "undefined" || lhs === null) {
@@ -535,6 +559,13 @@ function explainNumberMatch(lhs, match) {
535
559
  function explainNumberMatchCriteria(match) {
536
560
  return `${match.op} ${match.rhs}`;
537
561
  }
562
+ function getEnrichmentVectorKey(category, value) {
563
+ return `${category}${ENR_SEPARATOR}${value}`;
564
+ }
565
+ var _goal;
566
+ var _id;
567
+ _goal = /* @__PURE__ */ new WeakMap();
568
+ _id = /* @__PURE__ */ new WeakMap();
538
569
  var pageViewCountDimension = getEnrichmentVectorKey("$pvc", "v");
539
570
  var pageViewCountEvaluator = ({ update, criteria, commands, onLogMessage }) => {
540
571
  var _a, _b;
@@ -572,6 +603,26 @@ var pageViewCountEvaluator = ({ update, criteria, commands, onLogMessage }) => {
572
603
  pageViewCountEvaluator.alwaysExecute = true;
573
604
  var _evaluators;
574
605
  _evaluators = /* @__PURE__ */ new WeakMap();
606
+ var _goal2;
607
+ var _id2;
608
+ _goal2 = /* @__PURE__ */ new WeakMap();
609
+ _id2 = /* @__PURE__ */ new WeakMap();
610
+ var _goal3;
611
+ var _id3;
612
+ _goal3 = /* @__PURE__ */ new WeakMap();
613
+ _id3 = /* @__PURE__ */ new WeakMap();
614
+ var _evaluator;
615
+ var _onLogMessage;
616
+ _evaluator = /* @__PURE__ */ new WeakMap();
617
+ _onLogMessage = /* @__PURE__ */ new WeakMap();
618
+ var _mf;
619
+ var _signalInstances;
620
+ var _goalEvaluators;
621
+ var _onLogMessage2;
622
+ _mf = /* @__PURE__ */ new WeakMap();
623
+ _signalInstances = /* @__PURE__ */ new WeakMap();
624
+ _goalEvaluators = /* @__PURE__ */ new WeakMap();
625
+ _onLogMessage2 = /* @__PURE__ */ new WeakMap();
575
626
  var _data;
576
627
  var _initialData;
577
628
  var _mitt;
@@ -606,6 +657,7 @@ var emptyVisitorData = () => ({
606
657
  scores: {},
607
658
  sessionScores: {},
608
659
  tests: {},
660
+ goals: {},
609
661
  consent: false,
610
662
  controlGroup: false
611
663
  });
@@ -637,7 +689,7 @@ currentData_get = function() {
637
689
  };
638
690
  _replaceData = /* @__PURE__ */ new WeakSet();
639
691
  replaceData_fn = function(data, quiet = false) {
640
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
692
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
641
693
  const oldData = __privateGet(this, _currentData, currentData_get);
642
694
  const now = Date.now();
643
695
  if (data.controlGroup) {
@@ -658,6 +710,7 @@ replaceData_fn = function(data, quiet = false) {
658
710
  const haveSessionScoresChanged = !dequal(oldData == null ? void 0 : oldData.visitorData.sessionScores, data.sessionScores);
659
711
  const haveQuirksChanged = !dequal(oldData == null ? void 0 : oldData.visitorData.quirks, data.quirks);
660
712
  const haveTestsChanged = !dequal(oldData == null ? void 0 : oldData.visitorData.tests, data.tests);
713
+ const haveGoalsChanged = !dequal(oldData == null ? void 0 : oldData.visitorData.goals, data.goals);
661
714
  const updatedData = {
662
715
  updated: now,
663
716
  visitorData: data
@@ -682,6 +735,15 @@ replaceData_fn = function(data, quiet = false) {
682
735
  __privateGet(this, _mitt2).emit("controlGroupUpdated", data);
683
736
  (_i = (_h = __privateGet(this, _options)).onLogMessage) == null ? void 0 : _i.call(_h, ["debug", 104, (_g = data.controlGroup) != null ? _g : false]);
684
737
  }
738
+ if (haveGoalsChanged) {
739
+ const newGoalKeys = Object.keys((_j = data.goals) != null ? _j : {});
740
+ for (let i = 0; i < newGoalKeys.length; i++) {
741
+ const key = newGoalKeys[i];
742
+ if (!((_k = oldData == null ? void 0 : oldData.visitorData.goals) == null ? void 0 : _k[key])) {
743
+ __privateGet(this, _mitt2).emit("goalConverted", { goalId: key });
744
+ }
745
+ }
746
+ }
685
747
  }
686
748
  };
687
749
  _setVisitTimeout = /* @__PURE__ */ new WeakSet();
@@ -732,9 +794,12 @@ var _serverTransitionState;
732
794
  var _scores;
733
795
  var _state;
734
796
  var _pzCache;
797
+ var _plugins;
735
798
  var _mitt3;
736
799
  var _emitTest;
737
800
  var emitTest_fn;
801
+ var _updateGoals;
802
+ var updateGoals_fn;
738
803
  var _updateComputedScores;
739
804
  var updateComputedScores_fn;
740
805
  var _calculateScores;
@@ -743,17 +808,29 @@ _serverTransitionState = /* @__PURE__ */ new WeakMap();
743
808
  _scores = /* @__PURE__ */ new WeakMap();
744
809
  _state = /* @__PURE__ */ new WeakMap();
745
810
  _pzCache = /* @__PURE__ */ new WeakMap();
811
+ _plugins = /* @__PURE__ */ new WeakMap();
746
812
  _mitt3 = /* @__PURE__ */ new WeakMap();
747
813
  _emitTest = /* @__PURE__ */ new WeakSet();
748
814
  emitTest_fn = function(event) {
749
815
  __privateGet(this, _mitt3).emit("testResult", event);
750
816
  };
817
+ _updateGoals = /* @__PURE__ */ new WeakSet();
818
+ updateGoals_fn = async function(data) {
819
+ const goalCommands = this.manifest.computeGoals(data);
820
+ if (goalCommands.length !== 0) {
821
+ await this.storage.updateData(goalCommands);
822
+ }
823
+ };
751
824
  _updateComputedScores = /* @__PURE__ */ new WeakSet();
752
825
  updateComputedScores_fn = function(newData) {
753
826
  const newScores = __privateMethod(this, _calculateScores, calculateScores_fn).call(this, newData);
754
827
  const newScoresHaveChanged = !dequal(newScores, __privateGet(this, _scores));
755
828
  if (newScoresHaveChanged) {
756
829
  __privateSet(this, _scores, newScores);
830
+ __privateMethod(this, _updateGoals, updateGoals_fn).call(this, {
831
+ scores: __privateGet(this, _scores),
832
+ quirks: void 0
833
+ });
757
834
  __privateGet(this, _mitt3).emit("scoresUpdated", newScores);
758
835
  __privateGet(this, _mitt3).emit("log", ["info", 3, newScores]);
759
836
  }
@@ -846,10 +923,8 @@ function enableContextDevTools(options) {
846
923
  context.events.on("personalizationResult", onPersonalizationResult);
847
924
  context.events.on("testResult", onTestResult);
848
925
  context.events.on("scoresUpdated", onContextDataUpdated);
849
- context.storage.events.on("*", onContextDataUpdated);
850
926
  return () => {
851
927
  context.events.off("scoresUpdated", onContextDataUpdated);
852
- context.storage.events.off("*", onContextDataUpdated);
853
928
  context.events.off("personalizationResult", onPersonalizationResult);
854
929
  context.events.off("testResult", onTestResult);
855
930
  };
@@ -894,10 +969,10 @@ var createClientUniformContext = (options) => {
894
969
  };
895
970
 
896
971
  // src/hooks/useInitUniformContext.ts
897
- var import_react5 = require("react");
972
+ var import_react7 = require("react");
898
973
  var useInitUniformContext = (callback) => {
899
- const [called, setCalled] = (0, import_react5.useState)(false);
900
- (0, import_react5.useEffect)(() => {
974
+ const [called, setCalled] = (0, import_react7.useState)(false);
975
+ (0, import_react7.useEffect)(() => {
901
976
  if (typeof window === "undefined" || called || typeof window.__UNIFORM_CONTEXT__ !== "undefined") {
902
977
  return;
903
978
  }
@@ -933,12 +1008,12 @@ var DefaultUniformClientContext = ({ manifest, disableDevTools }) => {
933
1008
  // src/components/PersonalizeClient.ts
934
1009
  var import_canvas2 = require("@uniformdev/canvas");
935
1010
  var import_canvas_next_rsc_shared2 = require("@uniformdev/canvas-next-rsc-shared");
936
- var import_react6 = require("react");
1011
+ var import_react8 = require("react");
937
1012
  var PersonalizeClient = (props) => {
938
1013
  const { slots } = props;
939
1014
  const { context } = useUniformContext();
940
- const [indexesToShow, setIndexesToShow] = (0, import_react6.useState)(props.indexes);
941
- (0, import_react6.useEffect)(() => {
1015
+ const [indexesToShow, setIndexesToShow] = (0, import_react8.useState)(props.indexes);
1016
+ (0, import_react8.useEffect)(() => {
942
1017
  const result = (0, import_canvas_next_rsc_shared2.runPersonalization)({
943
1018
  ...props,
944
1019
  contextInstance: context
@@ -949,19 +1024,19 @@ var PersonalizeClient = (props) => {
949
1024
  var _a;
950
1025
  return (_a = slots[import_canvas2.CANVAS_PERSONALIZE_SLOT]) == null ? void 0 : _a.items[key];
951
1026
  });
952
- return (0, import_react6.createElement)(import_react6.Fragment, void 0, slotsToShow);
1027
+ return (0, import_react8.createElement)(import_react8.Fragment, void 0, slotsToShow);
953
1028
  };
954
1029
 
955
1030
  // src/components/TestClient.ts
956
1031
  var import_canvas3 = require("@uniformdev/canvas");
957
1032
  var import_canvas_next_rsc_shared3 = require("@uniformdev/canvas-next-rsc-shared");
958
- var import_react7 = require("react");
1033
+ var import_react9 = require("react");
959
1034
  var TestClient = (props) => {
960
1035
  var _a;
961
1036
  const { slots } = props;
962
1037
  const { context } = useUniformContext();
963
- const [index, setIndex] = (0, import_react7.useState)(0);
964
- (0, import_react7.useEffect)(() => {
1038
+ const [index, setIndex] = (0, import_react9.useState)(0);
1039
+ (0, import_react9.useEffect)(() => {
965
1040
  const result = (0, import_canvas_next_rsc_shared3.runTest)({
966
1041
  ...props,
967
1042
  contextInstance: context
@@ -971,20 +1046,20 @@ var TestClient = (props) => {
971
1046
  if (typeof index !== "number") {
972
1047
  return null;
973
1048
  }
974
- return (0, import_react7.createElement)(import_react7.Fragment, void 0, (_a = slots == null ? void 0 : slots[import_canvas3.CANVAS_TEST_SLOT]) == null ? void 0 : _a.items[index]);
1049
+ return (0, import_react9.createElement)(import_react9.Fragment, void 0, (_a = slots == null ? void 0 : slots[import_canvas3.CANVAS_TEST_SLOT]) == null ? void 0 : _a.items[index]);
975
1050
  };
976
1051
 
977
1052
  // src/components/UniformScriptClient.tsx
978
1053
  var import_canvas4 = require("@uniformdev/canvas");
979
1054
  var import_navigation4 = require("next/navigation");
980
- var import_react8 = require("react");
1055
+ var import_react10 = require("react");
981
1056
  var import_jsx_runtime3 = require("react/jsx-runtime");
982
1057
  var UniformScript = () => {
983
1058
  const router = (0, import_navigation4.useRouter)();
984
1059
  const params = (0, import_navigation4.useSearchParams)();
985
- const needsToRefreshRef = (0, import_react8.useRef)(false);
1060
+ const needsToRefreshRef = (0, import_react10.useRef)(false);
986
1061
  const enabled = params.get(import_canvas4.IN_CONTEXT_EDITOR_QUERY_STRING_PARAM) === "true";
987
- const channel = (0, import_react8.useMemo)(() => {
1062
+ const channel = (0, import_react10.useMemo)(() => {
988
1063
  var _a;
989
1064
  if (typeof window === "undefined") {
990
1065
  return;
@@ -995,7 +1070,7 @@ var UniformScript = () => {
995
1070
  });
996
1071
  return instance;
997
1072
  }, []);
998
- (0, import_react8.useEffect)(() => {
1073
+ (0, import_react10.useEffect)(() => {
999
1074
  if (!channel) {
1000
1075
  return;
1001
1076
  }
@@ -1012,7 +1087,7 @@ var UniformScript = () => {
1012
1087
  unsubscribeFromEditorUpdates();
1013
1088
  };
1014
1089
  }, [channel, router]);
1015
- (0, import_react8.useEffect)(() => {
1090
+ (0, import_react10.useEffect)(() => {
1016
1091
  if (typeof window === "undefined") {
1017
1092
  return;
1018
1093
  }
@@ -1033,7 +1108,7 @@ var UniformScript = () => {
1033
1108
  existing.remove();
1034
1109
  }
1035
1110
  }, [enabled]);
1036
- (0, import_react8.useEffect)(() => {
1111
+ (0, import_react10.useEffect)(() => {
1037
1112
  const handleBlurChange = () => {
1038
1113
  if (needsToRefreshRef.current) {
1039
1114
  router.refresh();
@@ -1049,6 +1124,8 @@ var UniformScript = () => {
1049
1124
  };
1050
1125
  // Annotate the CommonJS export names for ESM import in node:
1051
1126
  0 && (module.exports = {
1127
+ ClientContextPersonalizationTransfer,
1128
+ ClientContextTestTransfer,
1052
1129
  ClientContextUpdate,
1053
1130
  ClientContextualEditingComponentWrapper,
1054
1131
  ContextUpdateTransferClient,
package/dist/index.mjs CHANGED
@@ -233,6 +233,63 @@ var require_rfdc = __commonJS({
233
233
  }
234
234
  });
235
235
 
236
+ // src/components/ClientContextPersonalizationTransfer.tsx
237
+ import { useEffect as useEffect2, useState as useState2 } from "react";
238
+
239
+ // src/hooks/useUniformContext.ts
240
+ import { useEffect, useState } from "react";
241
+ var useUniformContext = () => {
242
+ const [context, setContext] = useState(
243
+ typeof window !== "undefined" ? window.__UNIFORM_CONTEXT__ : void 0
244
+ );
245
+ useEffect(() => {
246
+ const listener = () => {
247
+ setContext(window.__UNIFORM_CONTEXT__);
248
+ };
249
+ window.addEventListener("uniform.context.loaded", listener);
250
+ return () => {
251
+ window.removeEventListener("uniform.context.loaded", listener);
252
+ };
253
+ }, []);
254
+ return {
255
+ context
256
+ };
257
+ };
258
+
259
+ // src/components/ClientContextPersonalizationTransfer.tsx
260
+ var ClientContextPersonalizationTransfer = ({
261
+ event,
262
+ ts
263
+ }) => {
264
+ const { context } = useUniformContext();
265
+ const [lastLogged, setLastLogged] = useState2(void 0);
266
+ useEffect2(() => {
267
+ const shouldBeLogged = !ts || lastLogged !== ts;
268
+ const hasContext = typeof context !== "undefined";
269
+ if (shouldBeLogged && hasContext) {
270
+ setLastLogged(ts);
271
+ context.internal_processPersonalizationEvent(event);
272
+ }
273
+ }, [context, event, lastLogged, ts]);
274
+ return null;
275
+ };
276
+
277
+ // src/components/ClientContextTestTransfer.tsx
278
+ import { useEffect as useEffect3, useState as useState3 } from "react";
279
+ var ClientContextTestTransfer = ({ event, ts }) => {
280
+ const { context } = useUniformContext();
281
+ const [lastLogged, setLastLogged] = useState3(void 0);
282
+ useEffect3(() => {
283
+ const shouldBeLogged = !ts || lastLogged !== ts;
284
+ const hasContext = typeof context !== "undefined";
285
+ if (shouldBeLogged && hasContext && event.variantId) {
286
+ setLastLogged(ts);
287
+ context.internal_processTestEvent(event);
288
+ }
289
+ }, [context, event, lastLogged, ts]);
290
+ return null;
291
+ };
292
+
236
293
  // src/components/ClientContextualEditingComponentWrapper.tsx
237
294
  import { IN_CONTEXT_EDITOR_QUERY_STRING_PARAM } from "@uniformdev/canvas";
238
295
  import {
@@ -258,29 +315,7 @@ var ClientContextualEditingComponentWrapperInner = ({
258
315
 
259
316
  // src/components/ClientContextUpdate.tsx
260
317
  import { useParams, useSearchParams as useSearchParams2 } from "next/navigation";
261
- import { Suspense as Suspense2, useEffect as useEffect2 } from "react";
262
-
263
- // src/hooks/useUniformContext.ts
264
- import { useEffect, useState } from "react";
265
- var useUniformContext = () => {
266
- const [context, setContext] = useState(
267
- typeof window !== "undefined" ? window.__UNIFORM_CONTEXT__ : void 0
268
- );
269
- useEffect(() => {
270
- const listener = () => {
271
- setContext(window.__UNIFORM_CONTEXT__);
272
- };
273
- window.addEventListener("uniform.context.loaded", listener);
274
- return () => {
275
- window.removeEventListener("uniform.context.loaded", listener);
276
- };
277
- }, []);
278
- return {
279
- context
280
- };
281
- };
282
-
283
- // src/components/ClientContextUpdate.tsx
318
+ import { Suspense as Suspense2, useEffect as useEffect4 } from "react";
284
319
  import { Fragment as Fragment2, jsx as jsx2 } from "react/jsx-runtime";
285
320
  var ClientContextUpdate = () => {
286
321
  return /* @__PURE__ */ jsx2(Suspense2, { children: /* @__PURE__ */ jsx2(ClientContextUpdateInner, {}) });
@@ -289,7 +324,7 @@ var ClientContextUpdateInner = () => {
289
324
  const params = useParams();
290
325
  const searchParams = useSearchParams2();
291
326
  const { context } = useUniformContext();
292
- useEffect2(() => {
327
+ useEffect4(() => {
293
328
  if (!context || typeof window === "undefined") {
294
329
  return;
295
330
  }
@@ -303,14 +338,14 @@ var ClientContextUpdateInner = () => {
303
338
  };
304
339
 
305
340
  // src/components/ContextUpdateTransferClient.tsx
306
- import { useEffect as useEffect3, useState as useState2 } from "react";
341
+ import { useEffect as useEffect5, useState as useState4 } from "react";
307
342
  var ContextUpdateTransferClient = ({
308
343
  update,
309
344
  ts
310
345
  }) => {
311
346
  const { context } = useUniformContext();
312
- const [lastLogged, setLastLogged] = useState2(void 0);
313
- useEffect3(() => {
347
+ const [lastLogged, setLastLogged] = useState4(void 0);
348
+ useEffect5(() => {
314
349
  const shouldBeLogged = (!ts || lastLogged !== ts) && Object.keys(update).length > 0;
315
350
  const hasContext = typeof context !== "undefined";
316
351
  if (shouldBeLogged && hasContext) {
@@ -473,19 +508,6 @@ var __privateMethod = (obj, member, method) => {
473
508
  return method;
474
509
  };
475
510
  var ENR_SEPARATOR = "_";
476
- var _evaluator;
477
- var _onLogMessage;
478
- _evaluator = /* @__PURE__ */ new WeakMap();
479
- _onLogMessage = /* @__PURE__ */ new WeakMap();
480
- var _mf;
481
- var _signalInstances;
482
- var _onLogMessage2;
483
- _mf = /* @__PURE__ */ new WeakMap();
484
- _signalInstances = /* @__PURE__ */ new WeakMap();
485
- _onLogMessage2 = /* @__PURE__ */ new WeakMap();
486
- function getEnrichmentVectorKey(category, value) {
487
- return `${category}${ENR_SEPARATOR}${value}`;
488
- }
489
511
  function isNumberMatch(lhs, match) {
490
512
  var _a;
491
513
  if (typeof lhs === "undefined" || lhs === null) {
@@ -515,6 +537,13 @@ function explainNumberMatch(lhs, match) {
515
537
  function explainNumberMatchCriteria(match) {
516
538
  return `${match.op} ${match.rhs}`;
517
539
  }
540
+ function getEnrichmentVectorKey(category, value) {
541
+ return `${category}${ENR_SEPARATOR}${value}`;
542
+ }
543
+ var _goal;
544
+ var _id;
545
+ _goal = /* @__PURE__ */ new WeakMap();
546
+ _id = /* @__PURE__ */ new WeakMap();
518
547
  var pageViewCountDimension = getEnrichmentVectorKey("$pvc", "v");
519
548
  var pageViewCountEvaluator = ({ update, criteria, commands, onLogMessage }) => {
520
549
  var _a, _b;
@@ -552,6 +581,26 @@ var pageViewCountEvaluator = ({ update, criteria, commands, onLogMessage }) => {
552
581
  pageViewCountEvaluator.alwaysExecute = true;
553
582
  var _evaluators;
554
583
  _evaluators = /* @__PURE__ */ new WeakMap();
584
+ var _goal2;
585
+ var _id2;
586
+ _goal2 = /* @__PURE__ */ new WeakMap();
587
+ _id2 = /* @__PURE__ */ new WeakMap();
588
+ var _goal3;
589
+ var _id3;
590
+ _goal3 = /* @__PURE__ */ new WeakMap();
591
+ _id3 = /* @__PURE__ */ new WeakMap();
592
+ var _evaluator;
593
+ var _onLogMessage;
594
+ _evaluator = /* @__PURE__ */ new WeakMap();
595
+ _onLogMessage = /* @__PURE__ */ new WeakMap();
596
+ var _mf;
597
+ var _signalInstances;
598
+ var _goalEvaluators;
599
+ var _onLogMessage2;
600
+ _mf = /* @__PURE__ */ new WeakMap();
601
+ _signalInstances = /* @__PURE__ */ new WeakMap();
602
+ _goalEvaluators = /* @__PURE__ */ new WeakMap();
603
+ _onLogMessage2 = /* @__PURE__ */ new WeakMap();
555
604
  var _data;
556
605
  var _initialData;
557
606
  var _mitt;
@@ -586,6 +635,7 @@ var emptyVisitorData = () => ({
586
635
  scores: {},
587
636
  sessionScores: {},
588
637
  tests: {},
638
+ goals: {},
589
639
  consent: false,
590
640
  controlGroup: false
591
641
  });
@@ -617,7 +667,7 @@ currentData_get = function() {
617
667
  };
618
668
  _replaceData = /* @__PURE__ */ new WeakSet();
619
669
  replaceData_fn = function(data, quiet = false) {
620
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
670
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
621
671
  const oldData = __privateGet(this, _currentData, currentData_get);
622
672
  const now = Date.now();
623
673
  if (data.controlGroup) {
@@ -638,6 +688,7 @@ replaceData_fn = function(data, quiet = false) {
638
688
  const haveSessionScoresChanged = !dequal(oldData == null ? void 0 : oldData.visitorData.sessionScores, data.sessionScores);
639
689
  const haveQuirksChanged = !dequal(oldData == null ? void 0 : oldData.visitorData.quirks, data.quirks);
640
690
  const haveTestsChanged = !dequal(oldData == null ? void 0 : oldData.visitorData.tests, data.tests);
691
+ const haveGoalsChanged = !dequal(oldData == null ? void 0 : oldData.visitorData.goals, data.goals);
641
692
  const updatedData = {
642
693
  updated: now,
643
694
  visitorData: data
@@ -662,6 +713,15 @@ replaceData_fn = function(data, quiet = false) {
662
713
  __privateGet(this, _mitt2).emit("controlGroupUpdated", data);
663
714
  (_i = (_h = __privateGet(this, _options)).onLogMessage) == null ? void 0 : _i.call(_h, ["debug", 104, (_g = data.controlGroup) != null ? _g : false]);
664
715
  }
716
+ if (haveGoalsChanged) {
717
+ const newGoalKeys = Object.keys((_j = data.goals) != null ? _j : {});
718
+ for (let i = 0; i < newGoalKeys.length; i++) {
719
+ const key = newGoalKeys[i];
720
+ if (!((_k = oldData == null ? void 0 : oldData.visitorData.goals) == null ? void 0 : _k[key])) {
721
+ __privateGet(this, _mitt2).emit("goalConverted", { goalId: key });
722
+ }
723
+ }
724
+ }
665
725
  }
666
726
  };
667
727
  _setVisitTimeout = /* @__PURE__ */ new WeakSet();
@@ -712,9 +772,12 @@ var _serverTransitionState;
712
772
  var _scores;
713
773
  var _state;
714
774
  var _pzCache;
775
+ var _plugins;
715
776
  var _mitt3;
716
777
  var _emitTest;
717
778
  var emitTest_fn;
779
+ var _updateGoals;
780
+ var updateGoals_fn;
718
781
  var _updateComputedScores;
719
782
  var updateComputedScores_fn;
720
783
  var _calculateScores;
@@ -723,17 +786,29 @@ _serverTransitionState = /* @__PURE__ */ new WeakMap();
723
786
  _scores = /* @__PURE__ */ new WeakMap();
724
787
  _state = /* @__PURE__ */ new WeakMap();
725
788
  _pzCache = /* @__PURE__ */ new WeakMap();
789
+ _plugins = /* @__PURE__ */ new WeakMap();
726
790
  _mitt3 = /* @__PURE__ */ new WeakMap();
727
791
  _emitTest = /* @__PURE__ */ new WeakSet();
728
792
  emitTest_fn = function(event) {
729
793
  __privateGet(this, _mitt3).emit("testResult", event);
730
794
  };
795
+ _updateGoals = /* @__PURE__ */ new WeakSet();
796
+ updateGoals_fn = async function(data) {
797
+ const goalCommands = this.manifest.computeGoals(data);
798
+ if (goalCommands.length !== 0) {
799
+ await this.storage.updateData(goalCommands);
800
+ }
801
+ };
731
802
  _updateComputedScores = /* @__PURE__ */ new WeakSet();
732
803
  updateComputedScores_fn = function(newData) {
733
804
  const newScores = __privateMethod(this, _calculateScores, calculateScores_fn).call(this, newData);
734
805
  const newScoresHaveChanged = !dequal(newScores, __privateGet(this, _scores));
735
806
  if (newScoresHaveChanged) {
736
807
  __privateSet(this, _scores, newScores);
808
+ __privateMethod(this, _updateGoals, updateGoals_fn).call(this, {
809
+ scores: __privateGet(this, _scores),
810
+ quirks: void 0
811
+ });
737
812
  __privateGet(this, _mitt3).emit("scoresUpdated", newScores);
738
813
  __privateGet(this, _mitt3).emit("log", ["info", 3, newScores]);
739
814
  }
@@ -826,10 +901,8 @@ function enableContextDevTools(options) {
826
901
  context.events.on("personalizationResult", onPersonalizationResult);
827
902
  context.events.on("testResult", onTestResult);
828
903
  context.events.on("scoresUpdated", onContextDataUpdated);
829
- context.storage.events.on("*", onContextDataUpdated);
830
904
  return () => {
831
905
  context.events.off("scoresUpdated", onContextDataUpdated);
832
- context.storage.events.off("*", onContextDataUpdated);
833
906
  context.events.off("personalizationResult", onPersonalizationResult);
834
907
  context.events.off("testResult", onTestResult);
835
908
  };
@@ -874,10 +947,10 @@ var createClientUniformContext = (options) => {
874
947
  };
875
948
 
876
949
  // src/hooks/useInitUniformContext.ts
877
- import { useEffect as useEffect4, useState as useState3 } from "react";
950
+ import { useEffect as useEffect6, useState as useState5 } from "react";
878
951
  var useInitUniformContext = (callback) => {
879
- const [called, setCalled] = useState3(false);
880
- useEffect4(() => {
952
+ const [called, setCalled] = useState5(false);
953
+ useEffect6(() => {
881
954
  if (typeof window === "undefined" || called || typeof window.__UNIFORM_CONTEXT__ !== "undefined") {
882
955
  return;
883
956
  }
@@ -913,12 +986,12 @@ var DefaultUniformClientContext = ({ manifest, disableDevTools }) => {
913
986
  // src/components/PersonalizeClient.ts
914
987
  import { CANVAS_PERSONALIZE_SLOT } from "@uniformdev/canvas";
915
988
  import { runPersonalization } from "@uniformdev/canvas-next-rsc-shared";
916
- import { createElement, Fragment as Fragment3, useEffect as useEffect5, useState as useState4 } from "react";
989
+ import { createElement, Fragment as Fragment3, useEffect as useEffect7, useState as useState6 } from "react";
917
990
  var PersonalizeClient = (props) => {
918
991
  const { slots } = props;
919
992
  const { context } = useUniformContext();
920
- const [indexesToShow, setIndexesToShow] = useState4(props.indexes);
921
- useEffect5(() => {
993
+ const [indexesToShow, setIndexesToShow] = useState6(props.indexes);
994
+ useEffect7(() => {
922
995
  const result = runPersonalization({
923
996
  ...props,
924
997
  contextInstance: context
@@ -935,13 +1008,13 @@ var PersonalizeClient = (props) => {
935
1008
  // src/components/TestClient.ts
936
1009
  import { CANVAS_TEST_SLOT } from "@uniformdev/canvas";
937
1010
  import { runTest } from "@uniformdev/canvas-next-rsc-shared";
938
- import { createElement as createElement2, Fragment as Fragment4, useEffect as useEffect6, useState as useState5 } from "react";
1011
+ import { createElement as createElement2, Fragment as Fragment4, useEffect as useEffect8, useState as useState7 } from "react";
939
1012
  var TestClient = (props) => {
940
1013
  var _a;
941
1014
  const { slots } = props;
942
1015
  const { context } = useUniformContext();
943
- const [index, setIndex] = useState5(0);
944
- useEffect6(() => {
1016
+ const [index, setIndex] = useState7(0);
1017
+ useEffect8(() => {
945
1018
  const result = runTest({
946
1019
  ...props,
947
1020
  contextInstance: context
@@ -961,7 +1034,7 @@ import {
961
1034
  isAllowedReferrer
962
1035
  } from "@uniformdev/canvas";
963
1036
  import { useRouter as useRouter2, useSearchParams as useSearchParams3 } from "next/navigation";
964
- import { useEffect as useEffect7, useMemo, useRef } from "react";
1037
+ import { useEffect as useEffect9, useMemo, useRef } from "react";
965
1038
  import { Fragment as Fragment5, jsx as jsx3 } from "react/jsx-runtime";
966
1039
  var UniformScript = () => {
967
1040
  const router = useRouter2();
@@ -979,7 +1052,7 @@ var UniformScript = () => {
979
1052
  });
980
1053
  return instance;
981
1054
  }, []);
982
- useEffect7(() => {
1055
+ useEffect9(() => {
983
1056
  if (!channel) {
984
1057
  return;
985
1058
  }
@@ -996,7 +1069,7 @@ var UniformScript = () => {
996
1069
  unsubscribeFromEditorUpdates();
997
1070
  };
998
1071
  }, [channel, router]);
999
- useEffect7(() => {
1072
+ useEffect9(() => {
1000
1073
  if (typeof window === "undefined") {
1001
1074
  return;
1002
1075
  }
@@ -1017,7 +1090,7 @@ var UniformScript = () => {
1017
1090
  existing.remove();
1018
1091
  }
1019
1092
  }, [enabled]);
1020
- useEffect7(() => {
1093
+ useEffect9(() => {
1021
1094
  const handleBlurChange = () => {
1022
1095
  if (needsToRefreshRef.current) {
1023
1096
  router.refresh();
@@ -1032,6 +1105,8 @@ var UniformScript = () => {
1032
1105
  return /* @__PURE__ */ jsx3(Fragment5, {});
1033
1106
  };
1034
1107
  export {
1108
+ ClientContextPersonalizationTransfer,
1109
+ ClientContextTestTransfer,
1035
1110
  ClientContextUpdate,
1036
1111
  ClientContextualEditingComponentWrapper,
1037
1112
  ContextUpdateTransferClient,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/canvas-next-rsc-client",
3
- "version": "19.79.1-alpha.11+4547ef846",
3
+ "version": "19.79.1-alpha.18+12234b9350",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "scripts": {
6
6
  "build": "tsup",
@@ -24,17 +24,17 @@
24
24
  "/dist"
25
25
  ],
26
26
  "devDependencies": {
27
- "@types/node": "^18.0.0",
28
- "@types/react": "^18.2.20",
29
- "eslint": "^8.11.0",
30
- "next": "^13.4.12",
27
+ "@types/node": "^20.0.0",
28
+ "@types/react": "18.2.40",
29
+ "eslint": "8.54.0",
30
+ "next": "^14.0.0",
31
31
  "react": "18.2.0",
32
32
  "react-dom": "18.2.0"
33
33
  },
34
34
  "dependencies": {
35
- "@uniformdev/canvas": "19.79.1-alpha.11+4547ef846",
36
- "@uniformdev/canvas-next-rsc-shared": "^19.79.1-alpha.11+4547ef846",
37
- "@uniformdev/canvas-react": "^19.79.1-alpha.11+4547ef846"
35
+ "@uniformdev/canvas": "19.79.1-alpha.18+12234b9350",
36
+ "@uniformdev/canvas-next-rsc-shared": "^19.79.1-alpha.18+12234b9350",
37
+ "@uniformdev/canvas-react": "^19.79.1-alpha.18+12234b9350"
38
38
  },
39
39
  "engines": {
40
40
  "node": ">=16.14.0"
@@ -47,5 +47,5 @@
47
47
  "publishConfig": {
48
48
  "access": "public"
49
49
  },
50
- "gitHead": "4547ef8469f21f7f2341bcd87203372c4646bc08"
50
+ "gitHead": "12234b9350cfa4209bc7e242701d2dc535ece19e"
51
51
  }