@searchspring/snap-preact 0.60.0 → 0.60.1

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.
@@ -57,4 +57,9 @@ export declare class RecommendationInstantiator {
57
57
  on(event: string, ...func: Middleware<unknown>[]): void;
58
58
  use(attachments: Attachments): void;
59
59
  }
60
+ type DefinedProps = {
61
+ [key: string]: any;
62
+ };
63
+ export declare function defined(properties: Record<string, any>): DefinedProps;
64
+ export {};
60
65
  //# sourceMappingURL=RecommendationInstantiator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"RecommendationInstantiator.d.ts","sourceRoot":"","sources":["../../../src/Instantiators/RecommendationInstantiator.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,WAAW,EAAc,MAAM,4BAA4B,CAAC;AAC9E,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAErD,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAyB,MAAM,2BAA2B,CAAC;AACpG,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,KAAK,EACX,kBAAkB,EAClB,wBAAwB,EACxB,WAAW,EACX,gBAAgB,EAEhB,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAGnE,MAAM,MAAM,gCAAgC,GAAG;IAC9C,IAAI,CAAC,EAAE,MAAM,OAAO,OAAO,GAAG,OAAO,CAAC;IACtC,MAAM,CAAC,EAAE;QACR,OAAO,EAAE,aAAa,CAAC;QACvB,MAAM,CAAC,EAAE,YAAY,CAAC;KACtB,CAAC;IACF,UAAU,EAAE;QACX,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AK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,CAAA;KAAE,EAAE,CAAM;gBAE7D,MAAM,EAAE,gCAAgC,EAAE,QAAQ,CAAC,EAAE,kCAAkC,EAAE,OAAO,CAAC,EAAE,gBAAgB;IA8JxH,MAAM,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,kBAAkB,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,IAAI,CAAC,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAInG,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,GAAG,IAAI;IAIvD,GAAG,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI;CAG1C;AA6JD,KAAK,YAAY,GAAG;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACnB,CAAC;AAEF,wBAAgB,OAAO,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,YAAY,CAUrE"}
@@ -82,7 +82,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
82
82
  return (mod && mod.__esModule) ? mod : { "default": mod };
83
83
  };
84
84
  Object.defineProperty(exports, "__esModule", { value: true });
85
- exports.RecommendationInstantiator = void 0;
85
+ exports.defined = exports.RecommendationInstantiator = void 0;
86
86
  var jsx_runtime_1 = require("preact/jsx-runtime");
87
87
  var preact_1 = require("preact");
88
88
  var deepmerge_1 = __importDefault(require("deepmerge"));
