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

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/dist/index.d.mts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { ManifestV2, ContextOptions } from '@uniformdev/context';
2
+ import { PersonalizationEvent, TestEvent } 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
1
  import { ManifestV2, ContextOptions } from '@uniformdev/context';
2
+ import { PersonalizationEvent, TestEvent } 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_emitPersonalizationResult(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) {
286
+ setLastLogged(ts);
287
+ context.internal_emitTestResult(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,10 @@ var _serverTransitionState;
712
772
  var _scores;
713
773
  var _state;
714
774
  var _pzCache;
775
+ var _plugins;
715
776
  var _mitt3;
716
- var _emitTest;
717
- var emitTest_fn;
777
+ var _updateGoals;
778
+ var updateGoals_fn;
718
779
  var _updateComputedScores;
719
780
  var updateComputedScores_fn;
720
781
  var _calculateScores;
@@ -723,10 +784,14 @@ _serverTransitionState = /* @__PURE__ */ new WeakMap();
723
784
  _scores = /* @__PURE__ */ new WeakMap();
724
785
  _state = /* @__PURE__ */ new WeakMap();
725
786
  _pzCache = /* @__PURE__ */ new WeakMap();
787
+ _plugins = /* @__PURE__ */ new WeakMap();
726
788
  _mitt3 = /* @__PURE__ */ new WeakMap();
727
- _emitTest = /* @__PURE__ */ new WeakSet();
728
- emitTest_fn = function(event) {
729
- __privateGet(this, _mitt3).emit("testResult", event);
789
+ _updateGoals = /* @__PURE__ */ new WeakSet();
790
+ updateGoals_fn = async function(data) {
791
+ const goalCommands = this.manifest.computeGoals(data);
792
+ if (goalCommands.length !== 0) {
793
+ await this.storage.updateData(goalCommands);
794
+ }
730
795
  };
731
796
  _updateComputedScores = /* @__PURE__ */ new WeakSet();
732
797
  updateComputedScores_fn = function(newData) {
@@ -734,6 +799,10 @@ updateComputedScores_fn = function(newData) {
734
799
  const newScoresHaveChanged = !dequal(newScores, __privateGet(this, _scores));
735
800
  if (newScoresHaveChanged) {
736
801
  __privateSet(this, _scores, newScores);
802
+ __privateMethod(this, _updateGoals, updateGoals_fn).call(this, {
803
+ scores: __privateGet(this, _scores),
804
+ quirks: void 0
805
+ });
737
806
  __privateGet(this, _mitt3).emit("scoresUpdated", newScores);
738
807
  __privateGet(this, _mitt3).emit("log", ["info", 3, newScores]);
739
808
  }
@@ -874,10 +943,10 @@ var createClientUniformContext = (options) => {
874
943
  };
875
944
 
876
945
  // src/hooks/useInitUniformContext.ts
877
- import { useEffect as useEffect4, useState as useState3 } from "react";
946
+ import { useEffect as useEffect6, useState as useState5 } from "react";
878
947
  var useInitUniformContext = (callback) => {
879
- const [called, setCalled] = useState3(false);
880
- useEffect4(() => {
948
+ const [called, setCalled] = useState5(false);
949
+ useEffect6(() => {
881
950
  if (typeof window === "undefined" || called || typeof window.__UNIFORM_CONTEXT__ !== "undefined") {
882
951
  return;
883
952
  }
@@ -913,12 +982,12 @@ var DefaultUniformClientContext = ({ manifest, disableDevTools }) => {
913
982
  // src/components/PersonalizeClient.ts
914
983
  import { CANVAS_PERSONALIZE_SLOT } from "@uniformdev/canvas";
915
984
  import { runPersonalization } from "@uniformdev/canvas-next-rsc-shared";
916
- import { createElement, Fragment as Fragment3, useEffect as useEffect5, useState as useState4 } from "react";
985
+ import { createElement, Fragment as Fragment3, useEffect as useEffect7, useState as useState6 } from "react";
917
986
  var PersonalizeClient = (props) => {
918
987
  const { slots } = props;
919
988
  const { context } = useUniformContext();
920
- const [indexesToShow, setIndexesToShow] = useState4(props.indexes);
921
- useEffect5(() => {
989
+ const [indexesToShow, setIndexesToShow] = useState6(props.indexes);
990
+ useEffect7(() => {
922
991
  const result = runPersonalization({
923
992
  ...props,
924
993
  contextInstance: context
@@ -935,13 +1004,13 @@ var PersonalizeClient = (props) => {
935
1004
  // src/components/TestClient.ts
936
1005
  import { CANVAS_TEST_SLOT } from "@uniformdev/canvas";
937
1006
  import { runTest } from "@uniformdev/canvas-next-rsc-shared";
938
- import { createElement as createElement2, Fragment as Fragment4, useEffect as useEffect6, useState as useState5 } from "react";
1007
+ import { createElement as createElement2, Fragment as Fragment4, useEffect as useEffect8, useState as useState7 } from "react";
939
1008
  var TestClient = (props) => {
940
1009
  var _a;
941
1010
  const { slots } = props;
942
1011
  const { context } = useUniformContext();
943
- const [index, setIndex] = useState5(0);
944
- useEffect6(() => {
1012
+ const [index, setIndex] = useState7(0);
1013
+ useEffect8(() => {
945
1014
  const result = runTest({
946
1015
  ...props,
947
1016
  contextInstance: context
@@ -961,7 +1030,7 @@ import {
961
1030
  isAllowedReferrer
962
1031
  } from "@uniformdev/canvas";
963
1032
  import { useRouter as useRouter2, useSearchParams as useSearchParams3 } from "next/navigation";
964
- import { useEffect as useEffect7, useMemo, useRef } from "react";
1033
+ import { useEffect as useEffect9, useMemo, useRef } from "react";
965
1034
  import { Fragment as Fragment5, jsx as jsx3 } from "react/jsx-runtime";
966
1035
  var UniformScript = () => {
967
1036
  const router = useRouter2();
@@ -979,7 +1048,7 @@ var UniformScript = () => {
979
1048
  });
980
1049
  return instance;
981
1050
  }, []);
982
- useEffect7(() => {
1051
+ useEffect9(() => {
983
1052
  if (!channel) {
984
1053
  return;
985
1054
  }
@@ -996,7 +1065,7 @@ var UniformScript = () => {
996
1065
  unsubscribeFromEditorUpdates();
997
1066
  };
998
1067
  }, [channel, router]);
999
- useEffect7(() => {
1068
+ useEffect9(() => {
1000
1069
  if (typeof window === "undefined") {
1001
1070
  return;
1002
1071
  }
@@ -1017,7 +1086,7 @@ var UniformScript = () => {
1017
1086
  existing.remove();
1018
1087
  }
1019
1088
  }, [enabled]);
1020
- useEffect7(() => {
1089
+ useEffect9(() => {
1021
1090
  const handleBlurChange = () => {
1022
1091
  if (needsToRefreshRef.current) {
1023
1092
  router.refresh();
@@ -1032,6 +1101,8 @@ var UniformScript = () => {
1032
1101
  return /* @__PURE__ */ jsx3(Fragment5, {});
1033
1102
  };
1034
1103
  export {
1104
+ ClientContextPersonalizationTransfer,
1105
+ ClientContextTestTransfer,
1035
1106
  ClientContextUpdate,
1036
1107
  ClientContextualEditingComponentWrapper,
1037
1108
  ContextUpdateTransferClient,
package/dist/index.js CHANGED
@@ -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_emitPersonalizationResult(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) {
310
+ setLastLogged(ts);
311
+ context.internal_emitTestResult(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,10 @@ var _serverTransitionState;
732
794
  var _scores;
733
795
  var _state;
734
796
  var _pzCache;
797
+ var _plugins;
735
798
  var _mitt3;
736
- var _emitTest;
737
- var emitTest_fn;
799
+ var _updateGoals;
800
+ var updateGoals_fn;
738
801
  var _updateComputedScores;
739
802
  var updateComputedScores_fn;
740
803
  var _calculateScores;
@@ -743,10 +806,14 @@ _serverTransitionState = /* @__PURE__ */ new WeakMap();
743
806
  _scores = /* @__PURE__ */ new WeakMap();
744
807
  _state = /* @__PURE__ */ new WeakMap();
745
808
  _pzCache = /* @__PURE__ */ new WeakMap();
809
+ _plugins = /* @__PURE__ */ new WeakMap();
746
810
  _mitt3 = /* @__PURE__ */ new WeakMap();
747
- _emitTest = /* @__PURE__ */ new WeakSet();
748
- emitTest_fn = function(event) {
749
- __privateGet(this, _mitt3).emit("testResult", event);
811
+ _updateGoals = /* @__PURE__ */ new WeakSet();
812
+ updateGoals_fn = async function(data) {
813
+ const goalCommands = this.manifest.computeGoals(data);
814
+ if (goalCommands.length !== 0) {
815
+ await this.storage.updateData(goalCommands);
816
+ }
750
817
  };
751
818
  _updateComputedScores = /* @__PURE__ */ new WeakSet();
752
819
  updateComputedScores_fn = function(newData) {
@@ -754,6 +821,10 @@ updateComputedScores_fn = function(newData) {
754
821
  const newScoresHaveChanged = !dequal(newScores, __privateGet(this, _scores));
755
822
  if (newScoresHaveChanged) {
756
823
  __privateSet(this, _scores, newScores);
824
+ __privateMethod(this, _updateGoals, updateGoals_fn).call(this, {
825
+ scores: __privateGet(this, _scores),
826
+ quirks: void 0
827
+ });
757
828
  __privateGet(this, _mitt3).emit("scoresUpdated", newScores);
758
829
  __privateGet(this, _mitt3).emit("log", ["info", 3, newScores]);
759
830
  }
@@ -894,10 +965,10 @@ var createClientUniformContext = (options) => {
894
965
  };
895
966
 
896
967
  // src/hooks/useInitUniformContext.ts
897
- var import_react5 = require("react");
968
+ var import_react7 = require("react");
898
969
  var useInitUniformContext = (callback) => {
899
- const [called, setCalled] = (0, import_react5.useState)(false);
900
- (0, import_react5.useEffect)(() => {
970
+ const [called, setCalled] = (0, import_react7.useState)(false);
971
+ (0, import_react7.useEffect)(() => {
901
972
  if (typeof window === "undefined" || called || typeof window.__UNIFORM_CONTEXT__ !== "undefined") {
902
973
  return;
903
974
  }
@@ -933,12 +1004,12 @@ var DefaultUniformClientContext = ({ manifest, disableDevTools }) => {
933
1004
  // src/components/PersonalizeClient.ts
934
1005
  var import_canvas2 = require("@uniformdev/canvas");
935
1006
  var import_canvas_next_rsc_shared2 = require("@uniformdev/canvas-next-rsc-shared");
936
- var import_react6 = require("react");
1007
+ var import_react8 = require("react");
937
1008
  var PersonalizeClient = (props) => {
938
1009
  const { slots } = props;
939
1010
  const { context } = useUniformContext();
940
- const [indexesToShow, setIndexesToShow] = (0, import_react6.useState)(props.indexes);
941
- (0, import_react6.useEffect)(() => {
1011
+ const [indexesToShow, setIndexesToShow] = (0, import_react8.useState)(props.indexes);
1012
+ (0, import_react8.useEffect)(() => {
942
1013
  const result = (0, import_canvas_next_rsc_shared2.runPersonalization)({
943
1014
  ...props,
944
1015
  contextInstance: context
@@ -949,19 +1020,19 @@ var PersonalizeClient = (props) => {
949
1020
  var _a;
950
1021
  return (_a = slots[import_canvas2.CANVAS_PERSONALIZE_SLOT]) == null ? void 0 : _a.items[key];
951
1022
  });
952
- return (0, import_react6.createElement)(import_react6.Fragment, void 0, slotsToShow);
1023
+ return (0, import_react8.createElement)(import_react8.Fragment, void 0, slotsToShow);
953
1024
  };
954
1025
 
955
1026
  // src/components/TestClient.ts
956
1027
  var import_canvas3 = require("@uniformdev/canvas");
957
1028
  var import_canvas_next_rsc_shared3 = require("@uniformdev/canvas-next-rsc-shared");
958
- var import_react7 = require("react");
1029
+ var import_react9 = require("react");
959
1030
  var TestClient = (props) => {
960
1031
  var _a;
961
1032
  const { slots } = props;
962
1033
  const { context } = useUniformContext();
963
- const [index, setIndex] = (0, import_react7.useState)(0);
964
- (0, import_react7.useEffect)(() => {
1034
+ const [index, setIndex] = (0, import_react9.useState)(0);
1035
+ (0, import_react9.useEffect)(() => {
965
1036
  const result = (0, import_canvas_next_rsc_shared3.runTest)({
966
1037
  ...props,
967
1038
  contextInstance: context
@@ -971,20 +1042,20 @@ var TestClient = (props) => {
971
1042
  if (typeof index !== "number") {
972
1043
  return null;
973
1044
  }
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]);
1045
+ 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
1046
  };
976
1047
 
977
1048
  // src/components/UniformScriptClient.tsx
978
1049
  var import_canvas4 = require("@uniformdev/canvas");
979
1050
  var import_navigation4 = require("next/navigation");
980
- var import_react8 = require("react");
1051
+ var import_react10 = require("react");
981
1052
  var import_jsx_runtime3 = require("react/jsx-runtime");
982
1053
  var UniformScript = () => {
983
1054
  const router = (0, import_navigation4.useRouter)();
984
1055
  const params = (0, import_navigation4.useSearchParams)();
985
- const needsToRefreshRef = (0, import_react8.useRef)(false);
1056
+ const needsToRefreshRef = (0, import_react10.useRef)(false);
986
1057
  const enabled = params.get(import_canvas4.IN_CONTEXT_EDITOR_QUERY_STRING_PARAM) === "true";
987
- const channel = (0, import_react8.useMemo)(() => {
1058
+ const channel = (0, import_react10.useMemo)(() => {
988
1059
  var _a;
989
1060
  if (typeof window === "undefined") {
990
1061
  return;
@@ -995,7 +1066,7 @@ var UniformScript = () => {
995
1066
  });
996
1067
  return instance;
997
1068
  }, []);
998
- (0, import_react8.useEffect)(() => {
1069
+ (0, import_react10.useEffect)(() => {
999
1070
  if (!channel) {
1000
1071
  return;
1001
1072
  }
@@ -1012,7 +1083,7 @@ var UniformScript = () => {
1012
1083
  unsubscribeFromEditorUpdates();
1013
1084
  };
1014
1085
  }, [channel, router]);
1015
- (0, import_react8.useEffect)(() => {
1086
+ (0, import_react10.useEffect)(() => {
1016
1087
  if (typeof window === "undefined") {
1017
1088
  return;
1018
1089
  }
@@ -1033,7 +1104,7 @@ var UniformScript = () => {
1033
1104
  existing.remove();
1034
1105
  }
1035
1106
  }, [enabled]);
1036
- (0, import_react8.useEffect)(() => {
1107
+ (0, import_react10.useEffect)(() => {
1037
1108
  const handleBlurChange = () => {
1038
1109
  if (needsToRefreshRef.current) {
1039
1110
  router.refresh();
@@ -1049,6 +1120,8 @@ var UniformScript = () => {
1049
1120
  };
1050
1121
  // Annotate the CommonJS export names for ESM import in node:
1051
1122
  0 && (module.exports = {
1123
+ ClientContextPersonalizationTransfer,
1124
+ ClientContextTestTransfer,
1052
1125
  ClientContextUpdate,
1053
1126
  ClientContextualEditingComponentWrapper,
1054
1127
  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_emitPersonalizationResult(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) {
286
+ setLastLogged(ts);
287
+ context.internal_emitTestResult(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,10 @@ var _serverTransitionState;
712
772
  var _scores;
713
773
  var _state;
714
774
  var _pzCache;
775
+ var _plugins;
715
776
  var _mitt3;
716
- var _emitTest;
717
- var emitTest_fn;
777
+ var _updateGoals;
778
+ var updateGoals_fn;
718
779
  var _updateComputedScores;
719
780
  var updateComputedScores_fn;
720
781
  var _calculateScores;
@@ -723,10 +784,14 @@ _serverTransitionState = /* @__PURE__ */ new WeakMap();
723
784
  _scores = /* @__PURE__ */ new WeakMap();
724
785
  _state = /* @__PURE__ */ new WeakMap();
725
786
  _pzCache = /* @__PURE__ */ new WeakMap();
787
+ _plugins = /* @__PURE__ */ new WeakMap();
726
788
  _mitt3 = /* @__PURE__ */ new WeakMap();
727
- _emitTest = /* @__PURE__ */ new WeakSet();
728
- emitTest_fn = function(event) {
729
- __privateGet(this, _mitt3).emit("testResult", event);
789
+ _updateGoals = /* @__PURE__ */ new WeakSet();
790
+ updateGoals_fn = async function(data) {
791
+ const goalCommands = this.manifest.computeGoals(data);
792
+ if (goalCommands.length !== 0) {
793
+ await this.storage.updateData(goalCommands);
794
+ }
730
795
  };
731
796
  _updateComputedScores = /* @__PURE__ */ new WeakSet();
732
797
  updateComputedScores_fn = function(newData) {
@@ -734,6 +799,10 @@ updateComputedScores_fn = function(newData) {
734
799
  const newScoresHaveChanged = !dequal(newScores, __privateGet(this, _scores));
735
800
  if (newScoresHaveChanged) {
736
801
  __privateSet(this, _scores, newScores);
802
+ __privateMethod(this, _updateGoals, updateGoals_fn).call(this, {
803
+ scores: __privateGet(this, _scores),
804
+ quirks: void 0
805
+ });
737
806
  __privateGet(this, _mitt3).emit("scoresUpdated", newScores);
738
807
  __privateGet(this, _mitt3).emit("log", ["info", 3, newScores]);
739
808
  }
@@ -874,10 +943,10 @@ var createClientUniformContext = (options) => {
874
943
  };
875
944
 
876
945
  // src/hooks/useInitUniformContext.ts
877
- import { useEffect as useEffect4, useState as useState3 } from "react";
946
+ import { useEffect as useEffect6, useState as useState5 } from "react";
878
947
  var useInitUniformContext = (callback) => {
879
- const [called, setCalled] = useState3(false);
880
- useEffect4(() => {
948
+ const [called, setCalled] = useState5(false);
949
+ useEffect6(() => {
881
950
  if (typeof window === "undefined" || called || typeof window.__UNIFORM_CONTEXT__ !== "undefined") {
882
951
  return;
883
952
  }
@@ -913,12 +982,12 @@ var DefaultUniformClientContext = ({ manifest, disableDevTools }) => {
913
982
  // src/components/PersonalizeClient.ts
914
983
  import { CANVAS_PERSONALIZE_SLOT } from "@uniformdev/canvas";
915
984
  import { runPersonalization } from "@uniformdev/canvas-next-rsc-shared";
916
- import { createElement, Fragment as Fragment3, useEffect as useEffect5, useState as useState4 } from "react";
985
+ import { createElement, Fragment as Fragment3, useEffect as useEffect7, useState as useState6 } from "react";
917
986
  var PersonalizeClient = (props) => {
918
987
  const { slots } = props;
919
988
  const { context } = useUniformContext();
920
- const [indexesToShow, setIndexesToShow] = useState4(props.indexes);
921
- useEffect5(() => {
989
+ const [indexesToShow, setIndexesToShow] = useState6(props.indexes);
990
+ useEffect7(() => {
922
991
  const result = runPersonalization({
923
992
  ...props,
924
993
  contextInstance: context
@@ -935,13 +1004,13 @@ var PersonalizeClient = (props) => {
935
1004
  // src/components/TestClient.ts
936
1005
  import { CANVAS_TEST_SLOT } from "@uniformdev/canvas";
937
1006
  import { runTest } from "@uniformdev/canvas-next-rsc-shared";
938
- import { createElement as createElement2, Fragment as Fragment4, useEffect as useEffect6, useState as useState5 } from "react";
1007
+ import { createElement as createElement2, Fragment as Fragment4, useEffect as useEffect8, useState as useState7 } from "react";
939
1008
  var TestClient = (props) => {
940
1009
  var _a;
941
1010
  const { slots } = props;
942
1011
  const { context } = useUniformContext();
943
- const [index, setIndex] = useState5(0);
944
- useEffect6(() => {
1012
+ const [index, setIndex] = useState7(0);
1013
+ useEffect8(() => {
945
1014
  const result = runTest({
946
1015
  ...props,
947
1016
  contextInstance: context
@@ -961,7 +1030,7 @@ import {
961
1030
  isAllowedReferrer
962
1031
  } from "@uniformdev/canvas";
963
1032
  import { useRouter as useRouter2, useSearchParams as useSearchParams3 } from "next/navigation";
964
- import { useEffect as useEffect7, useMemo, useRef } from "react";
1033
+ import { useEffect as useEffect9, useMemo, useRef } from "react";
965
1034
  import { Fragment as Fragment5, jsx as jsx3 } from "react/jsx-runtime";
966
1035
  var UniformScript = () => {
967
1036
  const router = useRouter2();
@@ -979,7 +1048,7 @@ var UniformScript = () => {
979
1048
  });
980
1049
  return instance;
981
1050
  }, []);
982
- useEffect7(() => {
1051
+ useEffect9(() => {
983
1052
  if (!channel) {
984
1053
  return;
985
1054
  }
@@ -996,7 +1065,7 @@ var UniformScript = () => {
996
1065
  unsubscribeFromEditorUpdates();
997
1066
  };
998
1067
  }, [channel, router]);
999
- useEffect7(() => {
1068
+ useEffect9(() => {
1000
1069
  if (typeof window === "undefined") {
1001
1070
  return;
1002
1071
  }
@@ -1017,7 +1086,7 @@ var UniformScript = () => {
1017
1086
  existing.remove();
1018
1087
  }
1019
1088
  }, [enabled]);
1020
- useEffect7(() => {
1089
+ useEffect9(() => {
1021
1090
  const handleBlurChange = () => {
1022
1091
  if (needsToRefreshRef.current) {
1023
1092
  router.refresh();
@@ -1032,6 +1101,8 @@ var UniformScript = () => {
1032
1101
  return /* @__PURE__ */ jsx3(Fragment5, {});
1033
1102
  };
1034
1103
  export {
1104
+ ClientContextPersonalizationTransfer,
1105
+ ClientContextTestTransfer,
1035
1106
  ClientContextUpdate,
1036
1107
  ClientContextualEditingComponentWrapper,
1037
1108
  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.7+bd4b0c6f4",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "scripts": {
6
6
  "build": "tsup",
@@ -25,16 +25,16 @@
25
25
  ],
26
26
  "devDependencies": {
27
27
  "@types/node": "^18.0.0",
28
- "@types/react": "^18.2.20",
29
- "eslint": "^8.11.0",
28
+ "@types/react": "18.2.40",
29
+ "eslint": "8.54.0",
30
30
  "next": "^13.4.12",
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.7+bd4b0c6f4",
36
+ "@uniformdev/canvas-next-rsc-shared": "^19.79.1-alpha.7+bd4b0c6f4",
37
+ "@uniformdev/canvas-react": "^19.79.1-alpha.7+bd4b0c6f4"
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": "bd4b0c6f4a67549f8eb7e127a85927c798e7eed0"
51
51
  }