@ninetailed/experience.js-gatsby 4.2.3 → 4.3.0-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/gatsby-browser.js CHANGED
@@ -2,9 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var serialize = require('./serialize.js');
6
5
  var React = require('react');
7
- var experience_js = require('@ninetailed/experience.js');
8
6
  var experience_jsReact = require('@ninetailed/experience.js-react');
9
7
  var Tracker = require('./Tracker.js');
10
8
  var loaders_ninetailedPlugins = require('./loaders/ninetailed-plugins.js');
@@ -16,54 +14,45 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
16
14
 
17
15
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
18
16
 
19
- let ninetailed;
17
+ /******************************************************************************
18
+ Copyright (c) Microsoft Corporation.
19
+
20
+ Permission to use, copy, modify, and/or distribute this software for any
21
+ purpose with or without fee is hereby granted.
22
+
23
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
24
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
25
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
26
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
27
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
28
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
29
+ PERFORMANCE OF THIS SOFTWARE.
30
+ ***************************************************************************** */
31
+
32
+ function __rest(s, e) {
33
+ var t = {};
34
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
35
+ t[p] = s[p];
36
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
37
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
38
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
39
+ t[p[i]] = s[p[i]];
40
+ }
41
+ return t;
42
+ }
43
+
20
44
  const WrapRootElement = _a => {
21
45
  var {
22
46
  children
23
47
  } = _a,
24
- options = serialize.__rest(_a, ["children"]);
25
- if (!ninetailed) {
26
- const resolvedPlugins = loaders_ninetailedPlugins.plugins.map(({
27
- PluginCtor,
28
- options
29
- }) => {
30
- if (!options) {
31
- return new PluginCtor();
32
- }
33
- if (options && !options.serializedFunctionNames) {
34
- return new PluginCtor(options);
35
- }
36
- const updatedOptions = Object.assign(Object.assign({}, options), serialize.deserializePluginOptionFns(options));
37
- return new PluginCtor(updatedOptions);
38
- });
39
- const {
40
- clientId,
41
- environment,
42
- preview,
43
- url,
44
- profile,
45
- locale,
46
- requestTimeout,
47
- onLog,
48
- onError
49
- } = options;
50
- ninetailed = new experience_js.Ninetailed({
51
- clientId,
52
- environment,
53
- preview
54
- }, {
55
- url,
56
- plugins: resolvedPlugins,
57
- profile,
58
- locale,
59
- requestTimeout,
60
- onLog,
61
- onError
62
- });
63
- }
64
- return /*#__PURE__*/React__default["default"].createElement(experience_jsReact.NinetailedProvider, {
65
- ninetailed: ninetailed
66
- }, /*#__PURE__*/React__default["default"].createElement(Tracker.Tracker, null), children);
48
+ options = __rest(_a, ["children"]);
49
+ const resolvedPlugins = loaders_ninetailedPlugins.plugins.map(({
50
+ PluginCtor,
51
+ options
52
+ }) => new PluginCtor(options));
53
+ return /*#__PURE__*/React__default["default"].createElement(experience_jsReact.NinetailedProvider, Object.assign({}, options, {
54
+ plugins: resolvedPlugins
55
+ }), /*#__PURE__*/React__default["default"].createElement(Tracker.Tracker, null), children);
67
56
  };
68
57
  const wrapRootElement = (args, options) => {
69
58
  const {
package/gatsby-node.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { CreatePagesArgs, CreateWebpackConfigArgs, PluginOptionsSchemaArgs } from 'gatsby';
1
+ import { PluginOptionsSchemaArgs, CreateWebpackConfigArgs } from 'gatsby';
2
2
  import { ObjectSchema } from 'gatsby-plugin-utils';
3
3
  import { PluginOptions } from './plugin-options';
4
4
  export declare const pluginOptionsSchema: ({ Joi, }: PluginOptionsSchemaArgs) => ObjectSchema<any>;
@@ -6,4 +6,3 @@ export declare const pluginOptionsSchema: ({ Joi, }: PluginOptionsSchemaArgs) =>
6
6
  * Add the webpack config for loading MDX files
7
7
  */
8
8
  export declare const onCreateWebpackConfig: ({ loaders, actions }: CreateWebpackConfigArgs, pluginOptions: PluginOptions) => void;
9
- export declare const createPages: ({ actions, store, graphql, }: CreatePagesArgs) => Promise<void>;
package/gatsby-node.js CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var serialize = require('./serialize.js');
6
5
  var require$$0 = require('path');
7
6
 
8
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -48,89 +47,6 @@ const onCreateWebpackConfig = ({
48
47
  }
49
48
  });
50
49
  };