@@ -127,7 +127,7 @@ var RecommendationInstantiator = /** @class */ (function () {
127
127
  var profileCount = {};
128
128
  this.targeter = new snap_toolbox_1.DomTargeter([
129
129
  {
130
- selector: this.config.selector || 'script[type="searchspring/recommend"], script[type="searchspring/personalized-recommendations"]',
130
+ selector: "".concat(this.config.selector || 'script[type="searchspring/recommend"], script[type="searchspring/personalized-recommendations"]', ", script[type=\"searchspring/recommend\"][profile=\"email\"]"),
131
131
  autoRetarget: true,
132
132
  clickRetarget: true,
133
133
  inject: {
@@ -147,28 +147,42 @@ var RecommendationInstantiator = /** @class */ (function () {
147
147
  emptyTarget: false,
148
148
  },
149
149
  ], function (target, elem, originalElem) { return __awaiter(_this, void 0, void 0, function () {
150
- var elemContext, scriptContextProfiles, scriptContextGlobals_1, requestGlobals_1, targetsArr_1, profile, products, product, seed, options, batched, shopper, shopperId, profileRequestGlobals;
150
+ var elemContext, scriptContextProfiles, scriptContextGlobals_1, requestGlobals_1, targetsArr_1, profile, products, product, seed, filters, blockedItems, options, shopper, shopperId, profileRequestGlobals;
151
151
  var _this = this;
152
152
  var _a;
153
153
  return __generator(this, function (_b) {
154
- elemContext = (0, snap_toolbox_1.getContext)(['shopperId', 'shopper', 'product', 'products', 'seed', 'cart', 'options', 'profile', 'custom', 'profiles', 'globals'], (originalElem || elem));
154
+ elemContext = (0, snap_toolbox_1.getContext)([
155
+ 'shopperId',
156
+ 'shopper',
157
+ 'product',
158
+ 'products',
159
+ 'seed',
160
+ 'cart',
161
+ 'filters',
162
+ 'blockedItems',
163
+ 'options',
164
+ 'profile',
165
+ 'custom',
166
+ 'profiles',
167
+ 'globals',
168
+ ], (originalElem || elem));
155
169
  if (elemContext.profiles && elemContext.profiles.length) {
156
170
  scriptContextProfiles = elemContext.profiles;
157
171
  scriptContextGlobals_1 = elemContext.globals;
158
- requestGlobals_1 = {
172
+ requestGlobals_1 = __assign({}, defined({
159
173
  blockedItems: scriptContextGlobals_1.blockedItems,
174
+ filters: scriptContextGlobals_1.filters,
160
175
  cart: scriptContextGlobals_1.cart && getArrayFunc(scriptContextGlobals_1.cart),
161
176
  products: scriptContextGlobals_1.products,
162
177
  shopper: (_a = scriptContextGlobals_1.shopper) === null || _a === void 0 ? void 0 : _a.id,
163
- siteId: scriptContextGlobals_1.siteId,
164
178
  batchId: Math.random(),
165
- };
179
+ }));
166
180
  targetsArr_1 = [];
167
181
  // build out the targets array for each profile
168
182
  scriptContextProfiles.forEach(function (profile) {
169
- if (profile.target) {
183
+ if (profile.selector) {
170
184
  var targetObj = {
171
- selector: profile.target,
185
+ selector: profile.selector,
172
186
  autoRetarget: true,
173
187
  clickRetarget: true,
174
188
  profile: profile,
@@ -181,7 +195,7 @@ var RecommendationInstantiator = /** @class */ (function () {
181
195
  var _a, _b;
182
196
  return __generator(this, function (_c) {
183
197
  if ((_a = target.profile) === null || _a === void 0 ? void 0 : _a.profile) {
184
- profileRequestGlobals = __assign(__assign(__assign({}, requestGlobals_1), (_b = target.profile) === null || _b === void 0 ? void 0 : _b.options), { tag: target.profile.profile });
198
+ profileRequestGlobals = __assign(__assign({}, requestGlobals_1), { profile: (_b = target.profile) === null || _b === void 0 ? void 0 : _b.options, tag: target.profile.profile });
185
199
  profileContext = (0, deepmerge_1.default)(this.context, { globals: scriptContextGlobals_1, profile: target.profile });
186
200
  if (elemContext.custom) {
187
201
  profileContext.custom = elemContext.custom;
@@ -193,8 +207,15 @@ var RecommendationInstantiator = /** @class */ (function () {
193
207
  }); });
194
208
  }
195
209
  else {
196
- profile = elemContext.profile, products = elemContext.products, product = elemContext.product, seed = elemContext.seed, options = elemContext.options, batched = elemContext.batched, shopper = elemContext.shopper, shopperId = elemContext.shopperId;
197
- profileRequestGlobals = __assign({ tag: profile, batched: batched !== null && batched !== void 0 ? batched : true, batchId: 1, products: products || (product && [product]) || (seed && [seed]), cart: elemContext.cart && getArrayFunc(elemContext.cart), shopper: (shopper === null || shopper === void 0 ? void 0 : shopper.id) || shopperId }, options);
210
+ profile = elemContext.profile, products = elemContext.products, product = elemContext.product, seed = elemContext.seed, filters = elemContext.filters, blockedItems = elemContext.blockedItems, options = elemContext.options, shopper = elemContext.shopper, shopperId = elemContext.shopperId;
211
+ profileRequestGlobals = __assign({ tag: profile }, defined({
212
+ products: products || (product && [product]) || (seed && [seed]),
213
+ cart: elemContext.cart && getArrayFunc(elemContext.cart),
214
+ shopper: (shopper === null || shopper === void 0 ? void 0 : shopper.id) || shopperId,
215
+ filters: filters,
216
+ blockedItems: blockedItems,
217
+ profile: options,
218
+ }));
198
219
  readyTheController(this, elem, elemContext, profileCount, originalElem, profileRequestGlobals);
199
220
  }
200
221
  return [2 /*return*/];
@@ -222,13 +243,14 @@ var RecommendationInstantiator = /** @class */ (function () {
222
243
  }());
223
244
  exports.RecommendationInstantiator = RecommendationInstantiator;
224
245
  function readyTheController(instance, injectedElem, context, profileCount, elem, controllerGlobals) {
225
- var _a, _b, _c;
246
+ var _a, _b, _c, _d, _e, _f, _g, _h;
226
247
  return __awaiter(this, void 0, void 0, function () {
227
- var batched, batchId, realtime, cart, tag, defaultGlobals, globals, controllerConfig, controller, createRecommendationController, profileVars, component, RecommendationsComponent, _d;
228
- return __generator(this, function (_e) {
229
- switch (_e.label) {
248
+ var profile, batchId, cart, tag, batched, globals, controllerConfig, controller, createRecommendationController, profileVars, component, RecommendationsComponent, _j;
249
+ return __generator(this, function (_k) {
250
+ switch (_k.label) {
230
251
  case 0:
231
- batched = controllerGlobals.batched, batchId = controllerGlobals.batchId, realtime = controllerGlobals.realtime, cart = controllerGlobals.cart, tag = controllerGlobals.tag;
252
+ profile = controllerGlobals.profile, batchId = controllerGlobals.batchId, cart = controllerGlobals.cart, tag = controllerGlobals.tag;
253
+ batched = (_a = ((profile === null || profile === void 0 ? void 0 : profile.batched) || controllerGlobals.batched)) !== null && _a !== void 0 ? _a : true;
232
254
  if (!tag) {
233
255
  // FEEDBACK: change message depending on script integration type (profile vs. legacy)
234
256
  instance.logger.warn("'profile' is missing from <script> tag, skipping this profile", elem);
@@ -238,16 +260,15 @@ function readyTheController(instance, injectedElem, context, profileCount, elem,
238
260
  instance.tracker.cookies.cart.set(cart);
239
261
  }
240
262
  profileCount[tag] = profileCount[tag] + 1 || 1;
241
- defaultGlobals = {
242
- limit: 20,
243
- };
244
263
  globals = deepmerge_1.default.all([
245
- defaultGlobals,
246
- ((_a = instance.config.client) === null || _a === void 0 ? void 0 : _a.globals) || {},
247
- ((_b = instance.config.config) === null || _b === void 0 ? void 0 : _b.globals) || {},
264
+ ((_b = instance.config.client) === null || _b === void 0 ? void 0 : _b.globals) || {},
265
+ ((_c = instance.config.config) === null || _c === void 0 ? void 0 : _c.globals) || {},
248
266
  controllerGlobals,
249
267
  ]);
250
- controllerConfig = __assign(__assign({ id: "recommend_".concat(tag, "_").concat(profileCount[tag] - 1), tag: tag, batched: batched !== null && batched !== void 0 ? batched : true, realtime: Boolean(realtime), batchId: batchId }, instance.config.config), { globals: globals });
268
+ controllerConfig = __assign(__assign({ id: "recommend_".concat(tag, "_").concat(profileCount[tag] - 1), tag: tag, batched: batched !== null && batched !== void 0 ? batched : true, realtime: Boolean((_e = (_d = context.options) === null || _d === void 0 ? void 0 : _d.realtime) !== null && _e !== void 0 ? _e : (_g = (_f = context.profile) === null || _f === void 0 ? void 0 : _f.options) === null || _g === void 0 ? void 0 : _g.realtime), batchId: batchId }, instance.config.config), { globals: globals });
269
+ if (profile === null || profile === void 0 ? void 0 : profile.branch) {
270
+ controllerConfig.branch = profile === null || profile === void 0 ? void 0 : profile.branch;
271
+ }
251
272
  controller = Object.keys(instance.controller)
252
273
  .map(function (id) { return instance.controller[id]; })
253
274
  .filter(function (controller) {
@@ -269,7 +290,7 @@ function readyTheController(instance, injectedElem, context, profileCount, elem,
269
290
  if (!!controller) return [3 /*break*/, 2];
270
291
  return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require('../create/createRecommendationController')); })];
271
292
  case 1:
272
- createRecommendationController = (_e.sent()).default;
293
+ createRecommendationController = (_k.sent()).default;
273
294
  controller = createRecommendationController({
274
295
  url: instance.config.url,
275
296
  controller: controllerConfig,
@@ -279,20 +300,20 @@ function readyTheController(instance, injectedElem, context, profileCount, elem,
279
300
  instance.uses.forEach(function (attachements) { return controller.use(attachements); });
280
301
  instance.plugins.forEach(function (plugin) { return controller.plugin.apply(controller, __spreadArray([plugin.func], plugin.args, false)); });
281
302
  instance.middleware.forEach(function (middleware) { return controller.on.apply(controller, __spreadArray([middleware.event], middleware.func, false)); });
282
- _e.label = 2;
303
+ _k.label = 2;
283
304
  case 2:
284
305
  if (!(!controller.store.loaded && !controller.store.loading)) return [3 /*break*/, 4];
285
306
  return [4 /*yield*/, controller.search()];
286
307
  case 3:
287
- _e.sent();
288
- _e.label = 4;
308
+ _k.sent();
309
+ _k.label = 4;
289
310
  case 4:
290
311
  controller.addTargeter(instance.targeter);
291
312
  instance.controller[controller.config.id] = controller;
292
313
  window.searchspring.controller = window.searchspring.controller || {};
293
314
  window.searchspring.controller[controller.config.id] = controller;
294
315
  profileVars = controller.store.profile.display.templateParameters;
295
- component = (_c = controller.store.profile.display.template) === null || _c === void 0 ? void 0 : _c.component;
316
+ component = (_h = controller.store.profile.display.template) === null || _h === void 0 ? void 0 : _h.component;
296
317
  if (controller.store.error) {
297
318
  //something went wrong
298
319
  //err was already logged - nothing to do.
@@ -310,14 +331,14 @@ function readyTheController(instance, injectedElem, context, profileCount, elem,
310
331
  instance.logger.error("profile '".concat(tag, "' found on the following element is missing a component!\n").concat(elem === null || elem === void 0 ? void 0 : elem.outerHTML));
311
332
  return [2 /*return*/];
312
333
  }
313
- _d = instance.config.components[component];
314
- if (!_d) return [3 /*break*/, 6];
334
+ _j = instance.config.components[component];
335
+ if (!_j) return [3 /*break*/, 6];
315
336
  return [4 /*yield*/, instance.config.components[component]()];
316
337
  case 5:
317
- _d = (_e.sent());
318
- _e.label = 6;
338
+ _j = (_k.sent());
339
+ _k.label = 6;
319
340
  case 6:
320
- RecommendationsComponent = _d;
341
+ RecommendationsComponent = _j;
321
342
  if (!RecommendationsComponent) {
322
343
  instance.logger.error("profile '".concat(tag, "' found on the following element is expecting component mapping for '").concat(component, "' - verify instantiator config.\n").concat(elem === null || elem === void 0 ? void 0 : elem.outerHTML));
323
344
  return [2 /*return*/];
@@ -349,3 +370,13 @@ function getArrayFunc(arrayOrFunc) {
349
370
  }
350
371
  return [];
351
372
  }
373
+ function defined(properties) {
374
+ var definedProps = {};
375
+ Object.keys(properties).map(function (key) {
376
+ if (properties[key] !== undefined) {
377
+ definedProps[key] = properties[key];
378
+ }
379
+ });
380
+ return definedProps;
381
+ }
382
+ exports.defined = defined;
@@ -57,4 +57,9 @@ export declare class RecommendationInstantiator {
57
57
  on(event: string, ...func: Middleware<unknown>[]): void;
58
58
  use(attachments: Attachments): void;
59
59
  }
60
+ type DefinedProps = {
61
+ [key: string]: any;
62
+ };
63
+ export declare function defined(properties: Record<string, any>): DefinedProps;
64
+ export {};
60
65
  //# sourceMappingURL=RecommendationInstantiator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"RecommendationInstantiator.d.ts","sourceRoot":"","sources":["../../../src/Instantiators/RecommendationInstantiator.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,WAAW,EAAc,MAAM,4BAA4B,CAAC;AAC9E,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAErD,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAyB,MAAM,2BAA2B,CAAC;AACpG,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,KAAK,EACX,kBAAkB,EAClB,wBAAwB,EACxB,WAAW,EACX,gBAAgB,EAEhB,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAGnE,MAAM,MAAM,gCAAgC,GAAG;IAC9C,IAAI,CAAC,EAAE,MAAM,OAAO,OAAO,GAAG,OAAO,CAAC;IACtC,MAAM,CAAC,EAAE;QACR,OAAO,EAAE,aAAa,CAAC;QACvB,MAAM,CAAC,EAAE,YAAY,CAAC;KACtB,CAAC;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,UAAU,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,CAAA;KAAE,EAAE,CAAM;gBAE7D,MAAM,EAAE,gCAAgC,EAAE,QAAQ,CAAC,EAAE,kCAAkC,EAAE,OAAO,CAAC,EAAE,gBAAgB;IA8JxH,MAAM,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,kBAAkB,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,IAAI,CAAC,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAInG,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,GAAG,IAAI;IAIvD,GAAG,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI;CAG1C;AA6JD,KAAK,YAAY,GAAG;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACnB,CAAC;AAEF,wBAAgB,OAAO,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,YAAY,CAUrE"}
@@ -40,7 +40,7 @@ export class RecommendationInstantiator {
40
40
  const profileCount = {};
41
41
  this.targeter = new DomTargeter([
42
42
  {
43
- selector: this.config.selector || 'script[type="searchspring/recommend"], script[type="searchspring/personalized-recommendations"]',
43
+ selector: `${this.config.selector || 'script[type="searchspring/recommend"], script[type="searchspring/personalized-recommendations"]'}, script[type="searchspring/recommend"][profile="email"]`,
44
44
  autoRetarget: true,
45
45
  clickRetarget: true,
46
46
  inject: {
@@ -60,27 +60,43 @@ export class RecommendationInstantiator {
60
60
  emptyTarget: false,
61
61
  },
62
62
  ], async (target, elem, originalElem) => {
63
- const elemContext = getContext(['shopperId', 'shopper', 'product', 'products', 'seed', 'cart', 'options', 'profile', 'custom', 'profiles', 'globals'], (originalElem || elem));
63
+ const elemContext = getContext([
64
+ 'shopperId',
65
+ 'shopper',
66
+ 'product',
67
+ 'products',
68
+ 'seed',
69
+ 'cart',
70
+ 'filters',
71
+ 'blockedItems',
72
+ 'options',
73
+ 'profile',
74
+ 'custom',
75
+ 'profiles',
76
+ 'globals',
77
+ ], (originalElem || elem));
64
78
  if (elemContext.profiles && elemContext.profiles.length) {
65
- // using the new script integration structure
79
+ // using the "grouped block" integration structure
66
80
  // type the new profile specific integration context variables
67
81
  const scriptContextProfiles = elemContext.profiles;
68
82
  const scriptContextGlobals = elemContext.globals;
69
83
  // grab from globals
70
84
  const requestGlobals = {
71
- blockedItems: scriptContextGlobals.blockedItems,
72
- cart: scriptContextGlobals.cart && getArrayFunc(scriptContextGlobals.cart),
73
- products: scriptContextGlobals.products,
74
- shopper: scriptContextGlobals.shopper?.id,
75
- siteId: scriptContextGlobals.siteId,
76
- batchId: Math.random(),
85
+ ...defined({
86
+ blockedItems: scriptContextGlobals.blockedItems,
87
+ filters: scriptContextGlobals.filters,
88
+ cart: scriptContextGlobals.cart && getArrayFunc(scriptContextGlobals.cart),
89
+ products: scriptContextGlobals.products,
90
+ shopper: scriptContextGlobals.shopper?.id,
91
+ batchId: Math.random(),
92
+ }),
77
93
  };
78
94
  const targetsArr = [];
79
95
  // build out the targets array for each profile
80
96
  scriptContextProfiles.forEach((profile) => {
81
- if (profile.target) {
97
+ if (profile.selector) {
82
98
  const targetObj = {
83
- selector: profile.target,
99
+ selector: profile.selector,
84
100
  autoRetarget: true,
85
101
  clickRetarget: true,
86
102
  profile,
@@ -90,7 +106,11 @@ export class RecommendationInstantiator {
90
106
  });
91
107
  new DomTargeter(targetsArr, async (target, elem, originalElem) => {
92
108
  if (target.profile?.profile) {
93
- const profileRequestGlobals = { ...requestGlobals, ...target.profile?.options, tag: target.profile.profile };
109
+ const profileRequestGlobals = {
110
+ ...requestGlobals,
111
+ profile: target.profile?.options,
112
+ tag: target.profile.profile,
113
+ };
94
114
  const profileContext = deepmerge(this.context, { globals: scriptContextGlobals, profile: target.profile });
95
115
  if (elemContext.custom) {
96
116
  profileContext.custom = elemContext.custom;
@@ -100,16 +120,18 @@ export class RecommendationInstantiator {
100
120
  });
101
121
  }
102
122
  else {
103
- // using the "legacy" method
104
- const { profile, products, product, seed, options, batched, shopper, shopperId } = elemContext;
123
+ // using the "legacy" integration structure
124
+ const { profile, products, product, seed, filters, blockedItems, options, shopper, shopperId } = elemContext;
105
125
  const profileRequestGlobals = {
106
126
  tag: profile,
107
- batched: batched ?? true,
108
- batchId: 1,
109
- products: products || (product && [product]) || (seed && [seed]),
110
- cart: elemContext.cart && getArrayFunc(elemContext.cart),
111
- shopper: shopper?.id || shopperId,
112
- ...options,
127
+ ...defined({
128
+ products: products || (product && [product]) || (seed && [seed]),
129
+ cart: elemContext.cart && getArrayFunc(elemContext.cart),
130
+ shopper: shopper?.id || shopperId,
131
+ filters,
132
+ blockedItems,
133
+ profile: options,
134
+ }),
113
135
  };
114
136
  readyTheController(this, elem, elemContext, profileCount, originalElem, profileRequestGlobals);
115
137
  }
@@ -126,7 +148,8 @@ export class RecommendationInstantiator {
126
148
  }
127
149
  }
128
150
  async function readyTheController(instance, injectedElem, context, profileCount, elem, controllerGlobals) {
129
- const { batched, batchId, realtime, cart, tag } = controllerGlobals;
151
+ const { profile, batchId, cart, tag } = controllerGlobals;
152
+ const batched = (profile?.batched || controllerGlobals.batched) ?? true;
130
153
  if (!tag) {
131
154
  // FEEDBACK: change message depending on script integration type (profile vs. legacy)
132
155
  instance.logger.warn(`'profile' is missing from <script> tag, skipping this profile`, elem);
@@ -136,11 +159,7 @@ async function readyTheController(instance, injectedElem, context, profileCount,
136
159
  instance.tracker.cookies.cart.set(cart);
137
160
  }
138
161
  profileCount[tag] = profileCount[tag] + 1 || 1;
139
- const defaultGlobals = {
140
- limit: 20,
141
- };
142
162
  const globals = deepmerge.all([
143
- defaultGlobals,
144
163
  instance.config.client?.globals || {},
145
164
  instance.config.config?.globals || {},
146
165
  controllerGlobals,
@@ -149,11 +168,14 @@ async function readyTheController(instance, injectedElem, context, profileCount,
149
168
  id: `recommend_${tag}_${profileCount[tag] - 1}`,
150
169
  tag,
151
170
  batched: batched ?? true,
152
- realtime: Boolean(realtime),
171
+ realtime: Boolean(context.options?.realtime ?? context.profile?.options?.realtime),
153
172
  batchId: batchId,
154
173
  ...instance.config.config,
155
174
  globals,
156
175
  };
176
+ if (profile?.branch) {
177
+ controllerConfig.branch = profile?.branch;
178
+ }
157
179
  // try to find an existing controller by similar configuration
158
180
  let controller = Object.keys(instance.controller)
159
181
  .map((id) => instance.controller[id])
@@ -242,3 +264,12 @@ function getArrayFunc(arrayOrFunc) {
242
264
  }
243
265
  return [];
244
266
  }
267
+ export function defined(properties) {
268
+ const definedProps = {};
269
+ Object.keys(properties).map((key) => {
270
+ if (properties[key] !== undefined) {
271
+ definedProps[key] = properties[key];
272
+ }
273
+ });
274
+ return definedProps;
275
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@searchspring/snap-preact",
3
- "version": "0.60.0",
3
+ "version": "0.60.1",
4
4
  "description": "Snap Preact",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -20,17 +20,17 @@
20
20
  "test:watch": "jest --watch"
21
21
  },
22
22
  "dependencies": {
23
- "@searchspring/snap-client": "^0.60.0",
24
- "@searchspring/snap-controller": "^0.60.0",
25
- "@searchspring/snap-event-manager": "^0.60.0",
26
- "@searchspring/snap-logger": "^0.60.0",
27
- "@searchspring/snap-platforms": "^0.60.0",
28
- "@searchspring/snap-preact-components": "^0.60.0",
29
- "@searchspring/snap-profiler": "^0.60.0",
30
- "@searchspring/snap-store-mobx": "^0.60.0",
31
- "@searchspring/snap-toolbox": "^0.60.0",
32
- "@searchspring/snap-tracker": "^0.60.0",
33
- "@searchspring/snap-url-manager": "^0.60.0",
23
+ "@searchspring/snap-client": "^0.60.1",
24
+ "@searchspring/snap-controller": "^0.60.1",
25
+ "@searchspring/snap-event-manager": "^0.60.1",
26
+ "@searchspring/snap-logger": "^0.60.1",
27
+ "@searchspring/snap-platforms": "^0.60.1",
28
+ "@searchspring/snap-preact-components": "^0.60.1",
29
+ "@searchspring/snap-profiler": "^0.60.1",
30
+ "@searchspring/snap-store-mobx": "^0.60.1",
31
+ "@searchspring/snap-toolbox": "^0.60.1",
32
+ "@searchspring/snap-tracker": "^0.60.1",
33
+ "@searchspring/snap-url-manager": "^0.60.1",
34
34
  "deepmerge": "4.3.1",
35
35
  "intersection-observer": "0.12.0",
36
36
  "is-plain-object": "5.0.0"
@@ -43,5 +43,5 @@
43
43
  "files": [
44
44
  "dist/**/*"
45
45
  ],
46
- "gitHead": "c1b320737bc856b18032888f7b6825fd4706def9"
46
+ "gitHead": "94761345dd36b121494c165d9844a27086085dc9"
47
47
  }