@searchspring/snap-preact 0.20.4 → 0.21.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.
- package/README.md +9 -1
- package/dist/cjs/Instantiators/RecommendationInstantiator.d.ts +5 -2
- package/dist/cjs/Instantiators/RecommendationInstantiator.d.ts.map +1 -1
- package/dist/cjs/Instantiators/RecommendationInstantiator.js +34 -16
- package/dist/cjs/Snap.d.ts +7 -11
- package/dist/cjs/Snap.d.ts.map +1 -1
- package/dist/cjs/Snap.js +32 -20
- package/dist/cjs/create/createAutocompleteController.d.ts.map +1 -1
- package/dist/cjs/create/createAutocompleteController.js +1 -1
- package/dist/cjs/create/createFinderController.d.ts.map +1 -1
- package/dist/cjs/create/createFinderController.js +1 -1
- package/dist/cjs/create/createRecommendationController.d.ts.map +1 -1
- package/dist/cjs/create/createRecommendationController.js +1 -1
- package/dist/cjs/create/createSearchController.d.ts.map +1 -1
- package/dist/cjs/create/createSearchController.js +1 -1
- package/dist/cjs/types.d.ts +5 -1
- package/dist/cjs/types.d.ts.map +1 -1
- package/dist/esm/Instantiators/RecommendationInstantiator.d.ts +5 -2
- package/dist/esm/Instantiators/RecommendationInstantiator.d.ts.map +1 -1
- package/dist/esm/Instantiators/RecommendationInstantiator.js +25 -10
- package/dist/esm/Snap.d.ts +7 -11
- package/dist/esm/Snap.d.ts.map +1 -1
- package/dist/esm/Snap.js +31 -19
- package/dist/esm/create/createAutocompleteController.d.ts.map +1 -1
- package/dist/esm/create/createAutocompleteController.js +1 -1
- package/dist/esm/create/createFinderController.d.ts.map +1 -1
- package/dist/esm/create/createFinderController.js +1 -1
- package/dist/esm/create/createRecommendationController.d.ts.map +1 -1
- package/dist/esm/create/createRecommendationController.js +1 -1
- package/dist/esm/create/createSearchController.d.ts.map +1 -1
- package/dist/esm/create/createSearchController.js +1 -1
- package/dist/esm/types.d.ts +5 -1
- package/dist/esm/types.d.ts.map +1 -1
- package/package.json +11 -11
package/README.md
CHANGED
|
@@ -22,12 +22,13 @@ const snap = new Snap(config);
|
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
## Configuration
|
|
25
|
-
A configuration object provided to Snap will
|
|
25
|
+
A configuration object provided to Snap will determine the services that will be created.
|
|
26
26
|
|
|
27
27
|
Full example:
|
|
28
28
|
|
|
29
29
|
```typescript
|
|
30
30
|
const config = {
|
|
31
|
+
context: globalContext,
|
|
31
32
|
url: {
|
|
32
33
|
parameters: {
|
|
33
34
|
core: {
|
|
@@ -89,6 +90,8 @@ const config = {
|
|
|
89
90
|
};
|
|
90
91
|
```
|
|
91
92
|
|
|
93
|
+
### `config.context` - optional `Context` object to be used to set the global context. If no context is provided, a default context taken from the integration script (`shopper` variable) will be used, otherwise the provided `config.context` is merged with the script context. This context becomes the `globalContext` that is passed to all controllers that are created.
|
|
94
|
+
|
|
92
95
|
### config.client
|
|
93
96
|
A single client instance will be created and shared across all services using the provided config.
|
|
94
97
|
|
|
@@ -111,6 +114,7 @@ The `instantiators` object must be defined if any Recommendation controllers hav
|
|
|
111
114
|
const config = {
|
|
112
115
|
instantiators: {
|
|
113
116
|
recommendation: {
|
|
117
|
+
context: recommendationContext,
|
|
114
118
|
components: {
|
|
115
119
|
Standard: () => Standard
|
|
116
120
|
},
|
|
@@ -130,6 +134,8 @@ const config = {
|
|
|
130
134
|
|
|
131
135
|
`recommendation.components` - required mapping of recommendation components.
|
|
132
136
|
|
|
137
|
+
`recommendation.context` - optional `Context` object to be used to set controller specific context. Defaults to the global context if no context prop is provided, or if one is provided, it is merged into the global context.
|
|
138
|
+
|
|
133
139
|
`recommendation.config.branch` - required current git branch name. Defined via webpack during bundle build:
|
|
134
140
|
|
|
135
141
|
```typescript
|
|
@@ -218,6 +224,7 @@ type ExtendedTarget = {
|
|
|
218
224
|
|
|
219
225
|
`url` - optional `UrlTranslator` config object to be used with the `UrlManager` for this controller
|
|
220
226
|
|
|
227
|
+
`context` - optional `Context` object to be used to set controller specific context. Defaults to the global context if no context prop is provided, or if one is provided, it is merged into the global context.
|
|
221
228
|
|
|
222
229
|
An example creating a SearchController:
|
|
223
230
|
|
|
@@ -226,6 +233,7 @@ const config = {
|
|
|
226
233
|
controllers: {
|
|
227
234
|
search: [
|
|
228
235
|
{
|
|
236
|
+
context: searchContext,
|
|
229
237
|
config: {
|
|
230
238
|
id: 'search',
|
|
231
239
|
},
|
|
@@ -3,7 +3,7 @@ import type { Logger } from '@searchspring/snap-logger';
|
|
|
3
3
|
import type { UrlTranslatorConfig } from '@searchspring/snap-url-manager';
|
|
4
4
|
import type { Client } from '@searchspring/snap-client';
|
|
5
5
|
import type { Tracker } from '@searchspring/snap-tracker';
|
|
6
|
-
import type { AbstractController, RecommendationController, Attachments } from '@searchspring/snap-controller';
|
|
6
|
+
import type { AbstractController, RecommendationController, Attachments, ContextVariables } from '@searchspring/snap-controller';
|
|
7
7
|
import type { Middleware } from '@searchspring/snap-event-manager';
|
|
8
8
|
import type { SnapControllerServices, RootComponent } from '../types';
|
|
9
9
|
export declare type RecommendationInstantiatorConfig = {
|
|
@@ -14,10 +14,12 @@ export declare type RecommendationInstantiatorConfig = {
|
|
|
14
14
|
branch: string;
|
|
15
15
|
realtime?: boolean;
|
|
16
16
|
batched?: boolean;
|
|
17
|
+
limit?: number;
|
|
17
18
|
} & Attachments;
|
|
18
19
|
selector?: string;
|
|
19
20
|
services?: SnapControllerServices;
|
|
20
21
|
url?: UrlTranslatorConfig;
|
|
22
|
+
context?: ContextVariables;
|
|
21
23
|
};
|
|
22
24
|
export declare type RecommendationInstantiatorServices = {
|
|
23
25
|
client: Client;
|
|
@@ -32,6 +34,7 @@ export declare class RecommendationInstantiator {
|
|
|
32
34
|
tracker: Tracker;
|
|
33
35
|
logger: Logger;
|
|
34
36
|
config: RecommendationInstantiatorConfig;
|
|
37
|
+
context: ContextVariables;
|
|
35
38
|
uses: Attachments[];
|
|
36
39
|
plugins: {
|
|
37
40
|
(cntrlr: AbstractController): Promise<void>;
|
|
@@ -41,7 +44,7 @@ export declare class RecommendationInstantiator {
|
|
|
41
44
|
func: Middleware<unknown>[];
|
|
42
45
|
}[];
|
|
43
46
|
targeter: DomTargeter;
|
|
44
|
-
constructor(config: RecommendationInstantiatorConfig, { client, logger, tracker }: RecommendationInstantiatorServices);
|
|
47
|
+
constructor(config: RecommendationInstantiatorConfig, { client, logger, tracker }: RecommendationInstantiatorServices, context?: ContextVariables);
|
|
45
48
|
plugin(func: (cntrlr: AbstractController) => Promise<void>): void;
|
|
46
49
|
on<T>(event: string, ...func: Middleware<T>[]): void;
|
|
47
50
|
use(attachments: Attachments): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RecommendationInstantiator.d.ts","sourceRoot":"","sources":["../../../src/Instantiators/RecommendationInstantiator.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"RecommendationInstantiator.d.ts","sourceRoot":"","sources":["../../../src/Instantiators/RecommendationInstantiator.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAc,MAAM,4BAA4B,CAAC;AAErE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjI,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,KAAK,EAAE,sBAAsB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEtE,oBAAY,gCAAgC,GAAG;IAC9C,UAAU,EAAE;QACX,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,OAAO,CAAC,aAAa,CAAC,GAAG,aA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,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI;IAIjE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI;IAIpD,GAAG,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI;CAG1C"}
|
|
@@ -74,13 +74,17 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
74
74
|
}
|
|
75
75
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
76
76
|
};
|
|
77
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
78
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
79
|
+
};
|
|
77
80
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
78
81
|
exports.RecommendationInstantiator = void 0;
|
|
79
82
|
var jsx_runtime_1 = require("preact/jsx-runtime");
|
|
80
83
|
var preact_1 = require("preact");
|
|
84
|
+
var deepmerge_1 = __importDefault(require("deepmerge"));
|
|
81
85
|
var snap_toolbox_1 = require("@searchspring/snap-toolbox");
|
|
82
86
|
var RecommendationInstantiator = /** @class */ (function () {
|
|
83
|
-
function RecommendationInstantiator(config, _a) {
|
|
87
|
+
function RecommendationInstantiator(config, _a, context) {
|
|
84
88
|
var _this = this;
|
|
85
89
|
var client = _a.client, logger = _a.logger, tracker = _a.tracker;
|
|
86
90
|
var _b;
|
|
@@ -89,6 +93,7 @@ var RecommendationInstantiator = /** @class */ (function () {
|
|
|
89
93
|
this.plugins = [];
|
|
90
94
|
this.middleware = [];
|
|
91
95
|
this.config = config;
|
|
96
|
+
this.context = (0, deepmerge_1.default)(context || {}, config.context || {});
|
|
92
97
|
if (!this.config) {
|
|
93
98
|
throw new Error("Recommendation Instantiator config is required");
|
|
94
99
|
}
|
|
@@ -121,16 +126,20 @@ var RecommendationInstantiator = /** @class */ (function () {
|
|
|
121
126
|
},
|
|
122
127
|
},
|
|
123
128
|
], function (target, injectedElem, elem) { return __awaiter(_this, void 0, void 0, function () {
|
|
124
|
-
var
|
|
125
|
-
var _c, _d, _e, _f;
|
|
129
|
+
var contextGlobals, elemContext, context, shopper, shopperId, product, seed, options, tag, defaultGlobals, globals, controllerConfig, createRecommendationController, client, tracker, recs, profileVars, component, RecommendationsComponent, _a;
|
|
130
|
+
var _b, _c, _d, _e, _f;
|
|
126
131
|
return __generator(this, function (_g) {
|
|
127
132
|
switch (_g.label) {
|
|
128
133
|
case 0:
|
|
129
|
-
|
|
130
|
-
|
|
134
|
+
contextGlobals = {};
|
|
135
|
+
elemContext = (0, snap_toolbox_1.getContext)(['shopperId', 'shopper', 'product', 'seed', 'options', 'profile', 'custom'], elem);
|
|
136
|
+
context = (0, deepmerge_1.default)(this.context, elemContext);
|
|
137
|
+
shopper = context.shopper, shopperId = context.shopperId, product = context.product, seed = context.seed, options = context.options;
|
|
131
138
|
/*
|
|
132
139
|
type instantiatorContext = {
|
|
133
|
-
shopper?:
|
|
140
|
+
shopper?: {
|
|
141
|
+
id: string;
|
|
142
|
+
};
|
|
134
143
|
shopperId?: string;
|
|
135
144
|
product?: string;
|
|
136
145
|
seed?: string;
|
|
@@ -140,27 +149,35 @@ var RecommendationInstantiator = /** @class */ (function () {
|
|
|
140
149
|
batched?: boolean;
|
|
141
150
|
realtime?: boolean;
|
|
142
151
|
categories?: any;
|
|
152
|
+
limit?: number;
|
|
143
153
|
}
|
|
144
154
|
}
|
|
145
155
|
*/
|
|
146
156
|
if (shopper || shopperId) {
|
|
147
|
-
|
|
157
|
+
contextGlobals.shopper = (shopper === null || shopper === void 0 ? void 0 : shopper.id) || shopperId;
|
|
148
158
|
}
|
|
149
159
|
if (product || seed) {
|
|
150
|
-
|
|
160
|
+
contextGlobals.product = product || seed;
|
|
151
161
|
}
|
|
152
162
|
if (options === null || options === void 0 ? void 0 : options.branch) {
|
|
153
|
-
|
|
163
|
+
contextGlobals.branch = options.branch;
|
|
154
164
|
}
|
|
155
165
|
if (options === null || options === void 0 ? void 0 : options.siteId) {
|
|
156
|
-
|
|
166
|
+
contextGlobals.siteId = options.siteId;
|
|
157
167
|
}
|
|
158
168
|
if (options === null || options === void 0 ? void 0 : options.categories) {
|
|
159
|
-
|
|
169
|
+
contextGlobals.categories = options.categories;
|
|
170
|
+
}
|
|
171
|
+
if ((options === null || options === void 0 ? void 0 : options.limit) && Number.isInteger(Number(options === null || options === void 0 ? void 0 : options.limit))) {
|
|
172
|
+
contextGlobals.limits = Number(options === null || options === void 0 ? void 0 : options.limit);
|
|
160
173
|
}
|
|
161
174
|
tag = injectedElem.getAttribute('searchspring-recommend');
|
|
162
175
|
profileCount[tag] = profileCount[tag] + 1 || 1;
|
|
163
|
-
|
|
176
|
+
defaultGlobals = {
|
|
177
|
+
limits: 20,
|
|
178
|
+
};
|
|
179
|
+
globals = (0, deepmerge_1.default)((0, deepmerge_1.default)(defaultGlobals, ((_b = this.config.config) === null || _b === void 0 ? void 0 : _b.globals) || {}), contextGlobals);
|
|
180
|
+
controllerConfig = __assign(__assign({ id: "recommend_".concat(tag + (profileCount[tag] - 1)), tag: tag, batched: (_c = options === null || options === void 0 ? void 0 : options.batched) !== null && _c !== void 0 ? _c : true, realtime: Boolean(options === null || options === void 0 ? void 0 : options.realtime) }, this.config.config), { globals: globals });
|
|
164
181
|
return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require('../create/createRecommendationController')); })];
|
|
165
182
|
case 1:
|
|
166
183
|
createRecommendationController = (_g.sent()).default;
|
|
@@ -169,6 +186,7 @@ var RecommendationInstantiator = /** @class */ (function () {
|
|
|
169
186
|
recs = createRecommendationController({
|
|
170
187
|
url: this.config.url || {},
|
|
171
188
|
controller: controllerConfig,
|
|
189
|
+
context: context,
|
|
172
190
|
}, { client: client, tracker: tracker });
|
|
173
191
|
this.uses.forEach(function (attachements) { return recs.use(attachements); });
|
|
174
192
|
this.plugins.forEach(function (plugin) { return recs.plugin(plugin); });
|
|
@@ -188,14 +206,14 @@ var RecommendationInstantiator = /** @class */ (function () {
|
|
|
188
206
|
recs.log.error("template does not support components!");
|
|
189
207
|
return [2 /*return*/];
|
|
190
208
|
}
|
|
191
|
-
|
|
192
|
-
if (!
|
|
209
|
+
_a = this.config.components;
|
|
210
|
+
if (!_a) return [3 /*break*/, 4];
|
|
193
211
|
return [4 /*yield*/, this.config.components[component]()];
|
|
194
212
|
case 3:
|
|
195
|
-
|
|
213
|
+
_a = (_g.sent());
|
|
196
214
|
_g.label = 4;
|
|
197
215
|
case 4:
|
|
198
|
-
RecommendationsComponent =
|
|
216
|
+
RecommendationsComponent = _a;
|
|
199
217
|
if (!RecommendationsComponent) {
|
|
200
218
|
recs.log.error("component '".concat(profileVars.component, "' not found!"));
|
|
201
219
|
return [2 /*return*/];
|
package/dist/cjs/Snap.d.ts
CHANGED
|
@@ -2,8 +2,7 @@ import { Client } from '@searchspring/snap-client';
|
|
|
2
2
|
import { Logger } from '@searchspring/snap-logger';
|
|
3
3
|
import { Tracker } from '@searchspring/snap-tracker';
|
|
4
4
|
import type { ClientConfig, ClientGlobals } from '@searchspring/snap-client';
|
|
5
|
-
import type { AbstractController, SearchController, AutocompleteController, FinderController, RecommendationController, SearchControllerConfig, AutocompleteControllerConfig, FinderControllerConfig, RecommendationControllerConfig, ControllerConfigs } from '@searchspring/snap-controller';
|
|
6
|
-
import type { Product } from '@searchspring/snap-tracker';
|
|
5
|
+
import type { AbstractController, SearchController, AutocompleteController, FinderController, RecommendationController, SearchControllerConfig, AutocompleteControllerConfig, FinderControllerConfig, RecommendationControllerConfig, ControllerConfigs, ContextVariables } from '@searchspring/snap-controller';
|
|
7
6
|
import type { Target, OnTarget } from '@searchspring/snap-toolbox';
|
|
8
7
|
import type { UrlTranslatorConfig } from '@searchspring/snap-url-manager';
|
|
9
8
|
import { RecommendationInstantiator, RecommendationInstantiatorConfig } from './Instantiators/RecommendationInstantiator';
|
|
@@ -17,14 +16,6 @@ declare type ExtendedTarget = Target & {
|
|
|
17
16
|
onTarget?: OnTarget;
|
|
18
17
|
prefetch?: boolean;
|
|
19
18
|
};
|
|
20
|
-
declare type ContextVariables = {
|
|
21
|
-
shopper?: {
|
|
22
|
-
id: string;
|
|
23
|
-
cart?: Product[];
|
|
24
|
-
[variable: string]: any;
|
|
25
|
-
};
|
|
26
|
-
[variable: string]: any;
|
|
27
|
-
};
|
|
28
19
|
export declare type SnapConfig = {
|
|
29
20
|
context?: ContextVariables;
|
|
30
21
|
url?: UrlTranslatorConfig;
|
|
@@ -41,24 +32,28 @@ export declare type SnapConfig = {
|
|
|
41
32
|
targeters?: ExtendedTarget[];
|
|
42
33
|
services?: SnapControllerServices;
|
|
43
34
|
url?: UrlTranslatorConfig;
|
|
35
|
+
context?: ContextVariables;
|
|
44
36
|
}[];
|
|
45
37
|
autocomplete?: {
|
|
46
38
|
config: AutocompleteControllerConfig;
|
|
47
39
|
targeters: ExtendedTarget[];
|
|
48
40
|
services?: SnapControllerServices;
|
|
49
41
|
url?: UrlTranslatorConfig;
|
|
42
|
+
context?: ContextVariables;
|
|
50
43
|
}[];
|
|
51
44
|
finder?: {
|
|
52
45
|
config: FinderControllerConfig;
|
|
53
46
|
targeters?: ExtendedTarget[];
|
|
54
47
|
services?: SnapControllerServices;
|
|
55
48
|
url?: UrlTranslatorConfig;
|
|
49
|
+
context?: ContextVariables;
|
|
56
50
|
}[];
|
|
57
51
|
recommendation?: {
|
|
58
52
|
config: RecommendationControllerConfig;
|
|
59
53
|
targeters?: ExtendedTarget[];
|
|
60
54
|
services?: SnapControllerServices;
|
|
61
55
|
url?: UrlTranslatorConfig;
|
|
56
|
+
context?: ContextVariables;
|
|
62
57
|
}[];
|
|
63
58
|
};
|
|
64
59
|
};
|
|
@@ -74,6 +69,7 @@ export declare class Snap {
|
|
|
74
69
|
logger: Logger;
|
|
75
70
|
client: Client;
|
|
76
71
|
tracker: Tracker;
|
|
72
|
+
context: ContextVariables;
|
|
77
73
|
_controllerPromises: {
|
|
78
74
|
[controllerConfigId: string]: Promise<ControllerTypes>;
|
|
79
75
|
};
|
|
@@ -86,7 +82,7 @@ export declare class Snap {
|
|
|
86
82
|
getInstantiator: (id: string) => Promise<RecommendationInstantiator>;
|
|
87
83
|
getController: (id: string) => Promise<ControllerTypes>;
|
|
88
84
|
getControllers: (...controllerIds: string[]) => Promise<ControllerTypes[]>;
|
|
89
|
-
createController: (type: DynamicImportNames, config: ControllerConfigs, services: SnapControllerServices, urlConfig: UrlTranslatorConfig, resolve: (value?: ControllerTypes | PromiseLike<ControllerTypes>) => void) => Promise<ControllerTypes>;
|
|
85
|
+
createController: (type: DynamicImportNames, config: ControllerConfigs, services: SnapControllerServices, urlConfig: UrlTranslatorConfig, resolve: (value?: ControllerTypes | PromiseLike<ControllerTypes>) => void, context?: ContextVariables) => Promise<ControllerTypes>;
|
|
90
86
|
constructor(config: SnapConfig);
|
|
91
87
|
}
|
|
92
88
|
export {};
|
package/dist/cjs/Snap.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Snap.d.ts","sourceRoot":"","sources":["../../src/Snap.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACnD,OAAO,EAAE,MAAM,EAAW,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"Snap.d.ts","sourceRoot":"","sources":["../../src/Snap.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACnD,OAAO,EAAE,MAAM,EAAW,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAIrD,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC7E,OAAO,KAAK,EACX,kBAAkB,EAClB,gBAAgB,EAChB,sBAAsB,EACtB,gBAAgB,EAChB,wBAAwB,EACxB,sBAAsB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IAEF,WAAW,EAAE;QACZ,CAAC,kBAAkB,EAAE,MAAM,GAAG,eAAe,CAAC;KAC9C,CAAC;IAEF,qBAAqB,EAAE;QACtB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAC;KAC9D,CAAC;IAEK,eAAe,OAAQ,MAAM,KAAG,QAAQ,0BAA0B,CAAC,CAExE;IAEK,aAAa,OAAQ,MAAM,KAAG,QAAQ,eAAe,CAAC,CAE3D;IAEK,cAAc,qBAAsB,MAAM,EAAE,KAAG,QAAQ,eAAe,EAAE,CAAC,CAI9E;IAEK,gBAAgB,SAChB,kBAAkB,UAChB,iBAAiB,YACf,sBAAsB,aACrB,mBAAmB,oBACZ,eAAe,GAAG,YAAY,eAAe,CAAC,KAAK,IAAI,YAC/D,gBAAgB,KACxB,QAAQ,eAAe,CAAC,CAgCzB;gBAEU,MAAM,EAAE,UAAU;CAyb9B"}
|
package/dist/cjs/Snap.js
CHANGED
|
@@ -77,6 +77,7 @@ var snap_client_1 = require("@searchspring/snap-client");
|
|
|
77
77
|
var snap_logger_1 = require("@searchspring/snap-logger");
|
|
78
78
|
var snap_tracker_1 = require("@searchspring/snap-tracker");
|
|
79
79
|
var snap_toolbox_1 = require("@searchspring/snap-toolbox");
|
|
80
|
+
var snap_toolbox_2 = require("@searchspring/snap-toolbox");
|
|
80
81
|
var createSearchController_1 = __importDefault(require("./create/createSearchController"));
|
|
81
82
|
var BRANCH_COOKIE = 'ssBranch';
|
|
82
83
|
var SS_DEV_COOKIE = 'ssDev';
|
|
@@ -90,7 +91,7 @@ var DynamicImportNames;
|
|
|
90
91
|
var Snap = /** @class */ (function () {
|
|
91
92
|
function Snap(config) {
|
|
92
93
|
var _this = this;
|
|
93
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
94
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
94
95
|
this.getInstantiator = function (id) {
|
|
95
96
|
return _this._instantiatorPromises[id] || Promise.reject("getInstantiator could not find instantiator with id: ".concat(id));
|
|
96
97
|
};
|
|
@@ -106,7 +107,7 @@ var Snap = /** @class */ (function () {
|
|
|
106
107
|
controllerIds.forEach(function (id) { return getControllerPromises.push(_this.getController(id)); });
|
|
107
108
|
return Promise.all(getControllerPromises);
|
|
108
109
|
};
|
|
109
|
-
this.createController = function (type, config, services, urlConfig, resolve) {
|
|
110
|
+
this.createController = function (type, config, services, urlConfig, resolve, context) {
|
|
110
111
|
var importPromise;
|
|
111
112
|
switch (type) {
|
|
112
113
|
case DynamicImportNames.SEARCH:
|
|
@@ -127,6 +128,7 @@ var Snap = /** @class */ (function () {
|
|
|
127
128
|
_this.controllers[config.id] = _.default({
|
|
128
129
|
url: (0, deepmerge_1.default)(_this.config.url || {}, urlConfig || {}),
|
|
129
130
|
controller: config,
|
|
131
|
+
context: (0, deepmerge_1.default)(_this.context || {}, context || {}),
|
|
130
132
|
}, { client: (services === null || services === void 0 ? void 0 : services.client) || _this.client, tracker: (services === null || services === void 0 ? void 0 : services.tracker) || _this.tracker });
|
|
131
133
|
resolve(_this.controllers[config.id]);
|
|
132
134
|
}
|
|
@@ -135,6 +137,16 @@ var Snap = /** @class */ (function () {
|
|
|
135
137
|
};
|
|
136
138
|
this.config = config;
|
|
137
139
|
this.logger = new snap_logger_1.Logger('Snap Preact ');
|
|
140
|
+
var globalContext = {};
|
|
141
|
+
try {
|
|
142
|
+
// get global context
|
|
143
|
+
globalContext = (0, snap_toolbox_2.getContext)(['shopper', 'config']);
|
|
144
|
+
}
|
|
145
|
+
catch (err) {
|
|
146
|
+
this.logger.error('failed to find global context');
|
|
147
|
+
}
|
|
148
|
+
this.config = (0, deepmerge_1.default)(this.config || {}, globalContext.config || {});
|
|
149
|
+
this.context = (0, deepmerge_1.default)(globalContext || {}, this.config.context || {});
|
|
138
150
|
if (!((_c = (_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.client) === null || _b === void 0 ? void 0 : _b.globals) === null || _c === void 0 ? void 0 : _c.siteId)) {
|
|
139
151
|
throw new Error("Snap: config provided must contain a valid config.client.globals.siteId value");
|
|
140
152
|
}
|
|
@@ -201,20 +213,19 @@ var Snap = /** @class */ (function () {
|
|
|
201
213
|
}
|
|
202
214
|
catch (e) { }
|
|
203
215
|
if (window.searchspring) {
|
|
204
|
-
|
|
205
|
-
window.searchspring.context = this.config.context;
|
|
216
|
+
window.searchspring.context = this.context;
|
|
206
217
|
if (this.client)
|
|
207
218
|
window.searchspring.client = this.client;
|
|
208
219
|
}
|
|
209
220
|
// autotrack shopper id from the context
|
|
210
|
-
if ((_g = (_f = this.
|
|
221
|
+
if ((_g = (_f = this.context) === null || _f === void 0 ? void 0 : _f.shopper) === null || _g === void 0 ? void 0 : _g.id) {
|
|
211
222
|
this.tracker.track.shopper.login({
|
|
212
|
-
id: this.
|
|
223
|
+
id: this.context.shopper.id,
|
|
213
224
|
});
|
|
214
225
|
}
|
|
215
226
|
// auto populate cart cookie from the context
|
|
216
|
-
if ((_j = (_h = this.
|
|
217
|
-
var cart = this.
|
|
227
|
+
if ((_j = (_h = this.context) === null || _h === void 0 ? void 0 : _h.shopper) === null || _j === void 0 ? void 0 : _j.cart) {
|
|
228
|
+
var cart = this.context.shopper.cart;
|
|
218
229
|
if (Array.isArray(cart)) {
|
|
219
230
|
var cartItems = cart.filter(function (item) { return (item === null || item === void 0 ? void 0 : item.sku) || (item === null || item === void 0 ? void 0 : item.childSku); }).map(function (item) { return ((item === null || item === void 0 ? void 0 : item.sku) || (item === null || item === void 0 ? void 0 : item.childSku)).trim(); });
|
|
220
231
|
this.tracker.cookies.cart.set(cartItems);
|
|
@@ -229,6 +240,7 @@ var Snap = /** @class */ (function () {
|
|
|
229
240
|
var cntrlr_1 = (0, createSearchController_1.default)({
|
|
230
241
|
url: (0, deepmerge_1.default)(_this.config.url || {}, controller.url || {}),
|
|
231
242
|
controller: controller.config,
|
|
243
|
+
context: (0, deepmerge_1.default)(_this.context || {}, controller.context || {}),
|
|
232
244
|
}, { client: ((_a = controller.services) === null || _a === void 0 ? void 0 : _a.client) || _this.client, tracker: ((_b = controller.services) === null || _b === void 0 ? void 0 : _b.tracker) || _this.tracker });
|
|
233
245
|
_this.controllers[cntrlr_1.config.id] = cntrlr_1;
|
|
234
246
|
_this._controllerPromises[cntrlr_1.config.id] = new Promise(function (resolve) { return resolve(cntrlr_1); });
|
|
@@ -340,7 +352,7 @@ var Snap = /** @class */ (function () {
|
|
|
340
352
|
});
|
|
341
353
|
}); };
|
|
342
354
|
if (!(controller === null || controller === void 0 ? void 0 : controller.targeters) || (controller === null || controller === void 0 ? void 0 : controller.targeters.length) === 0) {
|
|
343
|
-
_this.createController(DynamicImportNames.AUTOCOMPLETE, controller.config, controller.services, controller.url, resolve);
|
|
355
|
+
_this.createController(DynamicImportNames.AUTOCOMPLETE, controller.config, controller.services, controller.url, resolve, controller.context);
|
|
344
356
|
}
|
|
345
357
|
(_a = controller === null || controller === void 0 ? void 0 : controller.targeters) === null || _a === void 0 ? void 0 : _a.forEach(function (target, target_index) { return __awaiter(_this, void 0, void 0, function () {
|
|
346
358
|
var targeter;
|
|
@@ -368,7 +380,7 @@ var Snap = /** @class */ (function () {
|
|
|
368
380
|
var cntrlr;
|
|
369
381
|
return __generator(this, function (_a) {
|
|
370
382
|
switch (_a.label) {
|
|
371
|
-
case 0: return [4 /*yield*/, this.createController(DynamicImportNames.AUTOCOMPLETE, controller.config, controller.services, controller.url, resolve)];
|
|
383
|
+
case 0: return [4 /*yield*/, this.createController(DynamicImportNames.AUTOCOMPLETE, controller.config, controller.services, controller.url, resolve, controller.context)];
|
|
372
384
|
case 1:
|
|
373
385
|
cntrlr = _a.sent();
|
|
374
386
|
runBind_1();
|
|
@@ -420,7 +432,7 @@ var Snap = /** @class */ (function () {
|
|
|
420
432
|
});
|
|
421
433
|
}); };
|
|
422
434
|
if (!(controller === null || controller === void 0 ? void 0 : controller.targeters) || (controller === null || controller === void 0 ? void 0 : controller.targeters.length) === 0) {
|
|
423
|
-
_this.createController(DynamicImportNames.FINDER, controller.config, controller.services, controller.url, resolve);
|
|
435
|
+
_this.createController(DynamicImportNames.FINDER, controller.config, controller.services, controller.url, resolve, controller.context);
|
|
424
436
|
}
|
|
425
437
|
(_a = controller === null || controller === void 0 ? void 0 : controller.targeters) === null || _a === void 0 ? void 0 : _a.forEach(function (target, target_index) { return __awaiter(_this, void 0, void 0, function () {
|
|
426
438
|
var targeter;
|
|
@@ -436,7 +448,7 @@ var Snap = /** @class */ (function () {
|
|
|
436
448
|
var cntrlr;
|
|
437
449
|
return __generator(this, function (_a) {
|
|
438
450
|
switch (_a.label) {
|
|
439
|
-
case 0: return [4 /*yield*/, this.createController(DynamicImportNames.FINDER, controller.config, controller.services, controller.url, resolve)];
|
|
451
|
+
case 0: return [4 /*yield*/, this.createController(DynamicImportNames.FINDER, controller.config, controller.services, controller.url, resolve, controller.context)];
|
|
440
452
|
case 1:
|
|
441
453
|
cntrlr = _a.sent();
|
|
442
454
|
runSearch_2();
|
|
@@ -488,7 +500,7 @@ var Snap = /** @class */ (function () {
|
|
|
488
500
|
});
|
|
489
501
|
}); };
|
|
490
502
|
if (!(controller === null || controller === void 0 ? void 0 : controller.targeters) || (controller === null || controller === void 0 ? void 0 : controller.targeters.length) === 0) {
|
|
491
|
-
_this.createController(DynamicImportNames.RECOMMENDATION, controller.config, controller.services, controller.url, resolve);
|
|
503
|
+
_this.createController(DynamicImportNames.RECOMMENDATION, controller.config, controller.services, controller.url, resolve, controller.context);
|
|
492
504
|
}
|
|
493
505
|
(_a = controller === null || controller === void 0 ? void 0 : controller.targeters) === null || _a === void 0 ? void 0 : _a.forEach(function (target, target_index) { return __awaiter(_this, void 0, void 0, function () {
|
|
494
506
|
var targeter;
|
|
@@ -504,7 +516,7 @@ var Snap = /** @class */ (function () {
|
|
|
504
516
|
var cntrlr;
|
|
505
517
|
return __generator(this, function (_a) {
|
|
506
518
|
switch (_a.label) {
|
|
507
|
-
case 0: return [4 /*yield*/, this.createController(DynamicImportNames.RECOMMENDATION, controller.config, controller.services, controller.url, resolve)];
|
|
519
|
+
case 0: return [4 /*yield*/, this.createController(DynamicImportNames.RECOMMENDATION, controller.config, controller.services, controller.url, resolve, controller.context)];
|
|
508
520
|
case 1:
|
|
509
521
|
cntrlr = _a.sent();
|
|
510
522
|
runSearch_3();
|
|
@@ -527,16 +539,16 @@ var Snap = /** @class */ (function () {
|
|
|
527
539
|
}
|
|
528
540
|
}
|
|
529
541
|
});
|
|
530
|
-
if ((_l = config === null ||
|
|
542
|
+
if ((_m = (_l = this.config) === null || _l === void 0 ? void 0 : _l.instantiators) === null || _m === void 0 ? void 0 : _m.recommendation) {
|
|
531
543
|
try {
|
|
532
544
|
this._instantiatorPromises.recommendations = Promise.resolve().then(function () { return __importStar(require('./Instantiators/RecommendationInstantiator')); }).then(function (_a) {
|
|
533
545
|
var _b, _c, _d, _e, _f, _g;
|
|
534
546
|
var RecommendationInstantiator = _a.RecommendationInstantiator;
|
|
535
|
-
return new RecommendationInstantiator(config.instantiators.recommendation, {
|
|
536
|
-
client: ((_c = (_b = config.instantiators.recommendation) === null || _b === void 0 ? void 0 : _b.services) === null || _c === void 0 ? void 0 : _c.client) || _this.client,
|
|
537
|
-
tracker: ((_e = (_d = config.instantiators.recommendation) === null || _d === void 0 ? void 0 : _d.services) === null || _e === void 0 ? void 0 : _e.tracker) || _this.tracker,
|
|
538
|
-
logger: ((_g = (_f = config.instantiators.recommendation) === null || _f === void 0 ? void 0 : _f.services) === null || _g === void 0 ? void 0 : _g.logger) || _this.logger,
|
|
539
|
-
});
|
|
547
|
+
return new RecommendationInstantiator(_this.config.instantiators.recommendation, {
|
|
548
|
+
client: ((_c = (_b = _this.config.instantiators.recommendation) === null || _b === void 0 ? void 0 : _b.services) === null || _c === void 0 ? void 0 : _c.client) || _this.client,
|
|
549
|
+
tracker: ((_e = (_d = _this.config.instantiators.recommendation) === null || _d === void 0 ? void 0 : _d.services) === null || _e === void 0 ? void 0 : _e.tracker) || _this.tracker,
|
|
550
|
+
logger: ((_g = (_f = _this.config.instantiators.recommendation) === null || _f === void 0 ? void 0 : _f.services) === null || _g === void 0 ? void 0 : _g.logger) || _this.logger,
|
|
551
|
+
}, _this.context);
|
|
540
552
|
});
|
|
541
553
|
}
|
|
542
554
|
catch (err) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createAutocompleteController.d.ts","sourceRoot":"","sources":["../../../src/create/createAutocompleteController.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AASvE,OAAO,KAAK,EAAE,sBAAsB,EAAE,gCAAgC,EAAE,MAAM,UAAU,CAAC;iCAIjE,gCAAgC,aAAa,sBAAsB,KAAG,sBAAsB;AAApH,
|
|
1
|
+
{"version":3,"file":"createAutocompleteController.d.ts","sourceRoot":"","sources":["../../../src/create/createAutocompleteController.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AASvE,OAAO,KAAK,EAAE,sBAAsB,EAAE,gCAAgC,EAAE,MAAM,UAAU,CAAC;iCAIjE,gCAAgC,aAAa,sBAAsB,KAAG,sBAAsB;AAApH,wBAkBE"}
|
|
@@ -20,6 +20,6 @@ exports.default = (function (config, services) {
|
|
|
20
20
|
profiler: (services === null || services === void 0 ? void 0 : services.profiler) || new snap_profiler_1.Profiler(),
|
|
21
21
|
logger: (services === null || services === void 0 ? void 0 : services.logger) || new snap_logger_1.Logger(),
|
|
22
22
|
tracker: (services === null || services === void 0 ? void 0 : services.tracker) || new snap_tracker_1.Tracker(config.client.globals),
|
|
23
|
-
});
|
|
23
|
+
}, config.context);
|
|
24
24
|
return cntrlr;
|
|
25
25
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createFinderController.d.ts","sourceRoot":"","sources":["../../../src/create/createFinderController.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AASjE,OAAO,KAAK,EAAE,sBAAsB,EAAE,0BAA0B,EAAE,MAAM,UAAU,CAAC;iCAI3D,0BAA0B,aAAa,sBAAsB,KAAG,gBAAgB;AAAxG,
|
|
1
|
+
{"version":3,"file":"createFinderController.d.ts","sourceRoot":"","sources":["../../../src/create/createFinderController.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AASjE,OAAO,KAAK,EAAE,sBAAsB,EAAE,0BAA0B,EAAE,MAAM,UAAU,CAAC;iCAI3D,0BAA0B,aAAa,sBAAsB,KAAG,gBAAgB;AAAxG,wBAkBE"}
|
|
@@ -20,6 +20,6 @@ exports.default = (function (config, services) {
|
|
|
20
20
|
profiler: (services === null || services === void 0 ? void 0 : services.profiler) || new snap_profiler_1.Profiler(),
|
|
21
21
|
logger: (services === null || services === void 0 ? void 0 : services.logger) || new snap_logger_1.Logger(),
|
|
22
22
|
tracker: (services === null || services === void 0 ? void 0 : services.tracker) || new snap_tracker_1.Tracker(config.client.globals),
|
|
23
|
-
});
|
|
23
|
+
}, config.context);
|
|
24
24
|
return cntrlr;
|
|
25
25
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRecommendationController.d.ts","sourceRoot":"","sources":["../../../src/create/createRecommendationController.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AASzE,OAAO,KAAK,EAAE,sBAAsB,EAAE,kCAAkC,EAAE,MAAM,UAAU,CAAC;iCAInE,kCAAkC,aAAa,sBAAsB,KAAG,wBAAwB;AAAxH,
|
|
1
|
+
{"version":3,"file":"createRecommendationController.d.ts","sourceRoot":"","sources":["../../../src/create/createRecommendationController.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AASzE,OAAO,KAAK,EAAE,sBAAsB,EAAE,kCAAkC,EAAE,MAAM,UAAU,CAAC;iCAInE,kCAAkC,aAAa,sBAAsB,KAAG,wBAAwB;AAAxH,wBAiBE"}
|
|
@@ -20,6 +20,6 @@ exports.default = (function (config, services) {
|
|
|
20
20
|
profiler: (services === null || services === void 0 ? void 0 : services.profiler) || new snap_profiler_1.Profiler(),
|
|
21
21
|
logger: (services === null || services === void 0 ? void 0 : services.logger) || new snap_logger_1.Logger(),
|
|
22
22
|
tracker: (services === null || services === void 0 ? void 0 : services.tracker) || new snap_tracker_1.Tracker(config.client.globals),
|
|
23
|
-
});
|
|
23
|
+
}, config.context);
|
|
24
24
|
return cntrlr;
|
|
25
25
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createSearchController.d.ts","sourceRoot":"","sources":["../../../src/create/createSearchController.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAQjE,OAAO,KAAK,EAAE,sBAAsB,EAAE,0BAA0B,EAAE,MAAM,UAAU,CAAC;iCAI3D,0BAA0B,aAAa,sBAAsB,KAAG,gBAAgB;AAAxG,
|
|
1
|
+
{"version":3,"file":"createSearchController.d.ts","sourceRoot":"","sources":["../../../src/create/createSearchController.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAQjE,OAAO,KAAK,EAAE,sBAAsB,EAAE,0BAA0B,EAAE,MAAM,UAAU,CAAC;iCAI3D,0BAA0B,aAAa,sBAAsB,KAAG,gBAAgB;AAAxG,wBAkBE"}
|
|
@@ -20,6 +20,6 @@ exports.default = (function (config, services) {
|
|
|
20
20
|
profiler: (services === null || services === void 0 ? void 0 : services.profiler) || new snap_profiler_1.Profiler(),
|
|
21
21
|
logger: (services === null || services === void 0 ? void 0 : services.logger) || new snap_logger_1.Logger(),
|
|
22
22
|
tracker: (services === null || services === void 0 ? void 0 : services.tracker) || new snap_tracker_1.Tracker(config.client.globals),
|
|
23
|
-
});
|
|
23
|
+
}, config.context);
|
|
24
24
|
return cntrlr;
|
|
25
25
|
});
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { Client, ClientConfig, ClientGlobals } from '@searchspring/snap-client';
|
|
3
|
-
import type { AbstractController, SearchControllerConfig, AutocompleteControllerConfig, FinderControllerConfig, RecommendationControllerConfig } from '@searchspring/snap-controller';
|
|
3
|
+
import type { AbstractController, SearchControllerConfig, AutocompleteControllerConfig, FinderControllerConfig, RecommendationControllerConfig, ContextVariables } from '@searchspring/snap-controller';
|
|
4
4
|
import type { AbstractStore } from '@searchspring/snap-store-mobx';
|
|
5
5
|
import type { UrlManager, UrlTranslatorConfig } from '@searchspring/snap-url-manager';
|
|
6
6
|
import type { EventManager } from '@searchspring/snap-event-manager';
|
|
@@ -26,6 +26,7 @@ export declare type SnapSearchControllerConfig = {
|
|
|
26
26
|
config?: ClientConfig;
|
|
27
27
|
};
|
|
28
28
|
controller: SearchControllerConfig;
|
|
29
|
+
context?: ContextVariables;
|
|
29
30
|
};
|
|
30
31
|
export declare type SnapAutocompleteControllerConfig = {
|
|
31
32
|
url?: UrlTranslatorConfig;
|
|
@@ -34,6 +35,7 @@ export declare type SnapAutocompleteControllerConfig = {
|
|
|
34
35
|
config?: ClientConfig;
|
|
35
36
|
};
|
|
36
37
|
controller: AutocompleteControllerConfig;
|
|
38
|
+
context?: ContextVariables;
|
|
37
39
|
};
|
|
38
40
|
export declare type SnapFinderControllerConfig = {
|
|
39
41
|
url?: UrlTranslatorConfig;
|
|
@@ -42,6 +44,7 @@ export declare type SnapFinderControllerConfig = {
|
|
|
42
44
|
config?: ClientConfig;
|
|
43
45
|
};
|
|
44
46
|
controller: FinderControllerConfig;
|
|
47
|
+
context?: ContextVariables;
|
|
45
48
|
};
|
|
46
49
|
export declare type SnapRecommendationControllerConfig = {
|
|
47
50
|
url?: UrlTranslatorConfig;
|
|
@@ -50,5 +53,6 @@ export declare type SnapRecommendationControllerConfig = {
|
|
|
50
53
|
config?: ClientConfig;
|
|
51
54
|
};
|
|
52
55
|
controller: RecommendationControllerConfig;
|
|
56
|
+
context?: ContextVariables;
|
|
53
57
|
};
|
|
54
58
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/cjs/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AACrF,OAAO,KAAK,EACX,kBAAkB,EAClB,sBAAsB,EACtB,4BAA4B,EAC5B,sBAAsB,EACtB,8BAA8B,EAC9B,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,KAAK,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACtF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAE1D,oBAAY,sBAAsB,GAAG;IACpC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,oBAAY,aAAa,GAAG,KAAK,CAAC,WAAW,CAAC;IAAE,UAAU,EAAE,kBAAkB,CAAA;CAAE,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A;CAAE,CAAC,CAAC;AAElF,oBAAY,0BAA0B,GAAG;IACxC,GAAG,CAAC,EAAE,mBAAmB,CAAC;IAC1B,MAAM,CAAC,EAAE;QACR,OAAO,EAAE,aAAa,CAAC;QACvB,MAAM,CAAC,EAAE,YAAY,CAAC;KACtB,CAAC;IACF,UAAU,EAAE,sBAAsB,CAAC;IACnC,OAAO,CAAC,EAAE,gBAAgB,CAAC;CAC3B,CAAC;AAEF,oBAAY,gCAAgC,GAAG;IAC9C,GAAG,CAAC,EAAE,mBAAmB,CAAC;IAC1B,MAAM,CAAC,EAAE;QACR,OAAO,EAAE,aAAa,CAAC;QACvB,MAAM,CAAC,EAAE,YAAY,CAAC;KACtB,CAAC;IACF,UAAU,EAAE,4BAA4B,CAAC;IACzC,OAAO,CAAC,EAAE,gBAAgB,CAAC;CAC3B,CAAC;AAEF,oBAAY,0BAA0B,GAAG;IACxC,GAAG,CAAC,EAAE,mBAAmB,CAAC;IAC1B,MAAM,CAAC,EAAE;QACR,OAAO,EAAE,aAAa,CAAC;QACvB,MAAM,CAAC,EAAE,YAAY,CAAC;KACtB,CAAC;IACF,UAAU,EAAE,sBAAsB,CAAC;IACnC,OAAO,CAAC,EAAE,gBAAgB,CAAC;CAC3B,CAAC;AAEF,oBAAY,kCAAkC,GAAG;IAChD,GAAG,CAAC,EAAE,mBAAmB,CAAC;IAC1B,MAAM,CAAC,EAAE;QACR,OAAO,EAAE,aAAa,CAAC;QACvB,MAAM,CAAC,EAAE,YAAY,CAAC;KACtB,CAAC;IACF,UAAU,EAAE,8BAA8B,CAAC;IAC3C,OAAO,CAAC,EAAE,gBAAgB,CAAC;CAC3B,CAAC"}
|
|
@@ -3,7 +3,7 @@ import type { Logger } from '@searchspring/snap-logger';
|
|
|
3
3
|
import type { UrlTranslatorConfig } from '@searchspring/snap-url-manager';
|
|
4
4
|
import type { Client } from '@searchspring/snap-client';
|
|
5
5
|
import type { Tracker } from '@searchspring/snap-tracker';
|
|
6
|
-
import type { AbstractController, RecommendationController, Attachments } from '@searchspring/snap-controller';
|
|
6
|
+
import type { AbstractController, RecommendationController, Attachments, ContextVariables } from '@searchspring/snap-controller';
|
|
7
7
|
import type { Middleware } from '@searchspring/snap-event-manager';
|
|
8
8
|
import type { SnapControllerServices, RootComponent } from '../types';
|
|
9
9
|
export declare type RecommendationInstantiatorConfig = {
|
|
@@ -14,10 +14,12 @@ export declare type RecommendationInstantiatorConfig = {
|
|
|
14
14
|
branch: string;
|
|
15
15
|
realtime?: boolean;
|
|
16
16
|
batched?: boolean;
|
|
17
|
+
limit?: number;
|
|
17
18
|
} & Attachments;
|
|
18
19
|
selector?: string;
|
|
19
20
|
services?: SnapControllerServices;
|
|
20
21
|
url?: UrlTranslatorConfig;
|
|
22
|
+
context?: ContextVariables;
|
|
21
23
|
};
|
|
22
24
|
export declare type RecommendationInstantiatorServices = {
|
|
23
25
|
client: Client;
|
|
@@ -32,6 +34,7 @@ export declare class RecommendationInstantiator {
|
|
|
32
34
|
tracker: Tracker;
|
|
33
35
|
logger: Logger;
|
|
34
36
|
config: RecommendationInstantiatorConfig;
|
|
37
|
+
context: ContextVariables;
|
|
35
38
|
uses: Attachments[];
|
|
36
39
|
plugins: {
|
|
37
40
|
(cntrlr: AbstractController): Promise<void>;
|
|
@@ -41,7 +44,7 @@ export declare class RecommendationInstantiator {
|
|
|
41
44
|
func: Middleware<unknown>[];
|
|
42
45
|
}[];
|
|
43
46
|
targeter: DomTargeter;
|
|
44
|
-
constructor(config: RecommendationInstantiatorConfig, { client, logger, tracker }: RecommendationInstantiatorServices);
|
|
47
|
+
constructor(config: RecommendationInstantiatorConfig, { client, logger, tracker }: RecommendationInstantiatorServices, context?: ContextVariables);
|
|
45
48
|
plugin(func: (cntrlr: AbstractController) => Promise<void>): void;
|
|
46
49
|
on<T>(event: string, ...func: Middleware<T>[]): void;
|
|
47
50
|
use(attachments: Attachments): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RecommendationInstantiator.d.ts","sourceRoot":"","sources":["../../../src/Instantiators/RecommendationInstantiator.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"RecommendationInstantiator.d.ts","sourceRoot":"","sources":["../../../src/Instantiators/RecommendationInstantiator.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAc,MAAM,4BAA4B,CAAC;AAErE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjI,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,KAAK,EAAE,sBAAsB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEtE,oBAAY,gCAAgC,GAAG;IAC9C,UAAU,EAAE;QACX,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,OAAO,CAAC,aAAa,CAAC,GAAG,aAAa,CAAC;KAC7D,CAAC;IACF,MAAM,EAAE;QACP,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,KAAK,CAAC,EAAE,MAAM,CAAC;KACf,GAAG,WAAW,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,sBAAsB,CAAC;IAClC,GAAG,CAAC,EAAE,mBAAmB,CAAC;IAC1B,OAAO,CAAC,EAAE,gBAAgB,CAAC;CAC3B,CAAC;AAEF,oBAAY,kCAAkC,GAAG;IAChD,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,qBAAa,0BAA0B;IACtC,WAAW,EAAE;QACZ,CAAC,GAAG,EAAE,MAAM,GAAG,wBAAwB,CAAC;KACxC,CAAM;IACP,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,gCAAgC,CAAC;IACzC,OAAO,EAAE,gBAAgB,CAAC;IAC1B,IAAI,EAAE,WAAW,EAAE,CAAM;IACzB,OAAO,EAAE;QAAE,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;KAAE,EAAE,CAAM;IAChE,UAAU,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,CAAA;KAAE,EAAE,CAAM;IAC3D,QAAQ,EAAE,WAAW,CAAC;gBAEjB,MAAM,EAAE,gCAAgC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,kCAAkC,EAAE,OAAO,CAAC,EAAE,gBAAgB;IA2J1I,MAAM,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,kBAAkB,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI;IAIjE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI;IAIpD,GAAG,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI;CAG1C"}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { jsx as _jsx } from "preact/jsx-runtime";
|
|
2
2
|
import { render } from 'preact';
|
|
3
|
+
import deepmerge from 'deepmerge';
|
|
3
4
|
import { DomTargeter, getContext } from '@searchspring/snap-toolbox';
|
|
4
5
|
export class RecommendationInstantiator {
|
|
5
|
-
constructor(config, { client, logger, tracker }) {
|
|
6
|
+
constructor(config, { client, logger, tracker }, context) {
|
|
6
7
|
this.controllers = {};
|
|
7
8
|
this.uses = [];
|
|
8
9
|
this.plugins = [];
|
|
9
10
|
this.middleware = [];
|
|
10
11
|
this.config = config;
|
|
12
|
+
this.context = deepmerge(context || {}, config.context || {});
|
|
11
13
|
if (!this.config) {
|
|
12
14
|
throw new Error(`Recommendation Instantiator config is required`);
|
|
13
15
|
}
|
|
@@ -40,11 +42,15 @@ export class RecommendationInstantiator {
|
|
|
40
42
|
},
|
|
41
43
|
},
|
|
42
44
|
], async (target, injectedElem, elem) => {
|
|
43
|
-
const
|
|
44
|
-
const
|
|
45
|
+
const contextGlobals = {};
|
|
46
|
+
const elemContext = getContext(['shopperId', 'shopper', 'product', 'seed', 'options', 'profile', 'custom'], elem);
|
|
47
|
+
const context = deepmerge(this.context, elemContext);
|
|
48
|
+
const { shopper, shopperId, product, seed, options } = context;
|
|
45
49
|
/*
|
|
46
50
|
type instantiatorContext = {
|
|
47
|
-
shopper?:
|
|
51
|
+
shopper?: {
|
|
52
|
+
id: string;
|
|
53
|
+
};
|
|
48
54
|
shopperId?: string;
|
|
49
55
|
product?: string;
|
|
50
56
|
seed?: string;
|
|
@@ -54,33 +60,41 @@ export class RecommendationInstantiator {
|
|
|
54
60
|
batched?: boolean;
|
|
55
61
|
realtime?: boolean;
|
|
56
62
|
categories?: any;
|
|
63
|
+
limit?: number;
|
|
57
64
|
}
|
|
58
65
|
}
|
|
59
66
|
*/
|
|
60
67
|
if (shopper || shopperId) {
|
|
61
|
-
|
|
68
|
+
contextGlobals.shopper = shopper?.id || shopperId;
|
|
62
69
|
}
|
|
63
70
|
if (product || seed) {
|
|
64
|
-
|
|
71
|
+
contextGlobals.product = product || seed;
|
|
65
72
|
}
|
|
66
73
|
if (options?.branch) {
|
|
67
|
-
|
|
74
|
+
contextGlobals.branch = options.branch;
|
|
68
75
|
}
|
|
69
76
|
if (options?.siteId) {
|
|
70
|
-
|
|
77
|
+
contextGlobals.siteId = options.siteId;
|
|
71
78
|
}
|
|
72
79
|
if (options?.categories) {
|
|
73
|
-
|
|
80
|
+
contextGlobals.categories = options.categories;
|
|
81
|
+
}
|
|
82
|
+
if (options?.limit && Number.isInteger(Number(options?.limit))) {
|
|
83
|
+
contextGlobals.limits = Number(options?.limit);
|
|
74
84
|
}
|
|
75
85
|
const tag = injectedElem.getAttribute('searchspring-recommend');
|
|
76
86
|
profileCount[tag] = profileCount[tag] + 1 || 1;
|
|
87
|
+
const defaultGlobals = {
|
|
88
|
+
limits: 20,
|
|
89
|
+
};
|
|
90
|
+
const globals = deepmerge(deepmerge(defaultGlobals, this.config.config?.globals || {}), contextGlobals);
|
|
77
91
|
const controllerConfig = {
|
|
78
92
|
id: `recommend_${tag + (profileCount[tag] - 1)}`,
|
|
79
93
|
tag,
|
|
80
94
|
batched: options?.batched ?? true,
|
|
81
95
|
realtime: Boolean(options?.realtime),
|
|
82
|
-
globals,
|
|
83
96
|
...this.config.config,
|
|
97
|
+
globals,
|
|
84
98
|
};
|
|
85
99
|
const createRecommendationController = (await import('../create/createRecommendationController')).default;
|
|
86
100
|
const client = this.config.services?.client || this.client;
|
|
@@ -88,6 +102,7 @@ export class RecommendationInstantiator {
|
|
|
88
102
|
const recs = createRecommendationController({
|
|
89
103
|
url: this.config.url || {},
|
|
90
104
|
controller: controllerConfig,
|
|
105
|
+
context,
|
|
91
106
|
}, { client, tracker });
|
|
92
107
|
this.uses.forEach((attachements) => recs.use(attachements));
|
|
93
108
|
this.plugins.forEach((plugin) => recs.plugin(plugin));
|
package/dist/esm/Snap.d.ts
CHANGED
|
@@ -2,8 +2,7 @@ import { Client } from '@searchspring/snap-client';
|
|
|
2
2
|
import { Logger } from '@searchspring/snap-logger';
|
|
3
3
|
import { Tracker } from '@searchspring/snap-tracker';
|
|
4
4
|
import type { ClientConfig, ClientGlobals } from '@searchspring/snap-client';
|
|
5
|
-
import type { AbstractController, SearchController, AutocompleteController, FinderController, RecommendationController, SearchControllerConfig, AutocompleteControllerConfig, FinderControllerConfig, RecommendationControllerConfig, ControllerConfigs } from '@searchspring/snap-controller';
|
|
6
|
-
import type { Product } from '@searchspring/snap-tracker';
|
|
5
|
+
import type { AbstractController, SearchController, AutocompleteController, FinderController, RecommendationController, SearchControllerConfig, AutocompleteControllerConfig, FinderControllerConfig, RecommendationControllerConfig, ControllerConfigs, ContextVariables } from '@searchspring/snap-controller';
|
|
7
6
|
import type { Target, OnTarget } from '@searchspring/snap-toolbox';
|
|
8
7
|
import type { UrlTranslatorConfig } from '@searchspring/snap-url-manager';
|
|
9
8
|
import { RecommendationInstantiator, RecommendationInstantiatorConfig } from './Instantiators/RecommendationInstantiator';
|
|
@@ -17,14 +16,6 @@ declare type ExtendedTarget = Target & {
|
|
|
17
16
|
onTarget?: OnTarget;
|
|
18
17
|
prefetch?: boolean;
|
|
19
18
|
};
|
|
20
|
-
declare type ContextVariables = {
|
|
21
|
-
shopper?: {
|
|
22
|
-
id: string;
|
|
23
|
-
cart?: Product[];
|
|
24
|
-
[variable: string]: any;
|
|
25
|
-
};
|
|
26
|
-
[variable: string]: any;
|
|
27
|
-
};
|
|
28
19
|
export declare type SnapConfig = {
|
|
29
20
|
context?: ContextVariables;
|
|
30
21
|
url?: UrlTranslatorConfig;
|
|
@@ -41,24 +32,28 @@ export declare type SnapConfig = {
|
|
|
41
32
|
targeters?: ExtendedTarget[];
|
|
42
33
|
services?: SnapControllerServices;
|
|
43
34
|
url?: UrlTranslatorConfig;
|
|
35
|
+
context?: ContextVariables;
|
|
44
36
|
}[];
|
|
45
37
|
autocomplete?: {
|
|
46
38
|
config: AutocompleteControllerConfig;
|
|
47
39
|
targeters: ExtendedTarget[];
|
|
48
40
|
services?: SnapControllerServices;
|
|
49
41
|
url?: UrlTranslatorConfig;
|
|
42
|
+
context?: ContextVariables;
|
|
50
43
|
}[];
|
|
51
44
|
finder?: {
|
|
52
45
|
config: FinderControllerConfig;
|
|
53
46
|
targeters?: ExtendedTarget[];
|
|
54
47
|
services?: SnapControllerServices;
|
|
55
48
|
url?: UrlTranslatorConfig;
|
|
49
|
+
context?: ContextVariables;
|
|
56
50
|
}[];
|
|
57
51
|
recommendation?: {
|
|
58
52
|
config: RecommendationControllerConfig;
|
|
59
53
|
targeters?: ExtendedTarget[];
|
|
60
54
|
services?: SnapControllerServices;
|
|
61
55
|
url?: UrlTranslatorConfig;
|
|
56
|
+
context?: ContextVariables;
|
|
62
57
|
}[];
|
|
63
58
|
};
|
|
64
59
|
};
|
|
@@ -74,6 +69,7 @@ export declare class Snap {
|
|
|
74
69
|
logger: Logger;
|
|
75
70
|
client: Client;
|
|
76
71
|
tracker: Tracker;
|
|
72
|
+
context: ContextVariables;
|
|
77
73
|
_controllerPromises: {
|
|
78
74
|
[controllerConfigId: string]: Promise<ControllerTypes>;
|
|
79
75
|
};
|
|
@@ -86,7 +82,7 @@ export declare class Snap {
|
|
|
86
82
|
getInstantiator: (id: string) => Promise<RecommendationInstantiator>;
|
|
87
83
|
getController: (id: string) => Promise<ControllerTypes>;
|
|
88
84
|
getControllers: (...controllerIds: string[]) => Promise<ControllerTypes[]>;
|
|
89
|
-
createController: (type: DynamicImportNames, config: ControllerConfigs, services: SnapControllerServices, urlConfig: UrlTranslatorConfig, resolve: (value?: ControllerTypes | PromiseLike<ControllerTypes>) => void) => Promise<ControllerTypes>;
|
|
85
|
+
createController: (type: DynamicImportNames, config: ControllerConfigs, services: SnapControllerServices, urlConfig: UrlTranslatorConfig, resolve: (value?: ControllerTypes | PromiseLike<ControllerTypes>) => void, context?: ContextVariables) => Promise<ControllerTypes>;
|
|
90
86
|
constructor(config: SnapConfig);
|
|
91
87
|
}
|
|
92
88
|
export {};
|
package/dist/esm/Snap.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Snap.d.ts","sourceRoot":"","sources":["../../src/Snap.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,C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CAAC;SAC3B,EAAE,CAAC;KACJ,CAAC;CACF,CAAC;AAEF,aAAK,eAAe,GAAG,gBAAgB,GAAG,sBAAsB,GAAG,gBAAgB,GAAG,wBAAwB,CAAC;AAC/G,aAAK,kBAAkB;IACtB,MAAM,qBAAqB;IAC3B,YAAY,2BAA2B;IACvC,MAAM,qBAAqB;IAC3B,cAAc,6BAA6B;CAC3C;AAED,qBAAa,IAAI;IAChB,MAAM,EAAE,UAAU,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,gBAAgB,CAAC;IAC1B,mBAAmB,EAAE;QACpB,CAAC,kBAAkB,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;KACvD,CAAC;IAEF,WAAW,EAAE;QACZ,CAAC,kBAAkB,EAAE,MAAM,GAAG,eAAe,CAAC;KAC9C,CAAC;IAEF,qBAAqB,EAAE;QACtB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAC;KAC9D,CAAC;IAEK,eAAe,OAAQ,MAAM,KAAG,QAAQ,0BAA0B,CAAC,CAExE;IAEK,aAAa,OAAQ,MAAM,KAAG,QAAQ,eAAe,CAAC,CAE3D;IAEK,cAAc,qBAAsB,MAAM,EAAE,KAAG,QAAQ,eAAe,EAAE,CAAC,CAI9E;IAEK,gBAAgB,SAChB,kBAAkB,UAChB,iBAAiB,YACf,sBAAsB,aACrB,mBAAmB,oBACZ,eAAe,GAAG,YAAY,eAAe,CAAC,KAAK,IAAI,YAC/D,gBAAgB,KACxB,QAAQ,eAAe,CAAC,CAgCzB;gBAEU,MAAM,EAAE,UAAU;CAyb9B"}
|
package/dist/esm/Snap.js
CHANGED
|
@@ -5,6 +5,7 @@ import { Client } from '@searchspring/snap-client';
|
|
|
5
5
|
import { Logger, LogMode } from '@searchspring/snap-logger';
|
|
6
6
|
import { Tracker } from '@searchspring/snap-tracker';
|
|
7
7
|
import { version, DomTargeter, url, cookies, featureFlags } from '@searchspring/snap-toolbox';
|
|
8
|
+
import { getContext } from '@searchspring/snap-toolbox';
|
|
8
9
|
import { default as createSearchController } from './create/createSearchController';
|
|
9
10
|
const BRANCH_COOKIE = 'ssBranch';
|
|
10
11
|
const SS_DEV_COOKIE = 'ssDev';
|
|
@@ -28,7 +29,7 @@ export class Snap {
|
|
|
28
29
|
controllerIds.forEach((id) => getControllerPromises.push(this.getController(id)));
|
|
29
30
|
return Promise.all(getControllerPromises);
|
|
30
31
|
};
|
|
31
|
-
this.createController = (type, config, services, urlConfig, resolve) => {
|
|
32
|
+
this.createController = (type, config, services, urlConfig, resolve, context) => {
|
|
32
33
|
let importPromise;
|
|
33
34
|
switch (type) {
|
|
34
35
|
case DynamicImportNames.SEARCH:
|
|
@@ -49,6 +50,7 @@ export class Snap {
|
|
|
49
50
|
this.controllers[config.id] = _.default({
|
|
50
51
|
url: deepmerge(this.config.url || {}, urlConfig || {}),
|
|
51
52
|
controller: config,
|
|
53
|
+
context: deepmerge(this.context || {}, context || {}),
|
|
52
54
|
}, { client: services?.client || this.client, tracker: services?.tracker || this.tracker });
|
|
53
55
|
resolve(this.controllers[config.id]);
|
|
54
56
|
}
|
|
@@ -57,6 +59,16 @@ export class Snap {
|
|
|
57
59
|
};
|
|
58
60
|
this.config = config;
|
|
59
61
|
this.logger = new Logger('Snap Preact ');
|
|
62
|
+
let globalContext = {};
|
|
63
|
+
try {
|
|
64
|
+
// get global context
|
|
65
|
+
globalContext = getContext(['shopper', 'config']);
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
this.logger.error('failed to find global context');
|
|
69
|
+
}
|
|
70
|
+
this.config = deepmerge(this.config || {}, globalContext.config || {});
|
|
71
|
+
this.context = deepmerge(globalContext || {}, this.config.context || {});
|
|
60
72
|
if (!this.config?.client?.globals?.siteId) {
|
|
61
73
|
throw new Error(`Snap: config provided must contain a valid config.client.globals.siteId value`);
|
|
62
74
|
}
|
|
@@ -115,20 +127,19 @@ export class Snap {
|
|
|
115
127
|
}
|
|
116
128
|
catch (e) { }
|
|
117
129
|
if (window.searchspring) {
|
|
118
|
-
|
|
119
|
-
window.searchspring.context = this.config.context;
|
|
130
|
+
window.searchspring.context = this.context;
|
|
120
131
|
if (this.client)
|
|
121
132
|
window.searchspring.client = this.client;
|
|
122
133
|
}
|
|
123
134
|
// autotrack shopper id from the context
|
|
124
|
-
if (this.
|
|
135
|
+
if (this.context?.shopper?.id) {
|
|
125
136
|
this.tracker.track.shopper.login({
|
|
126
|
-
id: this.
|
|
137
|
+
id: this.context.shopper.id,
|
|
127
138
|
});
|
|
128
139
|
}
|
|
129
140
|
// auto populate cart cookie from the context
|
|
130
|
-
if (this.
|
|
131
|
-
const cart = this.
|
|
141
|
+
if (this.context?.shopper?.cart) {
|
|
142
|
+
const cart = this.context.shopper.cart;
|
|
132
143
|
if (Array.isArray(cart)) {
|
|
133
144
|
const cartItems = cart.filter((item) => item?.sku || item?.childSku).map((item) => (item?.sku || item?.childSku).trim());
|
|
134
145
|
this.tracker.cookies.cart.set(cartItems);
|
|
@@ -142,6 +153,7 @@ export class Snap {
|
|
|
142
153
|
const cntrlr = createSearchController({
|
|
143
154
|
url: deepmerge(this.config.url || {}, controller.url || {}),
|
|
144
155
|
controller: controller.config,
|
|
156
|
+
context: deepmerge(this.context || {}, controller.context || {}),
|
|
145
157
|
}, { client: controller.services?.client || this.client, tracker: controller.services?.tracker || this.tracker });
|
|
146
158
|
this.controllers[cntrlr.config.id] = cntrlr;
|
|
147
159
|
this._controllerPromises[cntrlr.config.id] = new Promise((resolve) => resolve(cntrlr));
|
|
@@ -249,7 +261,7 @@ The error above happened in the following targeter in the Snap Config`, target);
|
|
|
249
261
|
});
|
|
250
262
|
};
|
|
251
263
|
if (!controller?.targeters || controller?.targeters.length === 0) {
|
|
252
|
-
this.createController(DynamicImportNames.AUTOCOMPLETE, controller.config, controller.services, controller.url, resolve);
|
|
264
|
+
this.createController(DynamicImportNames.AUTOCOMPLETE, controller.config, controller.services, controller.url, resolve, controller.context);
|
|
253
265
|
}
|
|
254
266
|
controller?.targeters?.forEach(async (target, target_index) => {
|
|
255
267
|
if (!target.selector) {
|
|
@@ -274,7 +286,7 @@ The error above happened in the following targeter in the Snap Config`, target);
|
|
|
274
286
|
...target,
|
|
275
287
|
},
|
|
276
288
|
], async (target, elem, originalElem) => {
|
|
277
|
-
const cntrlr = await this.createController(DynamicImportNames.AUTOCOMPLETE, controller.config, controller.services, controller.url, resolve);
|
|
289
|
+
const cntrlr = await this.createController(DynamicImportNames.AUTOCOMPLETE, controller.config, controller.services, controller.url, resolve, controller.context);
|
|
278
290
|
runBind();
|
|
279
291
|
targetFunction({ controller: cntrlr, ...target }, elem, originalElem);
|
|
280
292
|
cntrlr.addTargeter(targeter);
|
|
@@ -308,7 +320,7 @@ The error above happened in the following targeter in the Snap Config`, target);
|
|
|
308
320
|
});
|
|
309
321
|
};
|
|
310
322
|
if (!controller?.targeters || controller?.targeters.length === 0) {
|
|
311
|
-
this.createController(DynamicImportNames.FINDER, controller.config, controller.services, controller.url, resolve);
|
|
323
|
+
this.createController(DynamicImportNames.FINDER, controller.config, controller.services, controller.url, resolve, controller.context);
|
|
312
324
|
}
|
|
313
325
|
controller?.targeters?.forEach(async (target, target_index) => {
|
|
314
326
|
if (!target.selector) {
|
|
@@ -318,7 +330,7 @@ The error above happened in the following targeter in the Snap Config`, target);
|
|
|
318
330
|
throw new Error(`Targets at index ${target_index} missing component value (Component).`);
|
|
319
331
|
}
|
|
320
332
|
const targeter = new DomTargeter([{ ...target }], async (target, elem, originalElem) => {
|
|
321
|
-
const cntrlr = await this.createController(DynamicImportNames.FINDER, controller.config, controller.services, controller.url, resolve);
|
|
333
|
+
const cntrlr = await this.createController(DynamicImportNames.FINDER, controller.config, controller.services, controller.url, resolve, controller.context);
|
|
322
334
|
runSearch();
|
|
323
335
|
targetFunction({ controller: cntrlr, ...target }, elem, originalElem);
|
|
324
336
|
cntrlr.addTargeter(targeter);
|
|
@@ -352,7 +364,7 @@ The error above happened in the following targeter in the Snap Config`, target);
|
|
|
352
364
|
});
|
|
353
365
|
};
|
|
354
366
|
if (!controller?.targeters || controller?.targeters.length === 0) {
|
|
355
|
-
this.createController(DynamicImportNames.RECOMMENDATION, controller.config, controller.services, controller.url, resolve);
|
|
367
|
+
this.createController(DynamicImportNames.RECOMMENDATION, controller.config, controller.services, controller.url, resolve, controller.context);
|
|
356
368
|
}
|
|
357
369
|
controller?.targeters?.forEach(async (target, target_index) => {
|
|
358
370
|
if (!target.selector) {
|
|
@@ -362,7 +374,7 @@ The error above happened in the following targeter in the Snap Config`, target);
|
|
|
362
374
|
throw new Error(`Targets at index ${target_index} missing component value (Component).`);
|
|
363
375
|
}
|
|
364
376
|
const targeter = new DomTargeter([{ ...target }], async (target, elem, originalElem) => {
|
|
365
|
-
const cntrlr = await this.createController(DynamicImportNames.RECOMMENDATION, controller.config, controller.services, controller.url, resolve);
|
|
377
|
+
const cntrlr = await this.createController(DynamicImportNames.RECOMMENDATION, controller.config, controller.services, controller.url, resolve, controller.context);
|
|
366
378
|
runSearch();
|
|
367
379
|
targetFunction({ controller: cntrlr, ...target }, elem, originalElem);
|
|
368
380
|
cntrlr.addTargeter(targeter);
|
|
@@ -378,14 +390,14 @@ The error above happened in the following targeter in the Snap Config`, target);
|
|
|
378
390
|
}
|
|
379
391
|
}
|
|
380
392
|
});
|
|
381
|
-
if (config?.instantiators?.recommendation) {
|
|
393
|
+
if (this.config?.instantiators?.recommendation) {
|
|
382
394
|
try {
|
|
383
395
|
this._instantiatorPromises.recommendations = import('./Instantiators/RecommendationInstantiator').then(({ RecommendationInstantiator }) => {
|
|
384
|
-
return new RecommendationInstantiator(config.instantiators.recommendation, {
|
|
385
|
-
client: config.instantiators.recommendation?.services?.client || this.client,
|
|
386
|
-
tracker: config.instantiators.recommendation?.services?.tracker || this.tracker,
|
|
387
|
-
logger: config.instantiators.recommendation?.services?.logger || this.logger,
|
|
388
|
-
});
|
|
396
|
+
return new RecommendationInstantiator(this.config.instantiators.recommendation, {
|
|
397
|
+
client: this.config.instantiators.recommendation?.services?.client || this.client,
|
|
398
|
+
tracker: this.config.instantiators.recommendation?.services?.tracker || this.tracker,
|
|
399
|
+
logger: this.config.instantiators.recommendation?.services?.logger || this.logger,
|
|
400
|
+
}, this.context);
|
|
389
401
|
});
|
|
390
402
|
}
|
|
391
403
|
catch (err) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createAutocompleteController.d.ts","sourceRoot":"","sources":["../../../src/create/createAutocompleteController.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AASvE,OAAO,KAAK,EAAE,sBAAsB,EAAE,gCAAgC,EAAE,MAAM,UAAU,CAAC;iCAIjE,gCAAgC,aAAa,sBAAsB,KAAG,sBAAsB;AAApH,
|
|
1
|
+
{"version":3,"file":"createAutocompleteController.d.ts","sourceRoot":"","sources":["../../../src/create/createAutocompleteController.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AASvE,OAAO,KAAK,EAAE,sBAAsB,EAAE,gCAAgC,EAAE,MAAM,UAAU,CAAC;iCAIjE,gCAAgC,aAAa,sBAAsB,KAAG,sBAAsB;AAApH,wBAkBE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createFinderController.d.ts","sourceRoot":"","sources":["../../../src/create/createFinderController.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AASjE,OAAO,KAAK,EAAE,sBAAsB,EAAE,0BAA0B,EAAE,MAAM,UAAU,CAAC;iCAI3D,0BAA0B,aAAa,sBAAsB,KAAG,gBAAgB;AAAxG,
|
|
1
|
+
{"version":3,"file":"createFinderController.d.ts","sourceRoot":"","sources":["../../../src/create/createFinderController.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AASjE,OAAO,KAAK,EAAE,sBAAsB,EAAE,0BAA0B,EAAE,MAAM,UAAU,CAAC;iCAI3D,0BAA0B,aAAa,sBAAsB,KAAG,gBAAgB;AAAxG,wBAkBE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRecommendationController.d.ts","sourceRoot":"","sources":["../../../src/create/createRecommendationController.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AASzE,OAAO,KAAK,EAAE,sBAAsB,EAAE,kCAAkC,EAAE,MAAM,UAAU,CAAC;iCAInE,kCAAkC,aAAa,sBAAsB,KAAG,wBAAwB;AAAxH,
|
|
1
|
+
{"version":3,"file":"createRecommendationController.d.ts","sourceRoot":"","sources":["../../../src/create/createRecommendationController.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AASzE,OAAO,KAAK,EAAE,sBAAsB,EAAE,kCAAkC,EAAE,MAAM,UAAU,CAAC;iCAInE,kCAAkC,aAAa,sBAAsB,KAAG,wBAAwB;AAAxH,wBAiBE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createSearchController.d.ts","sourceRoot":"","sources":["../../../src/create/createSearchController.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAQjE,OAAO,KAAK,EAAE,sBAAsB,EAAE,0BAA0B,EAAE,MAAM,UAAU,CAAC;iCAI3D,0BAA0B,aAAa,sBAAsB,KAAG,gBAAgB;AAAxG,
|
|
1
|
+
{"version":3,"file":"createSearchController.d.ts","sourceRoot":"","sources":["../../../src/create/createSearchController.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAQjE,OAAO,KAAK,EAAE,sBAAsB,EAAE,0BAA0B,EAAE,MAAM,UAAU,CAAC;iCAI3D,0BAA0B,aAAa,sBAAsB,KAAG,gBAAgB;AAAxG,wBAkBE"}
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { Client, ClientConfig, ClientGlobals } from '@searchspring/snap-client';
|
|
3
|
-
import type { AbstractController, SearchControllerConfig, AutocompleteControllerConfig, FinderControllerConfig, RecommendationControllerConfig } from '@searchspring/snap-controller';
|
|
3
|
+
import type { AbstractController, SearchControllerConfig, AutocompleteControllerConfig, FinderControllerConfig, RecommendationControllerConfig, ContextVariables } from '@searchspring/snap-controller';
|
|
4
4
|
import type { AbstractStore } from '@searchspring/snap-store-mobx';
|
|
5
5
|
import type { UrlManager, UrlTranslatorConfig } from '@searchspring/snap-url-manager';
|
|
6
6
|
import type { EventManager } from '@searchspring/snap-event-manager';
|
|
@@ -26,6 +26,7 @@ export declare type SnapSearchControllerConfig = {
|
|
|
26
26
|
config?: ClientConfig;
|
|
27
27
|
};
|
|
28
28
|
controller: SearchControllerConfig;
|
|
29
|
+
context?: ContextVariables;
|
|
29
30
|
};
|
|
30
31
|
export declare type SnapAutocompleteControllerConfig = {
|
|
31
32
|
url?: UrlTranslatorConfig;
|
|
@@ -34,6 +35,7 @@ export declare type SnapAutocompleteControllerConfig = {
|
|
|
34
35
|
config?: ClientConfig;
|
|
35
36
|
};
|
|
36
37
|
controller: AutocompleteControllerConfig;
|
|
38
|
+
context?: ContextVariables;
|
|
37
39
|
};
|
|
38
40
|
export declare type SnapFinderControllerConfig = {
|
|
39
41
|
url?: UrlTranslatorConfig;
|
|
@@ -42,6 +44,7 @@ export declare type SnapFinderControllerConfig = {
|
|
|
42
44
|
config?: ClientConfig;
|
|
43
45
|
};
|
|
44
46
|
controller: FinderControllerConfig;
|
|
47
|
+
context?: ContextVariables;
|
|
45
48
|
};
|
|
46
49
|
export declare type SnapRecommendationControllerConfig = {
|
|
47
50
|
url?: UrlTranslatorConfig;
|
|
@@ -50,5 +53,6 @@ export declare type SnapRecommendationControllerConfig = {
|
|
|
50
53
|
config?: ClientConfig;
|
|
51
54
|
};
|
|
52
55
|
controller: RecommendationControllerConfig;
|
|
56
|
+
context?: ContextVariables;
|
|
53
57
|
};
|
|
54
58
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/esm/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AACrF,OAAO,KAAK,EACX,kBAAkB,EAClB,sBAAsB,EACtB,4BAA4B,EAC5B,sBAAsB,EACtB,8BAA8B,EAC9B,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,KAAK,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACtF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAE1D,oBAAY,sBAAsB,GAAG;IACpC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,oBAAY,aAAa,GAAG,KAAK,CAAC,W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snap Preact",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -20,15 +20,15 @@
|
|
|
20
20
|
"test:watch": "jest --watch"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@searchspring/snap-client": "^0.
|
|
24
|
-
"@searchspring/snap-controller": "^0.
|
|
25
|
-
"@searchspring/snap-event-manager": "^0.
|
|
26
|
-
"@searchspring/snap-logger": "^0.
|
|
27
|
-
"@searchspring/snap-profiler": "^0.
|
|
28
|
-
"@searchspring/snap-store-mobx": "^0.
|
|
29
|
-
"@searchspring/snap-toolbox": "^0.
|
|
30
|
-
"@searchspring/snap-tracker": "^0.
|
|
31
|
-
"@searchspring/snap-url-manager": "^0.
|
|
23
|
+
"@searchspring/snap-client": "^0.21.1",
|
|
24
|
+
"@searchspring/snap-controller": "^0.21.1",
|
|
25
|
+
"@searchspring/snap-event-manager": "^0.21.1",
|
|
26
|
+
"@searchspring/snap-logger": "^0.21.1",
|
|
27
|
+
"@searchspring/snap-profiler": "^0.21.1",
|
|
28
|
+
"@searchspring/snap-store-mobx": "^0.21.1",
|
|
29
|
+
"@searchspring/snap-toolbox": "^0.21.1",
|
|
30
|
+
"@searchspring/snap-tracker": "^0.21.1",
|
|
31
|
+
"@searchspring/snap-url-manager": "^0.21.1",
|
|
32
32
|
"deepmerge": "^4.2.2",
|
|
33
33
|
"intersection-observer": "^0.12.0"
|
|
34
34
|
},
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"files": [
|
|
40
40
|
"dist/**/*"
|
|
41
41
|
],
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "e54d2d21a811b65b0e766d2dc0fd5b0f6da6053e"
|
|
43
43
|
}
|