51
- const createPages = ({
52
- actions,
53
- store,
54
- graphql
55
- }) => serialize.__awaiter(void 0, void 0, void 0, function* () {
56
- const ninetailedGatsbyPlugin = store.getState().flattenedPlugins.find(plugin => plugin.name === '@ninetailed/experience.js-gatsby');
57
- if (!ninetailedGatsbyPlugin) {
58
- return;
59
- }
60
- const pluginOptions = ninetailedGatsbyPlugin.pluginOptions || {};
61
- const {
62
- ninetailedPlugins = []
63
- } = pluginOptions;
64
- const ninetailedPreviewPlugin = ninetailedPlugins.find(plugin => plugin.name === '@ninetailed/experience.js-plugin-preview');
65
- if (!ninetailedPreviewPlugin) {
66
- return;
67
- }
68
- const {
69
- setPluginStatus
70
- } = actions;
71
- if (typeof ninetailedPreviewPlugin.options !== 'object' || typeof ninetailedPreviewPlugin.options.customOptions !== 'object') {
72
- throw new Error('CustomOptions not found. CustomOptions are mandatory and need to be set in the preview plugin options.');
73
- }
74
- const {
75
- audienceQuery,
76
- experienceQuery,
77
- audienceMapper,
78
- experienceMapper
79
- } = ninetailedPreviewPlugin.options.customOptions;
80
- const audienceOptionsSet = audienceQuery && audienceMapper;
81
- const experienceOptionsSet = experienceQuery && experienceMapper;
82
- const passThroughReturn = {
83
- errors: null,
84
- data: null
85
- };
86
- if (!audienceOptionsSet) {
87
- console.warn('No audience query or mapper found. Please provide both to process audience data.');
88
- }
89
- const {
90
- errors: audienceErrors,
91
- data: audienceData
92
- } = audienceOptionsSet ? yield graphql(audienceQuery) : passThroughReturn;
93
- if (!experienceOptionsSet) {
94
- console.warn('No experience query or mapper found. Please provide both to process experience data.');
95
- }
96
- const {
97
- errors: experienceErrors,
98
- data: experienceData
99
- } = experienceOptionsSet ? yield graphql(experienceQuery) : passThroughReturn;
100
- if (audienceErrors) {
101
- throw new Error('Failed to query audience data. Check query configuration or data retrieval by the source plugin.');
102
- }
103
- const audiences = audienceOptionsSet ? audienceMapper(audienceData) : [];
104
- if (experienceErrors) {
105
- throw new Error('Failed to query experience data. Check query configuration or data retrieval by the source plugin.');
106
- }
107
- const experiences = experienceOptionsSet ? experienceMapper(experienceData) : [];
108
- const ninetailedPluginsOverride = ninetailedGatsbyPlugin.pluginOptions.ninetailedPlugins.map(plugin => {
109
- const pluginOptions = plugin.options;
110
- if (!pluginOptions) {
111
- return plugin;
112
- }
113
- const {
114
- serializedFunctions,
115
- serializedFunctionNames
116
- } = serialize.serializePluginOptionFns(pluginOptions);
117
- return Object.assign(Object.assign({}, plugin), {
118
- options: Object.assign(Object.assign(Object.assign(Object.assign({}, plugin.options), serializedFunctions), {
119
- serializedFunctionNames
120
- }), plugin.name === '@ninetailed/experience.js-plugin-preview' && {
121
- audiences,
122
- experiences
123
- })
124
- });
125
- });
126
- ninetailedGatsbyPlugin.pluginOptions = Object.assign(Object.assign({}, ninetailedGatsbyPlugin.pluginOptions), {
127
- ninetailedPlugins: ninetailedPluginsOverride
128
- });
129
- setPluginStatus({
130
- pluginOptions: ninetailedGatsbyPlugin.pluginOptions
131
- }, ninetailedGatsbyPlugin);
132
- });
133
50
 
