@ninetailed/experience.js-gatsby 4.2.0-beta.8 → 4.2.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/_tslib.js ADDED
@@ -0,0 +1,41 @@
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
+ exports.__awaiter = __awaiter;
41
+ exports.__rest = __rest;
package/gatsby-browser.js CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var _tslib = require('./_tslib.js');
5
6
  var React = require('react');
7
+ var experience_js = require('@ninetailed/experience.js');
6
8
  var experience_jsReact = require('@ninetailed/experience.js-react');
7
9
  var Tracker = require('./Tracker.js');
8
10
  var loaders_ninetailedPlugins = require('./loaders/ninetailed-plugins.js');
@@ -14,45 +16,45 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
14
16
 
15
17
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
16
18
 
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
-
19
+ let ninetailed;
44
20
  const WrapRootElement = _a => {
45
21
  var {
46
22
  children
47
23
  } = _a,
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);
24
+ options = _tslib.__rest(_a, ["children"]);
25
+ if (!ninetailed) {
26
+ const resolvedPlugins = loaders_ninetailedPlugins.plugins.map(({
27
+ PluginCtor,
28
+ options
29
+ }) => new PluginCtor(options));
30
+ const {
31
+ clientId,
32
+ environment,
33
+ preview,
34
+ url,
35
+ profile,
36
+ locale,
37
+ requestTimeout,
38
+ onLog,
39
+ onError
40
+ } = options;
41
+ ninetailed = new experience_js.Ninetailed({
42
+ clientId,
43
+ environment,
44
+ preview
45
+ }, {
46
+ url,
47
+ plugins: resolvedPlugins,
48
+ profile,
49
+ locale,
50
+ requestTimeout,
51
+ onLog,
52
+ onError
53
+ });
54
+ }
55
+ return /*#__PURE__*/React__default["default"].createElement(experience_jsReact.NinetailedProvider, {
56
+ ninetailed: ninetailed
57
+ }, /*#__PURE__*/React__default["default"].createElement(Tracker.Tracker, null), children);
56
58
  };
57
59
  const wrapRootElement = (args, options) => {
58
60
  const {
package/gatsby-node.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { PluginOptionsSchemaArgs, CreateWebpackConfigArgs } from 'gatsby';
1
+ import { PluginOptionsSchemaArgs, CreateWebpackConfigArgs, CreatePagesArgs } 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,3 +6,4 @@ 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,6 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var _tslib = require('./_tslib.js');
5
6
  var require$$0 = require('path');
6
7
 
7
8
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -47,6 +48,72 @@ const onCreateWebpackConfig = ({
47
48
  }
48
49
  });
49
50
  };
51
+ const createPages = ({
52
+ actions,
53
+ store,
54
+ graphql
55
+ }) => _tslib.__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
+ const {
59
+ setPluginStatus
60
+ } = actions;
61
+ const ninetailedPreviewPlugin = ninetailedGatsbyPlugin.pluginOptions.ninetailedPlugins.find(plugin => plugin.name === '@ninetailed/experience.js-plugin-preview');
62
+ if (!ninetailedPreviewPlugin.options.customOptions) {
63
+ throw new Error('CustomOptions not found. CustomOptions are mandatory and need to be set in the preview plugin options.');
64
+ }
65
+ const {
66
+ audienceQuery,
67
+ experienceQuery,
68
+ audienceMapper,
69
+ experienceMapper
70
+ } = ninetailedPreviewPlugin.options.customOptions;
71
+ const audienceOptionsSet = audienceQuery && audienceMapper;
72
+ const experienceOptionsSet = experienceQuery && experienceMapper;
73
+ const passThroughReturn = {
74
+ errors: null,
75
+ data: null
76
+ };
77
+ if (!audienceOptionsSet) {
78
+ console.warn('No audience query or mapper found. Please provide both to process audience data.');
79
+ }
80
+ const {
81
+ errors: audienceErrors,
82
+ data: audienceData
83
+ } = audienceOptionsSet ? yield graphql(audienceQuery) : passThroughReturn;
84
+ if (!experienceOptionsSet) {
85
+ console.warn('No experience query or mapper found. Please provide both to process experience data.');
86
+ }
87
+ const {
88
+ errors: experienceErrors,
89
+ data: experienceData
90
+ } = experienceOptionsSet ? yield graphql(experienceQuery) : passThroughReturn;
91
+ if (audienceErrors) {
92
+ throw new Error('Failed to query audience data. Check query configuration or data retrieval by the source plugin.');
93
+ }
94
+ const audiences = audienceOptionsSet ? audienceMapper(audienceData) : [];
95
+ if (experienceErrors) {
96
+ throw new Error('Failed to query experience data. Check query configuration or data retrieval by the source plugin.');
97
+ }
98
+ const experiences = experienceOptionsSet ? experienceMapper(experienceData) : [];
99
+ const ninetailedPreviewPluginOverride = Object.assign(Object.assign({}, ninetailedPreviewPlugin), {
100
+ options: Object.assign(Object.assign({}, ninetailedPreviewPlugin.options), {
101
+ audiences,
102
+ experiences
103
+ })
104
+ });
105
+ const ninetailedPluginsOverwrite = ninetailedGatsbyPlugin.pluginOptions.ninetailedPlugins.map(plugin => {
106
+ return plugin === ninetailedPreviewPlugin ? ninetailedPreviewPluginOverride : plugin;
107
+ });
108
+ ninetailedGatsbyPlugin.pluginOptions = Object.assign(Object.assign({}, ninetailedGatsbyPlugin.pluginOptions), {
109
+ ninetailedPlugins: ninetailedPluginsOverwrite
110
+ });
111
+ setPluginStatus({
112
+ pluginOptions: ninetailedGatsbyPlugin.pluginOptions
113
+ }, ninetailedGatsbyPlugin);
114
+ }
115
+ });
50
116
 
117
+ exports.createPages = createPages;
51
118
  exports.onCreateWebpackConfig = onCreateWebpackConfig;
52
119
  exports.pluginOptionsSchema = pluginOptionsSchema;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ninetailed/experience.js-gatsby",
3
- "version": "4.2.0-beta.8",
3
+ "version": "4.2.0",
4
4
  "keywords": [
5
5
  "gatsby",
6
6
  "gatsby-plugin",
@@ -18,7 +18,8 @@
18
18
  "type": "commonjs",
19
19
  "types": "./index.d.ts",
20
20
  "dependencies": {
21
- "@ninetailed/experience.js-react": "4.2.0-beta.8",
21
+ "@ninetailed/experience.js": "4.2.0",
22
+ "@ninetailed/experience.js-react": "4.2.0",
22
23
  "gatsby-plugin-utils": "3.19.0"
23
24
  }
24
25
  }
@@ -1,6 +1,6 @@
1
1
  import type { PluginOptions as GatsbyPluginOptions } from 'gatsby';
2
- import type { NinetailedProviderProps } from '@ninetailed/experience.js-react';
3
- export type PluginOptions = GatsbyPluginOptions & NinetailedProviderProps & {
2
+ import type { NinetailedProviderInstantiationProps } from '@ninetailed/experience.js-react';
3
+ export type PluginOptions = GatsbyPluginOptions & NinetailedProviderInstantiationProps & {
4
4
  ninetailedPlugins?: {
5
5
  resolve: string;
6
6
  options: unknown;