@searchspring/snap-preact 0.29.0 → 0.30.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/Instantiators/RecommendationInstantiator.d.ts +4 -3
- package/dist/cjs/Instantiators/RecommendationInstantiator.d.ts.map +1 -1
- package/dist/cjs/Instantiators/RecommendationInstantiator.js +13 -2
- package/dist/cjs/Snap.d.ts +64 -13
- package/dist/cjs/Snap.d.ts.map +1 -1
- package/dist/cjs/Snap.js +159 -65
- package/dist/cjs/create/createAutocompleteController.d.ts +1 -1
- package/dist/cjs/create/createAutocompleteController.d.ts.map +1 -1
- package/dist/cjs/create/createAutocompleteController.js +6 -1
- package/dist/cjs/create/createFinderController.d.ts +1 -1
- package/dist/cjs/create/createFinderController.d.ts.map +1 -1
- package/dist/cjs/create/createFinderController.js +6 -1
- package/dist/cjs/create/createRecommendationController.d.ts +1 -1
- package/dist/cjs/create/createRecommendationController.d.ts.map +1 -1
- package/dist/cjs/create/createRecommendationController.js +6 -1
- package/dist/cjs/create/createSearchController.d.ts +1 -1
- package/dist/cjs/create/createSearchController.d.ts.map +1 -1
- package/dist/cjs/create/createSearchController.js +6 -1
- package/dist/cjs/types.d.ts +6 -5
- package/dist/cjs/types.d.ts.map +1 -1
- package/dist/esm/Instantiators/RecommendationInstantiator.d.ts +4 -3
- package/dist/esm/Instantiators/RecommendationInstantiator.d.ts.map +1 -1
- package/dist/esm/Instantiators/RecommendationInstantiator.js +15 -3
- package/dist/esm/Snap.d.ts +14 -12
- package/dist/esm/Snap.d.ts.map +1 -1
- package/dist/esm/Snap.js +129 -52
- package/dist/esm/create/createAutocompleteController.d.ts.map +1 -1
- package/dist/esm/create/createAutocompleteController.js +6 -1
- package/dist/esm/create/createFinderController.d.ts.map +1 -1
- package/dist/esm/create/createFinderController.js +6 -1
- package/dist/esm/create/createRecommendationController.d.ts.map +1 -1
- package/dist/esm/create/createRecommendationController.js +6 -1
- package/dist/esm/create/createSearchController.d.ts.map +1 -1
- package/dist/esm/create/createSearchController.js +6 -1
- package/dist/esm/types.d.ts +6 -5
- package/dist/esm/types.d.ts.map +1 -1
- package/package.json +13 -13
package/dist/cjs/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"
|
|
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,EAEX,sBAAsB,EACtB,4BAA4B,EAC5B,sBAAsB,EACtB,8BAA8B,EAC9B,gBAAgB,EAChB,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACtH,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;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAErD,oBAAY,sBAAsB,GAAG;IACpC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,WAAW,GAAG,iBAAiB,GAAG,WAAW,GAAG,mBAAmB,CAAC;IAC5E,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,MAAM,CAA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M,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;AAEF,OAAO,CAAC,MAAM,CAAC;IACd,UAAU,MAAM;QACf,YAAY,CAAC,EAAE,GAAG,CAAC;KACnB;CACD"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DomTargeter } from '@searchspring/snap-toolbox';
|
|
1
|
+
import { AppMode, DomTargeter } from '@searchspring/snap-toolbox';
|
|
2
2
|
import { Client } from '@searchspring/snap-client';
|
|
3
3
|
import { Logger } from '@searchspring/snap-logger';
|
|
4
4
|
import { Tracker } from '@searchspring/snap-tracker';
|
|
@@ -6,14 +6,14 @@ import type { ClientConfig, ClientGlobals } from '@searchspring/snap-client';
|
|
|
6
6
|
import type { UrlTranslatorConfig } from '@searchspring/snap-url-manager';
|
|
7
7
|
import type { AbstractController, RecommendationController, Attachments, ContextVariables } from '@searchspring/snap-controller';
|
|
8
8
|
import type { Middleware } from '@searchspring/snap-event-manager';
|
|
9
|
-
import type { RootComponent } from '../types';
|
|
10
9
|
export declare type RecommendationInstantiatorConfig = {
|
|
10
|
+
mode?: keyof typeof AppMode | AppMode;
|
|
11
11
|
client?: {
|
|
12
12
|
globals: ClientGlobals;
|
|
13
13
|
config?: ClientConfig;
|
|
14
14
|
};
|
|
15
15
|
components: {
|
|
16
|
-
[name: string]: () => Promise<
|
|
16
|
+
[name: string]: () => Promise<any> | any;
|
|
17
17
|
};
|
|
18
18
|
config: {
|
|
19
19
|
branch: string;
|
|
@@ -31,6 +31,7 @@ export declare type RecommendationInstantiatorServices = {
|
|
|
31
31
|
tracker?: Tracker;
|
|
32
32
|
};
|
|
33
33
|
export declare class RecommendationInstantiator {
|
|
34
|
+
private mode;
|
|
34
35
|
client: Client;
|
|
35
36
|
tracker: Tracker;
|
|
36
37
|
logger: Logger;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RecommendationInstantiator.d.ts","sourceRoot":"","sources":["../../../src/Instantiators/RecommendationInstantiator.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAc,MAAM,4BAA4B,CAAC;
|
|
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;AAGrD,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC7E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,KAAK,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjI,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAGnE,oBAAY,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,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;KACzC,CAAC;IACF,MAAM,EAAE;QACP,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,KAAK,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jsx-runtime";
|
|
2
2
|
import { render } from 'preact';
|
|
3
3
|
import deepmerge from 'deepmerge';
|
|
4
|
-
import { DomTargeter, getContext } from '@searchspring/snap-toolbox';
|
|
4
|
+
import { AppMode, DomTargeter, getContext } from '@searchspring/snap-toolbox';
|
|
5
5
|
import { Client } from '@searchspring/snap-client';
|
|
6
6
|
import { Logger } from '@searchspring/snap-logger';
|
|
7
7
|
import { Tracker } from '@searchspring/snap-tracker';
|
|
8
8
|
export class RecommendationInstantiator {
|
|
9
9
|
constructor(config, services, context) {
|
|
10
|
+
this.mode = AppMode.production;
|
|
10
11
|
this.controller = {};
|
|
11
12
|
this.uses = [];
|
|
12
13
|
this.plugins = [];
|
|
@@ -24,10 +25,18 @@ export class RecommendationInstantiator {
|
|
|
24
25
|
if ((!services?.client || !services?.tracker) && !this.config?.client?.globals?.siteId) {
|
|
25
26
|
throw new Error(`Recommendation Instantiator config must contain a valid config.client.globals.siteId value`);
|
|
26
27
|
}
|
|
28
|
+
if (this.config.mode && Object.values(AppMode).includes(this.config.mode)) {
|
|
29
|
+
this.mode = this.config.mode;
|
|
30
|
+
if (this.config?.client?.globals?.siteId) {
|
|
31
|
+
this.config.client.config = this.config.client.config || {};
|
|
32
|
+
this.config.client.config.mode = this.config.client.config.mode || this.mode;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
window.searchspring = window.searchspring || {};
|
|
27
36
|
this.context = deepmerge(context || {}, config.context || {});
|
|
28
37
|
this.client = services?.client || new Client(this.config.client.globals, this.config.client.config);
|
|
29
38
|
this.tracker = services?.tracker || new Tracker(this.config.client.globals);
|
|
30
|
-
this.logger = services?.logger || new Logger('RecommendationInstantiator ');
|
|
39
|
+
this.logger = services?.logger || new Logger({ prefix: 'RecommendationInstantiator ', mode: this.mode });
|
|
31
40
|
const profileCount = {};
|
|
32
41
|
this.targeter = new DomTargeter([
|
|
33
42
|
{
|
|
@@ -134,6 +143,8 @@ export class RecommendationInstantiator {
|
|
|
134
143
|
await controller.search();
|
|
135
144
|
controller.addTargeter(this.targeter);
|
|
136
145
|
this.controller[controller.config.id] = controller;
|
|
146
|
+
window.searchspring.controller = window.searchspring.controller || {};
|
|
147
|
+
window.searchspring.controller[controller.config.id] = controller;
|
|
137
148
|
const profileVars = controller.store.profile.display.templateParameters;
|
|
138
149
|
const component = controller.store.profile.display.template?.component;
|
|
139
150
|
if (!profileVars) {
|
|
@@ -144,7 +155,8 @@ export class RecommendationInstantiator {
|
|
|
144
155
|
this.logger.error(`profile '${tag}' found on ${elem} is missing component!`);
|
|
145
156
|
return;
|
|
146
157
|
}
|
|
147
|
-
const RecommendationsComponent = this.config.components[component] &&
|
|
158
|
+
const RecommendationsComponent = this.config.components[component] &&
|
|
159
|
+
(await this.config.components[component]());
|
|
148
160
|
if (!RecommendationsComponent) {
|
|
149
161
|
this.logger.error(`profile '${tag}' found on ${elem} is expecting component mapping for '${component}' - verify instantiator config.`);
|
|
150
162
|
return;
|
package/dist/esm/Snap.d.ts
CHANGED
|
@@ -1,25 +1,29 @@
|
|
|
1
1
|
import { Client } from '@searchspring/snap-client';
|
|
2
2
|
import { Logger } from '@searchspring/snap-logger';
|
|
3
3
|
import { Tracker } from '@searchspring/snap-tracker';
|
|
4
|
+
import { AppMode } from '@searchspring/snap-toolbox';
|
|
4
5
|
import { ControllerTypes } from '@searchspring/snap-controller';
|
|
5
6
|
import type { ClientConfig, ClientGlobals } from '@searchspring/snap-client';
|
|
6
7
|
import type { AbstractController, SearchController, AutocompleteController, FinderController, RecommendationController, SearchControllerConfig, AutocompleteControllerConfig, FinderControllerConfig, RecommendationControllerConfig, ControllerConfigs, ContextVariables } from '@searchspring/snap-controller';
|
|
7
8
|
import type { Target, OnTarget } from '@searchspring/snap-toolbox';
|
|
8
9
|
import type { UrlTranslatorConfig } from '@searchspring/snap-url-manager';
|
|
9
10
|
import { RecommendationInstantiator, RecommendationInstantiatorConfig } from './Instantiators/RecommendationInstantiator';
|
|
10
|
-
import type { SnapControllerServices
|
|
11
|
+
import type { SnapControllerServices } from './types';
|
|
11
12
|
export declare const BRANCH_COOKIE = "ssBranch";
|
|
12
|
-
export declare const
|
|
13
|
+
export declare const DEV_COOKIE = "ssDev";
|
|
13
14
|
declare type ExtendedTarget = Target & {
|
|
14
15
|
name?: string;
|
|
15
16
|
controller?: AbstractController;
|
|
16
|
-
component?: () => Promise<
|
|
17
|
-
skeleton?: () => Promise<any
|
|
18
|
-
props?:
|
|
17
|
+
component?: () => Promise<any> | any;
|
|
18
|
+
skeleton?: () => Promise<any> | any;
|
|
19
|
+
props?: {
|
|
20
|
+
[propName: string]: any;
|
|
21
|
+
};
|
|
19
22
|
onTarget?: OnTarget;
|
|
20
23
|
prefetch?: boolean;
|
|
21
24
|
};
|
|
22
25
|
export declare type SnapConfig = {
|
|
26
|
+
mode?: keyof typeof AppMode | AppMode;
|
|
23
27
|
context?: ContextVariables;
|
|
24
28
|
url?: UrlTranslatorConfig;
|
|
25
29
|
client?: {
|
|
@@ -67,20 +71,17 @@ declare type SnapServices = {
|
|
|
67
71
|
};
|
|
68
72
|
declare type Controllers = SearchController | AutocompleteController | FinderController | RecommendationController;
|
|
69
73
|
export declare class Snap {
|
|
70
|
-
|
|
74
|
+
private mode;
|
|
75
|
+
private config;
|
|
76
|
+
private _instantiatorPromises;
|
|
77
|
+
private _controllerPromises;
|
|
71
78
|
logger: Logger;
|
|
72
79
|
client: Client;
|
|
73
80
|
tracker: Tracker;
|
|
74
81
|
context: ContextVariables;
|
|
75
|
-
_controllerPromises: {
|
|
76
|
-
[controllerConfigId: string]: Promise<Controllers>;
|
|
77
|
-
};
|
|
78
82
|
controllers: {
|
|
79
83
|
[controllerConfigId: string]: Controllers;
|
|
80
84
|
};
|
|
81
|
-
_instantiatorPromises: {
|
|
82
|
-
[instantiatorId: string]: Promise<RecommendationInstantiator>;
|
|
83
|
-
};
|
|
84
85
|
getInstantiator: (id: string) => Promise<RecommendationInstantiator>;
|
|
85
86
|
getController: (id: string) => Promise<Controllers>;
|
|
86
87
|
getControllers: (...controllerIds: string[]) => Promise<Controllers[]>;
|
|
@@ -134,6 +135,7 @@ export declare class Snap {
|
|
|
134
135
|
}>;
|
|
135
136
|
}>;
|
|
136
137
|
}> | undefined, context?: ContextVariables | undefined, callback?: ((value?: Controllers | PromiseLike<Controllers> | undefined) => void | Promise<void>) | undefined) => Promise<Controllers>;
|
|
138
|
+
private _createController;
|
|
137
139
|
handlers: {
|
|
138
140
|
error: (event: ErrorEvent) => void;
|
|
139
141
|
};
|
package/dist/esm/Snap.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Snap.d.ts","sourceRoot":"","sources":["../../src/Snap.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACnD,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"Snap.d.ts","sourceRoot":"","sources":["../../src/Snap.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AACrD,OAAO,EAAE,OAAO,EAAgE,MAAM,4BAA4B,CAAC;AACnH,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAGhE,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,EACtB,4BAA4B,EAC5B,sBAAsB,EACtB,8BAA8B,EAC9B,iBAAiB,EACjB,gBAAgB,EAChB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,KAAK,EAAE,mBAAmB,EA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E,gBAAgB,CAAC;IAC1B,WAAW,EAAE;QACnB,CAAC,kBAAkB,EAAE,MAAM,GAAG,WAAW,CAAC;KAC1C,CAAM;IAEA,eAAe,OAAQ,MAAM,KAAG,QAAQ,0BAA0B,CAAC,CAExE;IAEK,aAAa,OAAQ,MAAM,KAAG,QAAQ,WAAW,CAAC,CAEvD;IAEK,cAAc,qBAAsB,MAAM,EAAE,KAAG,QAAQ,WAAW,EAAE,CAAC,CAI1E;IAGK,gBAAgB,SAChB,MAAM,sBAAsB,UAC1B,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wIAIsC,IAAI,GAAG,QAAQ,IAAI,CAAC,kBACjF,QAAQ,WAAW,CAAC,CAarB;IAGF,OAAO,CAAC,iBAAiB,CAsDvB;IAEK,QAAQ;uBACC,UAAU,KAAG,IAAI;MA8B/B;gBAEU,MAAM,EAAE,UAAU,EAAE,QAAQ,CAAC,EAAE,YAAY;CAikBvD"}
|
package/dist/esm/Snap.js
CHANGED
|
@@ -3,14 +3,14 @@ import deepmerge from 'deepmerge';
|
|
|
3
3
|
import { isPlainObject } from 'is-plain-object';
|
|
4
4
|
import { render } from 'preact';
|
|
5
5
|
import { Client } from '@searchspring/snap-client';
|
|
6
|
-
import { Logger
|
|
6
|
+
import { Logger } from '@searchspring/snap-logger';
|
|
7
7
|
import { Tracker } from '@searchspring/snap-tracker';
|
|
8
|
-
import { version, DomTargeter, url, cookies, featureFlags } from '@searchspring/snap-toolbox';
|
|
9
|
-
import { getContext } from '@searchspring/snap-toolbox';
|
|
8
|
+
import { AppMode, version, getContext, DomTargeter, url, cookies, featureFlags } from '@searchspring/snap-toolbox';
|
|
10
9
|
import { ControllerTypes } from '@searchspring/snap-controller';
|
|
11
10
|
import { default as createSearchController } from './create/createSearchController';
|
|
12
11
|
export const BRANCH_COOKIE = 'ssBranch';
|
|
13
|
-
export const
|
|
12
|
+
export const DEV_COOKIE = 'ssDev';
|
|
13
|
+
const SESSION_ATTRIBUTION = 'ssAttribution';
|
|
14
14
|
const COMPONENT_ERROR = `Uncaught Error - Invalid value passed as the component.
|
|
15
15
|
This usually happens when you pass a JSX Element, and not a function that returns the component, in the snap config.
|
|
16
16
|
|
|
@@ -47,6 +47,10 @@ This usually happens when you pass a JSX Element, and not a function that return
|
|
|
47
47
|
The error above happened in the following targeter in the Snap Config`;
|
|
48
48
|
export class Snap {
|
|
49
49
|
constructor(config, services) {
|
|
50
|
+
this.mode = AppMode.production;
|
|
51
|
+
this._instantiatorPromises = {};
|
|
52
|
+
this._controllerPromises = {};
|
|
53
|
+
this.controllers = {};
|
|
50
54
|
this.getInstantiator = (id) => {
|
|
51
55
|
return this._instantiatorPromises[id] || Promise.reject(`getInstantiator could not find instantiator with id: ${id}`);
|
|
52
56
|
};
|
|
@@ -58,7 +62,20 @@ export class Snap {
|
|
|
58
62
|
controllerIds.forEach((id) => getControllerPromises.push(this.getController(id)));
|
|
59
63
|
return Promise.all(getControllerPromises);
|
|
60
64
|
};
|
|
65
|
+
// exposed method used for creating controllers dynamically - calls _createController()
|
|
61
66
|
this.createController = async (type, config, services, urlConfig, context, callback) => {
|
|
67
|
+
if (typeof this._controllerPromises[config.id] != 'undefined') {
|
|
68
|
+
throw new Error(`Controller with id '${config.id}' is already defined`);
|
|
69
|
+
}
|
|
70
|
+
this._controllerPromises[config.id] = new Promise((resolve) => this._createController(type, config, services, urlConfig, context, async (cntrlr) => {
|
|
71
|
+
if (typeof callback == 'function')
|
|
72
|
+
await callback(cntrlr);
|
|
73
|
+
resolve(cntrlr);
|
|
74
|
+
}));
|
|
75
|
+
return this._controllerPromises[config.id];
|
|
76
|
+
};
|
|
77
|
+
// internal use method that creates controllers without verifying if id is in use first
|
|
78
|
+
this._createController = async (type, config, services, urlConfig, context, callback) => {
|
|
62
79
|
let importPromise;
|
|
63
80
|
switch (type) {
|
|
64
81
|
case ControllerTypes.autocomplete:
|
|
@@ -78,7 +95,9 @@ export class Snap {
|
|
|
78
95
|
// @ts-ignore - we know the config is correct, but complicated typing
|
|
79
96
|
const creationFunc = (await importPromise).default;
|
|
80
97
|
if (!this.controllers[config.id]) {
|
|
81
|
-
|
|
98
|
+
window.searchspring.controller = window.searchspring.controller || {};
|
|
99
|
+
window.searchspring.controller[config.id] = this.controllers[config.id] = creationFunc({
|
|
100
|
+
mode: this.mode,
|
|
82
101
|
url: deepmerge(this.config.url || {}, urlConfig || {}),
|
|
83
102
|
controller: config,
|
|
84
103
|
context: deepmerge(this.context || {}, context || {}),
|
|
@@ -126,14 +145,13 @@ export class Snap {
|
|
|
126
145
|
window.removeEventListener('error', this.handlers.error);
|
|
127
146
|
window.addEventListener('error', this.handlers.error);
|
|
128
147
|
this.config = config;
|
|
129
|
-
this.logger = services?.logger || new Logger('Snap Preact ');
|
|
130
148
|
let globalContext = {};
|
|
131
149
|
try {
|
|
132
150
|
// get global context
|
|
133
151
|
globalContext = getContext(['shopper', 'config', 'merchandising']);
|
|
134
152
|
}
|
|
135
153
|
catch (err) {
|
|
136
|
-
|
|
154
|
+
console.error('Snap failed to find global context');
|
|
137
155
|
}
|
|
138
156
|
// merge configs - but only merge plain objects
|
|
139
157
|
this.config = deepmerge(this.config || {}, globalContext.config || {}, {
|
|
@@ -145,8 +163,9 @@ export class Snap {
|
|
|
145
163
|
if ((!services?.client || !services?.tracker) && !this.config?.client?.globals?.siteId) {
|
|
146
164
|
throw new Error(`Snap: config provided must contain a valid config.client.globals.siteId value`);
|
|
147
165
|
}
|
|
148
|
-
|
|
149
|
-
|
|
166
|
+
// segmented merchandising context -> client globals
|
|
167
|
+
if (this.config.client?.globals && this.context.merchandising?.segments) {
|
|
168
|
+
if (this.config.client.globals?.merchandising) {
|
|
150
169
|
this.config.client.globals.merchandising.segments = deepmerge(this.config.client.globals.merchandising.segments, this.context.merchandising.segments);
|
|
151
170
|
}
|
|
152
171
|
else {
|
|
@@ -155,33 +174,73 @@ export class Snap {
|
|
|
155
174
|
};
|
|
156
175
|
}
|
|
157
176
|
}
|
|
158
|
-
this.client = services?.client || new Client(this.config.client.globals, this.config.client.config);
|
|
159
|
-
this.tracker = services?.tracker || new Tracker(this.config.client.globals, { framework: 'preact' });
|
|
160
|
-
this._controllerPromises = {};
|
|
161
|
-
this._instantiatorPromises = {};
|
|
162
|
-
this.controllers = {};
|
|
163
|
-
// TODO environment switch using URL?
|
|
164
|
-
this.logger.setMode(process.env.NODE_ENV);
|
|
165
|
-
// log version
|
|
166
|
-
this.logger.imageText({
|
|
167
|
-
url: 'https://snapui.searchspring.io/favicon.svg',
|
|
168
|
-
text: `[${version}]`,
|
|
169
|
-
style: `color: ${this.logger.colors.indigo}; font-weight: bold;`,
|
|
170
|
-
});
|
|
171
177
|
try {
|
|
172
178
|
const urlParams = url(window.location.href);
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
|
|
179
|
+
const branchOverride = urlParams?.params?.query?.branch || cookies.get(BRANCH_COOKIE);
|
|
180
|
+
/* app mode priority:
|
|
181
|
+
1. node env
|
|
182
|
+
2. config
|
|
183
|
+
3. override via query param / cookie
|
|
184
|
+
*/
|
|
185
|
+
// node env
|
|
186
|
+
if (process.env.NODE_ENV && Object.values(AppMode).includes(process.env.NODE_ENV)) {
|
|
187
|
+
this.mode = process.env.NODE_ENV;
|
|
188
|
+
}
|
|
189
|
+
// config
|
|
190
|
+
if (this.config.mode && Object.values(AppMode).includes(this.config.mode)) {
|
|
191
|
+
this.mode = this.config.mode;
|
|
192
|
+
}
|
|
193
|
+
// query param / cookiev override
|
|
194
|
+
if ((urlParams?.params?.query && 'dev' in urlParams.params.query) || !!cookies.get(DEV_COOKIE)) {
|
|
195
|
+
if (urlParams?.params.query?.dev == 'false' || urlParams?.params.query?.dev == '0') {
|
|
196
|
+
cookies.unset(DEV_COOKIE);
|
|
197
|
+
this.mode = AppMode.production;
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
cookies.set(DEV_COOKIE, '1', 'Lax', 0);
|
|
201
|
+
this.mode = AppMode.development;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
// client mode uses client config over snap config
|
|
205
|
+
if (this.config.client) {
|
|
206
|
+
this.config.client.config = this.config.client.config || {};
|
|
207
|
+
this.config.client.config.mode = this.config.client.config.mode || this.mode;
|
|
208
|
+
}
|
|
209
|
+
this.client = services?.client || new Client(this.config.client.globals, this.config.client.config);
|
|
210
|
+
this.tracker = services?.tracker || new Tracker(this.config.client.globals, { framework: 'preact' });
|
|
211
|
+
this.logger = services?.logger || new Logger({ prefix: 'Snap Preact ', mode: this.mode });
|
|
212
|
+
// check for tracking attribution in URL ?ss_attribution=type:id
|
|
213
|
+
const sessionAttribution = window.sessionStorage?.getItem(SESSION_ATTRIBUTION);
|
|
214
|
+
if (urlParams?.params?.query?.ss_attribution) {
|
|
215
|
+
const attribution = urlParams.params.query.ss_attribution.split(':');
|
|
216
|
+
const [type, id] = attribution;
|
|
217
|
+
if (type && id) {
|
|
218
|
+
this.tracker.updateContext('attribution', { type, id });
|
|
219
|
+
}
|
|
220
|
+
// save to session storage
|
|
221
|
+
window.sessionStorage?.setItem(SESSION_ATTRIBUTION, urlParams.params.query.ss_attribution);
|
|
222
|
+
}
|
|
223
|
+
else if (sessionAttribution) {
|
|
224
|
+
const [type, id] = sessionAttribution.split(':');
|
|
225
|
+
if (type && id) {
|
|
226
|
+
this.tracker.updateContext('attribution', { type, id });
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
// log version
|
|
230
|
+
this.logger.imageText({
|
|
231
|
+
url: 'https://snapui.searchspring.io/favicon.svg',
|
|
232
|
+
text: `[${version}]`,
|
|
233
|
+
style: `color: ${this.logger.colors.indigo}; font-weight: bold;`,
|
|
234
|
+
});
|
|
235
|
+
if (branchOverride && !document.querySelector(`script[${BRANCH_COOKIE}]`)) {
|
|
236
|
+
this.logger.warn(`...loading build... '${branchOverride}'`);
|
|
237
|
+
// set a cookie with branch
|
|
176
238
|
if (featureFlags.cookies) {
|
|
177
|
-
cookies.set(BRANCH_COOKIE,
|
|
178
|
-
cookies.set(SS_DEV_COOKIE, '1', 'Lax', 0);
|
|
239
|
+
cookies.set(BRANCH_COOKIE, branchOverride, 'Lax', 3600000); // 1 hour
|
|
179
240
|
}
|
|
180
241
|
else {
|
|
181
242
|
this.logger.warn('Cookies are not supported/enabled by this browser, branch overrides will not persist!');
|
|
182
243
|
}
|
|
183
|
-
this.logger.setMode(LogMode.DEVELOPMENT);
|
|
184
|
-
this.logger.warn(`...loading build... '${branchParam}'`);
|
|
185
244
|
// get the path and siteId from the current bundle script in case its not the same as the client config
|
|
186
245
|
let path = `https://snapui.searchspring.io/${this.config.client.globals.siteId}/`;
|
|
187
246
|
const script = document.querySelector('script[src*="//snapui.searchspring.io"]');
|
|
@@ -193,9 +252,9 @@ export class Snap {
|
|
|
193
252
|
}
|
|
194
253
|
// append script with new branch in path
|
|
195
254
|
const branchScript = document.createElement('script');
|
|
196
|
-
const src = `${path}${
|
|
255
|
+
const src = `${path}${branchOverride}/bundle.js`;
|
|
197
256
|
branchScript.src = src;
|
|
198
|
-
branchScript.setAttribute(BRANCH_COOKIE,
|
|
257
|
+
branchScript.setAttribute(BRANCH_COOKIE, branchOverride);
|
|
199
258
|
new DomTargeter([
|
|
200
259
|
{
|
|
201
260
|
selector: 'body',
|
|
@@ -209,20 +268,16 @@ export class Snap {
|
|
|
209
268
|
},
|
|
210
269
|
},
|
|
211
270
|
], async (target, elem) => {
|
|
212
|
-
const
|
|
213
|
-
message: 'Error',
|
|
214
|
-
description: '',
|
|
215
|
-
};
|
|
216
|
-
let bundleDetails;
|
|
271
|
+
const props = {};
|
|
217
272
|
try {
|
|
218
273
|
const getBundleDetails = (await import('./getBundleDetails/getBundleDetails')).getBundleDetails;
|
|
219
|
-
|
|
274
|
+
props.details = await getBundleDetails(src);
|
|
220
275
|
}
|
|
221
276
|
catch (err) {
|
|
222
|
-
error
|
|
277
|
+
props.error = err;
|
|
223
278
|
}
|
|
224
279
|
const BranchOverride = (await import('./components/BranchOverride')).BranchOverride;
|
|
225
|
-
render(_jsx(BranchOverride, {
|
|
280
|
+
render(_jsx(BranchOverride, { ...props, name: branchOverride, onRemoveClick: () => {
|
|
226
281
|
cookies.unset(BRANCH_COOKIE);
|
|
227
282
|
const urlState = url(window.location.href);
|
|
228
283
|
delete urlState?.params.query['branch'];
|
|
@@ -234,19 +289,22 @@ export class Snap {
|
|
|
234
289
|
window.location.reload();
|
|
235
290
|
}
|
|
236
291
|
} }), elem);
|
|
237
|
-
|
|
292
|
+
// reset the global searchspring object
|
|
293
|
+
delete window.searchspring;
|
|
238
294
|
document.head.appendChild(branchScript);
|
|
239
295
|
});
|
|
240
296
|
// prevent further instantiation of config
|
|
241
297
|
return;
|
|
242
298
|
}
|
|
243
299
|
}
|
|
244
|
-
catch (e) {
|
|
245
|
-
|
|
246
|
-
window.searchspring.context = this.context;
|
|
247
|
-
if (this.client)
|
|
248
|
-
window.searchspring.client = this.client;
|
|
300
|
+
catch (e) {
|
|
301
|
+
this.logger.error(e);
|
|
249
302
|
}
|
|
303
|
+
// bind to window global
|
|
304
|
+
window.searchspring = window.searchspring || {};
|
|
305
|
+
window.searchspring.context = this.context;
|
|
306
|
+
if (this.client)
|
|
307
|
+
window.searchspring.client = this.client;
|
|
250
308
|
// autotrack shopper id from the context
|
|
251
309
|
if (this.context?.shopper?.id) {
|
|
252
310
|
this.tracker.track.shopper.login({
|
|
@@ -266,7 +324,12 @@ export class Snap {
|
|
|
266
324
|
case 'search': {
|
|
267
325
|
this.config.controllers[type].forEach((controller, index) => {
|
|
268
326
|
try {
|
|
327
|
+
if (typeof this._controllerPromises[controller.config.id] != 'undefined') {
|
|
328
|
+
this.logger.error(`Controller with id '${controller.config.id}' is already defined`);
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
269
331
|
const cntrlr = createSearchController({
|
|
332
|
+
mode: this.mode,
|
|
270
333
|
url: deepmerge(this.config.url || {}, controller.url || {}),
|
|
271
334
|
controller: controller.config,
|
|
272
335
|
context: deepmerge(this.context || {}, controller.context || {}),
|
|
@@ -279,7 +342,8 @@ export class Snap {
|
|
|
279
342
|
logger: controller.services?.logger,
|
|
280
343
|
tracker: controller.services?.tracker || this.tracker,
|
|
281
344
|
});
|
|
282
|
-
|
|
345
|
+
window.searchspring.controller = window.searchspring.controller || {};
|
|
346
|
+
window.searchspring.controller[cntrlr.config.id] = this.controllers[cntrlr.config.id] = cntrlr;
|
|
283
347
|
this._controllerPromises[cntrlr.config.id] = new Promise((resolve) => resolve(cntrlr));
|
|
284
348
|
let searched = false;
|
|
285
349
|
const runSearch = () => {
|
|
@@ -331,6 +395,10 @@ export class Snap {
|
|
|
331
395
|
}
|
|
332
396
|
case 'autocomplete': {
|
|
333
397
|
this.config.controllers[type].forEach((controller, index) => {
|
|
398
|
+
if (typeof this._controllerPromises[controller.config.id] != 'undefined') {
|
|
399
|
+
this.logger.error(`Controller with id '${controller.config.id}' is already defined`);
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
334
402
|
this._controllerPromises[controller.config.id] = new Promise((resolve) => {
|
|
335
403
|
try {
|
|
336
404
|
let bound = false;
|
|
@@ -356,7 +424,7 @@ export class Snap {
|
|
|
356
424
|
}
|
|
357
425
|
};
|
|
358
426
|
if (!controller?.targeters || controller?.targeters.length === 0) {
|
|
359
|
-
this.
|
|
427
|
+
this._createController(ControllerTypes.autocomplete, controller.config, controller.services, controller.url, controller.context, (cntrlr) => {
|
|
360
428
|
if (cntrlr)
|
|
361
429
|
resolve(cntrlr);
|
|
362
430
|
});
|
|
@@ -384,7 +452,7 @@ export class Snap {
|
|
|
384
452
|
...target,
|
|
385
453
|
},
|
|
386
454
|
], async (target, elem, originalElem) => {
|
|
387
|
-
const cntrlr = await this.
|
|
455
|
+
const cntrlr = await this._createController(ControllerTypes.autocomplete, controller.config, controller.services, controller.url, controller.context, (cntrlr) => {
|
|
388
456
|
if (cntrlr)
|
|
389
457
|
resolve(cntrlr);
|
|
390
458
|
});
|
|
@@ -403,6 +471,10 @@ export class Snap {
|
|
|
403
471
|
}
|
|
404
472
|
case 'finder': {
|
|
405
473
|
this.config.controllers[type].forEach((controller, index) => {
|
|
474
|
+
if (typeof this._controllerPromises[controller.config.id] != 'undefined') {
|
|
475
|
+
this.logger.error(`Controller with id '${controller.config.id}' is already defined`);
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
406
478
|
this._controllerPromises[controller.config.id] = new Promise((resolve) => {
|
|
407
479
|
try {
|
|
408
480
|
let searched = false;
|
|
@@ -426,7 +498,7 @@ export class Snap {
|
|
|
426
498
|
}
|
|
427
499
|
};
|
|
428
500
|
if (!controller?.targeters || controller?.targeters.length === 0) {
|
|
429
|
-
this.
|
|
501
|
+
this._createController(ControllerTypes.finder, controller.config, controller.services, controller.url, controller.context, (cntrlr) => {
|
|
430
502
|
if (cntrlr)
|
|
431
503
|
resolve(cntrlr);
|
|
432
504
|
});
|
|
@@ -439,7 +511,7 @@ export class Snap {
|
|
|
439
511
|
throw new Error(`Targets at index ${target_index} missing component value (Component).`);
|
|
440
512
|
}
|
|
441
513
|
const targeter = new DomTargeter([{ ...target }], async (target, elem, originalElem) => {
|
|
442
|
-
const cntrlr = await this.
|
|
514
|
+
const cntrlr = await this._createController(ControllerTypes.finder, controller.config, controller.services, controller.url, controller.context, (cntrlr) => {
|
|
443
515
|
if (cntrlr)
|
|
444
516
|
resolve(cntrlr);
|
|
445
517
|
});
|
|
@@ -458,6 +530,10 @@ export class Snap {
|
|
|
458
530
|
}
|
|
459
531
|
case 'recommendation': {
|
|
460
532
|
this.config.controllers[type].forEach((controller, index) => {
|
|
533
|
+
if (typeof this._controllerPromises[controller.config.id] != 'undefined') {
|
|
534
|
+
this.logger.error(`Controller with id '${controller.config.id}' is already defined`);
|
|
535
|
+
return;
|
|
536
|
+
}
|
|
461
537
|
this._controllerPromises[controller.config.id] = new Promise((resolve) => {
|
|
462
538
|
try {
|
|
463
539
|
let searched = false;
|
|
@@ -481,7 +557,7 @@ export class Snap {
|
|
|
481
557
|
}
|
|
482
558
|
};
|
|
483
559
|
if (!controller?.targeters || controller?.targeters.length === 0) {
|
|
484
|
-
this.
|
|
560
|
+
this._createController(ControllerTypes.recommendation, controller.config, controller.services, controller.url, controller.context, (cntrlr) => {
|
|
485
561
|
if (cntrlr)
|
|
486
562
|
resolve(cntrlr);
|
|
487
563
|
});
|
|
@@ -494,7 +570,7 @@ export class Snap {
|
|
|
494
570
|
throw new Error(`Targets at index ${target_index} missing component value (Component).`);
|
|
495
571
|
}
|
|
496
572
|
const targeter = new DomTargeter([{ ...target }], async (target, elem, originalElem) => {
|
|
497
|
-
const cntrlr = await this.
|
|
573
|
+
const cntrlr = await this._createController(ControllerTypes.recommendation, controller.config, controller.services, controller.url, controller.context, (cntrlr) => {
|
|
498
574
|
if (cntrlr)
|
|
499
575
|
resolve(cntrlr);
|
|
500
576
|
});
|
|
@@ -516,6 +592,7 @@ export class Snap {
|
|
|
516
592
|
if (this.config?.instantiators?.recommendation) {
|
|
517
593
|
try {
|
|
518
594
|
this._instantiatorPromises.recommendation = import('./Instantiators/RecommendationInstantiator').then(({ RecommendationInstantiator }) => {
|
|
595
|
+
this.config.instantiators.recommendation.mode = this.config.instantiators.recommendation.mode || this.mode;
|
|
519
596
|
return new RecommendationInstantiator(this.config.instantiators.recommendation, {
|
|
520
597
|
client: this.client,
|
|
521
598
|
tracker: this.tracker,
|
|
@@ -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,oDAAsC,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,oDAAsC,sBAAsB;AAApH,wBAwBE"}
|
|
@@ -10,13 +10,18 @@ import { Tracker } from '@searchspring/snap-tracker';
|
|
|
10
10
|
configureMobx({ useProxies: 'never' });
|
|
11
11
|
export default (config, services) => {
|
|
12
12
|
const urlManager = (services?.urlManager || new UrlManager(new UrlTranslator(config.url), reactLinker)).detach();
|
|
13
|
+
// set client mode
|
|
14
|
+
if (config.mode && config.client) {
|
|
15
|
+
config.client.config = config.client.config || {};
|
|
16
|
+
config.client.config.mode = config.mode;
|
|
17
|
+
}
|
|
13
18
|
const cntrlr = new AutocompleteController(config.controller, {
|
|
14
19
|
client: services?.client || new Client(config.client.globals, config.client.config),
|
|
15
20
|
store: services?.store || new AutocompleteStore(config.controller, { urlManager }),
|
|
16
21
|
urlManager,
|
|
17
22
|
eventManager: services?.eventManager || new EventManager(),
|
|
18
23
|
profiler: services?.profiler || new Profiler(),
|
|
19
|
-
logger: services?.logger || new Logger(),
|
|
24
|
+
logger: services?.logger || new Logger({ mode: config.mode }),
|
|
20
25
|
tracker: services?.tracker || new Tracker(config.client.globals),
|
|
21
26
|
}, config.context);
|
|
22
27
|
return cntrlr;
|
|
@@ -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,oDAAsC,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,oDAAsC,gBAAgB;AAAxG,wBAwBE"}
|
|
@@ -10,13 +10,18 @@ import { Tracker } from '@searchspring/snap-tracker';
|
|
|
10
10
|
configureMobx({ useProxies: 'never' });
|
|
11
11
|
export default (config, services) => {
|
|
12
12
|
const urlManager = (services?.urlManager || new UrlManager(new UrlTranslator(config.url), reactLinker)).detach(true);
|
|
13
|
+
// set client mode
|
|
14
|
+
if (config.mode && config.client) {
|
|
15
|
+
config.client.config = config.client.config || {};
|
|
16
|
+
config.client.config.mode = config.mode;
|
|
17
|
+
}
|
|
13
18
|
const cntrlr = new FinderController(config.controller, {
|
|
14
19
|
client: services?.client || new Client(config.client.globals, config.client.config),
|
|
15
20
|
store: services?.store || new FinderStore(config.controller, { urlManager }),
|
|
16
21
|
urlManager,
|
|
17
22
|
eventManager: services?.eventManager || new EventManager(),
|
|
18
23
|
profiler: services?.profiler || new Profiler(),
|
|
19
|
-
logger: services?.logger || new Logger(),
|
|
24
|
+
logger: services?.logger || new Logger({ mode: config.mode }),
|
|
20
25
|
tracker: services?.tracker || new Tracker(config.client.globals),
|
|
21
26
|
}, config.context);
|
|
22
27
|
return cntrlr;
|
|
@@ -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,oDAAsC,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,oDAAsC,wBAAwB;AAAxH,wBAwBE"}
|