134
- exports.createPages = createPages;
135
51
  exports.onCreateWebpackConfig = onCreateWebpackConfig;
136
52
  exports.pluginOptionsSchema = pluginOptionsSchema;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ninetailed/experience.js-gatsby",
3
- "version": "4.2.3",
3
+ "version": "4.3.0-beta.0",
4
4
  "keywords": [
5
5
  "gatsby",
6
6
  "gatsby-plugin",
@@ -18,8 +18,7 @@
18
18
  "type": "commonjs",
19
19
  "types": "./index.d.ts",
20
20
  "dependencies": {
21
- "@ninetailed/experience.js": "4.2.3",
22
- "@ninetailed/experience.js-react": "4.2.3",
21
+ "@ninetailed/experience.js-react": "4.3.0-beta.0",
23
22
  "gatsby-plugin-utils": "3.19.0"
24
23
  }
25
24
  }
@@ -1,17 +1,8 @@
1
1
  import type { PluginOptions as GatsbyPluginOptions } from 'gatsby';
2
- import type { NinetailedProviderInstantiationProps } from '@ninetailed/experience.js-react';
3
- export type PluginOptions = GatsbyPluginOptions & NinetailedProviderInstantiationProps & {
2
+ import type { NinetailedProviderProps } from '@ninetailed/experience.js-react';
3
+ export type PluginOptions = GatsbyPluginOptions & NinetailedProviderProps & {
4
4
  ninetailedPlugins?: {
5
5
  resolve: string;
6
6
  options: unknown;
7
7
  }[];
8
8
  };
9
- export type NinetailedPluginOptions = Record<string, unknown>;
10
- export type SerializedFunctions = {
11
- serializedFunctionNames: string[];
12
- };
13
- export type ResolvedPluginOptions = Record<string, unknown> & SerializedFunctions;
14
- export type ResolvedPlugin = {
15
- PluginCtor: any;
16
- options?: ResolvedPluginOptions;
17
- };
package/serialize.js DELETED
@@ -1,80 +0,0 @@
1
- 'use strict';
2
-
3
- /******************************************************************************
4
- Copyright (c) Microsoft Corporation.
5
-
6
- Permission to use, copy, modify, and/or distribute this software for any
7
- purpose with or without fee is hereby granted.
8
-
9
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
- PERFORMANCE OF THIS SOFTWARE.
16
- ***************************************************************************** */
17
-
18
- function __rest(s, e) {
19
- var t = {};
20
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
21
- t[p] = s[p];
22
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
23
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
24
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
25
- t[p[i]] = s[p[i]];
26
- }
27
- return t;
28
- }
29
-
30
- function __awaiter(thisArg, _arguments, P, generator) {
31
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
32
- return new (P || (P = Promise))(function (resolve, reject) {
33
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
34
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
35
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
36
- step((generator = generator.apply(thisArg, _arguments || [])).next());
37
- });
38
- }
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
- exports.__awaiter = __awaiter;
78
- exports.__rest = __rest;
79
- exports.deserializePluginOptionFns = deserializePluginOptionFns;
80
- exports.serializePluginOptionFns = serializePluginOptionFns;
@@ -1,6 +0,0 @@
1
- import { NinetailedPluginOptions, ResolvedPluginOptions } from '../plugin-options';
2
- export declare const deserializePluginOptionFns: (options: ResolvedPluginOptions) => Record<string, (...args: unknown[]) => void>;
3
- export declare const serializePluginOptionFns: (pluginOptions: NinetailedPluginOptions) => {
4
- serializedFunctions: {};
5
- serializedFunctionNames: string[];
6
- };