@ninetailed/experience.js-gatsby 4.2.5 → 4.2.6-beta.0
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 +25 -4
- package/gatsby-node.js +52 -7
- package/package.json +3 -3
- package/plugin-options.d.ts +13 -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,12 +16,31 @@ 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;
|
|
20
39
|
const WrapRootElement = _a => {
|
|
21
40
|
var {
|
|
22
41
|
children
|
|
23
42
|
} = _a,
|
|
24
|
-
options =
|
|
43
|
+
options = _tslib.__rest(_a, ["children"]);
|
|
25
44
|
if (!ninetailed) {
|
|
26
45
|
const resolvedPlugins = loaders_ninetailedPlugins.plugins.map(({
|
|
27
46
|
PluginCtor,
|
|
@@ -30,10 +49,12 @@ const WrapRootElement = _a => {
|
|
|
30
49
|
if (!options) {
|
|
31
50
|
return new PluginCtor();
|
|
32
51
|
}
|
|
33
|
-
if (options && !options.serializedFunctionNames) {
|
|
52
|
+
if (options && !options.serializedFunctionNames && !options.customOptions.serializedFunctionNames) {
|
|
34
53
|
return new PluginCtor(options);
|
|
35
54
|
}
|
|
36
|
-
const updatedOptions = Object.assign(Object.assign({}, options),
|
|
55
|
+
const updatedOptions = Object.assign(Object.assign(Object.assign({}, options), deserializePluginOptionFunctions(options)), {
|
|
56
|
+
customOptions: Object.assign(Object.assign({}, options.customOptions), deserializePluginOptionFunctions(options.customOptions))
|
|
57
|
+
});
|
|
37
58
|
return new PluginCtor(updatedOptions);
|
|
38
59
|
});
|
|
39
60
|
const {
|
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;
|
|
@@ -106,17 +145,23 @@ const createPages = ({
|
|
|
106
145
|
}
|
|
107
146
|
const experiences = experienceOptionsSet ? experienceMapper(experienceData) : [];
|
|
108
147
|
const ninetailedPluginsOverride = ninetailedGatsbyPlugin.pluginOptions.ninetailedPlugins.map(plugin => {
|
|
148
|
+
var _a;
|
|
109
149
|
const pluginOptions = plugin.options;
|
|
110
150
|
if (!pluginOptions) {
|
|
111
151
|
return plugin;
|
|
112
152
|
}
|
|
113
153
|
const {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
154
|
+
serializedOptionFunctions,
|
|
155
|
+
serializedOptionFunctionNames,
|
|
156
|
+
serializedCustomOptionFunctions,
|
|
157
|
+
serializedCustomOptionFunctionNames
|
|
158
|
+
} = serializePluginOptionFunctions(pluginOptions);
|
|
117
159
|
return Object.assign(Object.assign({}, plugin), {
|
|
118
|
-
options: Object.assign(Object.assign(Object.assign(Object.assign({}, plugin.options),
|
|
119
|
-
serializedFunctionNames
|
|
160
|
+
options: Object.assign(Object.assign(Object.assign(Object.assign({}, plugin.options), serializedOptionFunctions), {
|
|
161
|
+
serializedFunctionNames: serializedOptionFunctionNames,
|
|
162
|
+
customOptions: Object.assign(Object.assign(Object.assign({}, (_a = plugin.options) === null || _a === void 0 ? void 0 : _a.customOptions), serializedCustomOptionFunctions), {
|
|
163
|
+
serializedFunctionNames: serializedCustomOptionFunctionNames
|
|
164
|
+
})
|
|
120
165
|
}), plugin.name === '@ninetailed/experience.js-plugin-preview' && {
|
|
121
166
|
audiences,
|
|
122
167
|
experiences
|
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.0",
|
|
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.0",
|
|
22
|
+
"@ninetailed/experience.js-react": "4.2.6-beta.0",
|
|
23
23
|
"gatsby-plugin-utils": "3.19.0"
|
|
24
24
|
}
|
|
25
25
|
}
|
package/plugin-options.d.ts
CHANGED
|
@@ -6,12 +6,23 @@ export type PluginOptions = GatsbyPluginOptions & NinetailedProviderInstantiatio
|
|
|
6
6
|
options: unknown;
|
|
7
7
|
}[];
|
|
8
8
|
};
|
|
9
|
-
export type NinetailedPluginOptions = Record<string, unknown
|
|
9
|
+
export type NinetailedPluginOptions = Record<string, unknown> & {
|
|
10
|
+
customOptions: Record<string, unknown>;
|
|
11
|
+
};
|
|
10
12
|
export type SerializedFunctions = {
|
|
11
13
|
serializedFunctionNames: string[];
|
|
12
14
|
};
|
|
13
|
-
|
|
15
|
+
type CustomOptions = {
|
|
16
|
+
audienceQuery: string;
|
|
17
|
+
audienceMapper: string;
|
|
18
|
+
experienceQuery: string;
|
|
19
|
+
experienceMapper: string;
|
|
20
|
+
};
|
|
21
|
+
export type ResolvedPluginOptions = Record<string, unknown> & SerializedFunctions & {
|
|
22
|
+
customOptions: CustomOptions & SerializedFunctions;
|
|
23
|
+
};
|
|
14
24
|
export type ResolvedPlugin = {
|
|
15
25
|
PluginCtor: any;
|
|
16
26
|
options?: ResolvedPluginOptions;
|
|
17
27
|
};
|
|
28
|
+
export {};
|
package/utils/serialize.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { NinetailedPluginOptions
|
|
2
|
-
export declare const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { NinetailedPluginOptions } from '../plugin-options';
|
|
2
|
+
export declare const serializePluginOptionFunctions: (pluginOptions: NinetailedPluginOptions) => {
|
|
3
|
+
serializedOptionFunctions: {};
|
|
4
|
+
serializedOptionFunctionNames: string[];
|
|
5
|
+
serializedCustomOptionFunctions: {};
|
|
6
|
+
serializedCustomOptionFunctionNames: string[];
|
|
6
7
|
};
|