@ninetailed/experience.js-gatsby 4.2.5 → 4.2.6-beta.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/{serialize.js → _tslib.js} +0 -39
- package/gatsby-browser.js +31 -7
- package/gatsby-node.js +61 -12
- package/package.json +3 -3
- package/plugin-options.d.ts +15 -2
- package/utils/deserialize.d.ts +3 -0
- package/utils/serialize.d.ts +6 -5
|
@@ -37,44 +37,5 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
const createFunctionBody = serializedFunction => {
|
|
41
|
-
return '"use strict";\n return ' + serializedFunction + ';';
|
|
42
|
-
};
|
|
43
|
-
const deserializeFunction = serializedFunction => {
|
|
44
|
-
return new Function(createFunctionBody(serializedFunction))();
|
|
45
|
-
};
|
|
46
|
-
const deserializePluginOptionFns = options => {
|
|
47
|
-
var _a;
|
|
48
|
-
return (_a = options.serializedFunctionNames) === null || _a === void 0 ? void 0 : _a.reduce((acc, currFuncName) => {
|
|
49
|
-
const currentFunction = options[currFuncName];
|
|
50
|
-
if (currentFunction && typeof currentFunction === 'string') {
|
|
51
|
-
return Object.assign(Object.assign({}, acc), {
|
|
52
|
-
[currFuncName]: deserializeFunction(currentFunction)
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
return acc;
|
|
56
|
-
}, {});
|
|
57
|
-
};
|
|
58
|
-
const serializePluginOptionFns = pluginOptions => {
|
|
59
|
-
const serializedFunctionNames = [];
|
|
60
|
-
const serializedFunctions = Object.keys(pluginOptions).reduce((acc, optionKey) => {
|
|
61
|
-
const optionValue = pluginOptions[optionKey];
|
|
62
|
-
if (optionValue && typeof optionValue === 'function') {
|
|
63
|
-
const serializedFunction = optionValue.toString();
|
|
64
|
-
serializedFunctionNames.push(optionKey);
|
|
65
|
-
return Object.assign(Object.assign({}, acc), {
|
|
66
|
-
[optionKey]: serializedFunction
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
return acc;
|
|
70
|
-
}, {});
|
|
71
|
-
return {
|
|
72
|
-
serializedFunctions,
|
|
73
|
-
serializedFunctionNames
|
|
74
|
-
};
|
|
75
|
-
};
|
|
76
|
-
|
|
77
40
|
exports.__awaiter = __awaiter;
|
|
78
41
|
exports.__rest = __rest;
|
|
79
|
-
exports.deserializePluginOptionFns = deserializePluginOptionFns;
|
|
80
|
-
exports.serializePluginOptionFns = serializePluginOptionFns;
|
package/gatsby-browser.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _tslib = require('./_tslib.js');
|
|
6
6
|
var React = require('react');
|
|
7
7
|
var experience_js = require('@ninetailed/experience.js');
|
|
8
8
|
var experience_jsReact = require('@ninetailed/experience.js-react');
|
|
@@ -16,25 +16,49 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
16
16
|
|
|
17
17
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
18
18
|
|
|
19
|
+
const createFunctionBody = serializedFunction => {
|
|
20
|
+
return '"use strict";\n return ' + serializedFunction + ';';
|
|
21
|
+
};
|
|
22
|
+
const deserializeFunction = serializedFunction => {
|
|
23
|
+
return new Function(createFunctionBody(serializedFunction))();
|
|
24
|
+
};
|
|
25
|
+
const deserializePluginOptionFunctions = options => {
|
|
26
|
+
var _a;
|
|
27
|
+
return (_a = options.serializedFunctionNames) === null || _a === void 0 ? void 0 : _a.reduce((acc, currFuncName) => {
|
|
28
|
+
const currentFunction = options[currFuncName];
|
|
29
|
+
if (currentFunction && typeof currentFunction === 'string') {
|
|
30
|
+
return Object.assign(Object.assign({}, acc), {
|
|
31
|
+
[currFuncName]: deserializeFunction(currentFunction)
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return acc;
|
|
35
|
+
}, {});
|
|
36
|
+
};
|
|
37
|
+
|
|
19
38
|
let ninetailed;
|
|
39
|
+
const isSerializedPreviewPlugin = options => {
|
|
40
|
+
return !!(options.customOptions && options.serializedFunctionNames && options.customOptions.serializedFunctionNames);
|
|
41
|
+
};
|
|
20
42
|
const WrapRootElement = _a => {
|
|
21
43
|
var {
|
|
22
44
|
children
|
|
23
45
|
} = _a,
|
|
24
|
-
options =
|
|
46
|
+
options = _tslib.__rest(_a, ["children"]);
|
|
25
47
|
if (!ninetailed) {
|
|
26
48
|
const resolvedPlugins = loaders_ninetailedPlugins.plugins.map(({
|
|
27
49
|
PluginCtor,
|
|
28
50
|
options
|
|
29
51
|
}) => {
|
|
30
|
-
if (
|
|
31
|
-
|
|
52
|
+
if (isSerializedPreviewPlugin(options)) {
|
|
53
|
+
const updatedOptions = Object.assign(Object.assign(Object.assign({}, options), deserializePluginOptionFunctions(options)), {
|
|
54
|
+
customOptions: Object.assign(Object.assign({}, options.customOptions), deserializePluginOptionFunctions(options.customOptions))
|
|
55
|
+
});
|
|
56
|
+
return new PluginCtor(updatedOptions);
|
|
32
57
|
}
|
|
33
|
-
if (options
|
|
58
|
+
if (options) {
|
|
34
59
|
return new PluginCtor(options);
|
|
35
60
|
}
|
|
36
|
-
|
|
37
|
-
return new PluginCtor(updatedOptions);
|
|
61
|
+
return new PluginCtor();
|
|
38
62
|
});
|
|
39
63
|
const {
|
|
40
64
|
clientId,
|
package/gatsby-node.js
CHANGED
|
@@ -2,13 +2,52 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _tslib = require('./_tslib.js');
|
|
6
6
|
var require$$0 = require('path');
|
|
7
7
|
|
|
8
8
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
9
9
|
|
|
10
10
|
var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Constructs an object/context holding serialized functions along with an array of their names
|
|
14
|
+
* @param objectToSerialize - The object to serialize
|
|
15
|
+
*/
|
|
16
|
+
const constructSerializationContext = objectToSerialize => {
|
|
17
|
+
return Object.keys(objectToSerialize).reduce((acc, key) => {
|
|
18
|
+
const optionValue = objectToSerialize[key];
|
|
19
|
+
if (optionValue && typeof optionValue === 'function') {
|
|
20
|
+
const serializedFunction = optionValue.toString();
|
|
21
|
+
// Storing the keys of the serialized functions in a separate array in the context object
|
|
22
|
+
acc['serializedFunctionsNames'].push(key);
|
|
23
|
+
return Object.assign(Object.assign({}, acc), {
|
|
24
|
+
[key]: serializedFunction
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return acc;
|
|
28
|
+
}, {
|
|
29
|
+
serializedFunctionsNames: []
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
const serializePluginOptionFunctions = pluginOptions => {
|
|
33
|
+
const serializedOptionsContext = constructSerializationContext(pluginOptions);
|
|
34
|
+
const serializedCustomOptionsContext = constructSerializationContext(pluginOptions.customOptions);
|
|
35
|
+
const {
|
|
36
|
+
serializedFunctionsNames: serializedOptionFunctionNames
|
|
37
|
+
} = serializedOptionsContext,
|
|
38
|
+
serializedOptionFunctions = _tslib.__rest(serializedOptionsContext, ["serializedFunctionsNames"]);
|
|
39
|
+
const {
|
|
40
|
+
serializedFunctionsNames: serializedCustomOptionFunctionNames
|
|
41
|
+
} = serializedCustomOptionsContext,
|
|
42
|
+
serializedCustomOptionFunctions = _tslib.__rest(serializedCustomOptionsContext, ["serializedFunctionsNames"]);
|
|
43
|
+
return {
|
|
44
|
+
serializedOptionFunctions,
|
|
45
|
+
serializedOptionFunctionNames,
|
|
46
|
+
serializedCustomOptionFunctions,
|
|
47
|
+
serializedCustomOptionFunctionNames
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
|
|
12
51
|
const pluginOptionsSchema = ({
|
|
13
52
|
Joi
|
|
14
53
|
}) => {
|
|
@@ -52,7 +91,7 @@ const createPages = ({
|
|
|
52
91
|
actions,
|
|
53
92
|
store,
|
|
54
93
|
graphql
|
|
55
|
-
}) =>
|
|
94
|
+
}) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
56
95
|
const ninetailedGatsbyPlugin = store.getState().flattenedPlugins.find(plugin => plugin.name === '@ninetailed/experience.js-gatsby');
|
|
57
96
|
if (!ninetailedGatsbyPlugin) {
|
|
58
97
|
return;
|
|
@@ -110,17 +149,27 @@ const createPages = ({
|
|
|
110
149
|
if (!pluginOptions) {
|
|
111
150
|
return plugin;
|
|
112
151
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
152
|
+
if (plugin.name === '@ninetailed/experience.js-plugin-preview') {
|
|
153
|
+
const _pluginOptions = plugin.options;
|
|
154
|
+
const {
|
|
155
|
+
serializedOptionFunctions,
|
|
156
|
+
serializedOptionFunctionNames,
|
|
157
|
+
serializedCustomOptionFunctions,
|
|
158
|
+
serializedCustomOptionFunctionNames
|
|
159
|
+
} = serializePluginOptionFunctions(_pluginOptions);
|
|
160
|
+
return Object.assign(Object.assign({}, plugin), {
|
|
161
|
+
options: Object.assign(Object.assign(Object.assign({}, _pluginOptions), serializedOptionFunctions), {
|
|
162
|
+
serializedFunctionNames: serializedOptionFunctionNames,
|
|
163
|
+
customOptions: Object.assign(Object.assign(Object.assign({}, _pluginOptions.customOptions), serializedCustomOptionFunctions), {
|
|
164
|
+
serializedFunctionNames: serializedCustomOptionFunctionNames
|
|
165
|
+
}),
|
|
166
|
+
audiences,
|
|
167
|
+
experiences
|
|
168
|
+
})
|
|
169
|
+
});
|
|
170
|
+
}
|
|
117
171
|
return Object.assign(Object.assign({}, plugin), {
|
|
118
|
-
options: Object.assign(
|
|
119
|
-
serializedFunctionNames
|
|
120
|
-
}), plugin.name === '@ninetailed/experience.js-plugin-preview' && {
|
|
121
|
-
audiences,
|
|
122
|
-
experiences
|
|
123
|
-
})
|
|
172
|
+
options: Object.assign({}, plugin.options)
|
|
124
173
|
});
|
|
125
174
|
});
|
|
126
175
|
ninetailedGatsbyPlugin.pluginOptions = Object.assign(Object.assign({}, ninetailedGatsbyPlugin.pluginOptions), {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ninetailed/experience.js-gatsby",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.6-beta.1",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"gatsby",
|
|
6
6
|
"gatsby-plugin",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"type": "commonjs",
|
|
19
19
|
"types": "./index.d.ts",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@ninetailed/experience.js": "4.2.
|
|
22
|
-
"@ninetailed/experience.js-react": "4.2.
|
|
21
|
+
"@ninetailed/experience.js": "4.2.6-beta.1",
|
|
22
|
+
"@ninetailed/experience.js-react": "4.2.6-beta.1",
|
|
23
23
|
"gatsby-plugin-utils": "3.19.0"
|
|
24
24
|
}
|
|
25
25
|
}
|
package/plugin-options.d.ts
CHANGED
|
@@ -6,12 +6,25 @@ export type PluginOptions = GatsbyPluginOptions & NinetailedProviderInstantiatio
|
|
|
6
6
|
options: unknown;
|
|
7
7
|
}[];
|
|
8
8
|
};
|
|
9
|
-
export type NinetailedPluginOptions = Record<string, unknown>;
|
|
10
9
|
export type SerializedFunctions = {
|
|
11
10
|
serializedFunctionNames: string[];
|
|
12
11
|
};
|
|
13
|
-
|
|
12
|
+
type PreviewPluginCustomOptions = {
|
|
13
|
+
audienceQuery: string;
|
|
14
|
+
audienceMapper: string;
|
|
15
|
+
experienceQuery: string;
|
|
16
|
+
experienceMapper: string;
|
|
17
|
+
};
|
|
18
|
+
export type NinetailedPreviewPluginOptions = Record<string, unknown> & {
|
|
19
|
+
customOptions: PreviewPluginCustomOptions & SerializedFunctions;
|
|
20
|
+
};
|
|
21
|
+
export type NinetailedPluginOptions = Record<string, unknown> | NinetailedPreviewPluginOptions;
|
|
22
|
+
export type ResolvedPreviewPluginOptions = Record<string, unknown> & SerializedFunctions & {
|
|
23
|
+
customOptions: PreviewPluginCustomOptions & SerializedFunctions;
|
|
24
|
+
};
|
|
25
|
+
export type ResolvedPluginOptions = Record<string, unknown> | ResolvedPreviewPluginOptions;
|
|
14
26
|
export type ResolvedPlugin = {
|
|
15
27
|
PluginCtor: any;
|
|
16
28
|
options?: ResolvedPluginOptions;
|
|
17
29
|
};
|
|
30
|
+
export {};
|
package/utils/serialize.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { NinetailedPreviewPluginOptions } from '../plugin-options';
|
|
2
|
+
export declare const serializePluginOptionFunctions: (pluginOptions: NinetailedPreviewPluginOptions) => {
|
|
3
|
+
serializedOptionFunctions: {};
|
|
4
|
+
serializedOptionFunctionNames: string[];
|
|
5
|
+
serializedCustomOptionFunctions: {};
|
|
6
|
+
serializedCustomOptionFunctionNames: string[];
|
|
6
7
|
};
|