@ninetailed/experience.js-plugin-preview 3.0.0-beta.32 → 3.0.0-beta.34

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/index.cjs CHANGED
@@ -3,6 +3,8 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var union = require('lodash/union');
6
+ var experience_jsPluginAnalytics = require('@ninetailed/experience.js-plugin-analytics');
7
+ var experience_js = require('@ninetailed/experience.js');
6
8
 
7
9
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
10
 
@@ -2378,38 +2380,33 @@ class WidgetContainer {
2378
2380
  }
2379
2381
  }
2380
2382
 
2381
- const NinetailedPreviewPlugin = ({
2382
- clientId,
2383
- secret,
2384
- url,
2385
- environment,
2386
- ui
2387
- }) => {
2388
- let isOpen = false;
2389
- let activatedAudiences = [];
2390
- let audiences = [];
2391
- let lastProfile;
2392
- return {
2393
- name: 'ninetailed:preview' + Math.random(),
2394
- config: {},
2395
- initialize: ({
2383
+ var _a;
2384
+ class NinetailedPreviewPlugin extends experience_jsPluginAnalytics.NinetailedPlugin {
2385
+ constructor(options) {
2386
+ super();
2387
+ this.options = options;
2388
+ this.name = 'ninetailed:preview' + Math.random();
2389
+ this.isOpen = false;
2390
+ this.activatedAudiences = [];
2391
+ this.audiences = [];
2392
+ this.initialize = ({
2396
2393
  instance
2397
- }) => __awaiter(void 0, void 0, void 0, function* () {
2398
- var _a;
2394
+ }) => __awaiter(this, void 0, void 0, function* () {
2395
+ var _b;
2399
2396
  if (typeof window !== 'undefined') {
2400
2397
  const {
2401
2398
  PreviewBridge
2402
2399
  } = yield Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@ninetailed/experience.js-preview-bridge')); });
2403
2400
  const container = new WidgetContainer({
2404
- ui
2401
+ ui: this.options.ui
2405
2402
  });
2406
2403
  const preview = PreviewBridge({
2407
- url
2404
+ url: this.options.url
2408
2405
  });
2409
2406
  preview.render(container.element);
2410
2407
  const open = () => {
2411
2408
  container.open();
2412
- isOpen = true;
2409
+ this.isOpen = true;
2413
2410
  instance.dispatch({
2414
2411
  type: 'preview:change'
2415
2412
  });
@@ -2417,59 +2414,59 @@ const NinetailedPreviewPlugin = ({
2417
2414
  const close = () => {
2418
2415
  container.close();
2419
2416
  setTimeout(() => {
2420
- isOpen = false;
2417
+ this.isOpen = false;
2421
2418
  instance.dispatch({
2422
2419
  type: 'preview:change'
2423
2420
  });
2424
2421
  }, 700);
2425
2422
  };
2426
2423
  const toggle = () => {
2427
- if (isOpen) {
2424
+ if (this.isOpen) {
2428
2425
  close();
2429
2426
  } else {
2430
2427
  open();
2431
2428
  }
2432
2429
  };
2433
2430
  const activateAudience = id => {
2434
- activatedAudiences = union__default["default"](activatedAudiences, [id]);
2431
+ this.activatedAudiences = union__default["default"](this.activatedAudiences, [id]);
2435
2432
  instance.dispatch({
2436
- type: 'profile',
2437
- profile: lastProfile
2433
+ type: experience_js.PROFILE_CHANGE,
2434
+ profile: this.lastProfile
2438
2435
  });
2439
2436
  };
2440
2437
  const deactivateAudience = id => {
2441
- activatedAudiences = activatedAudiences.filter(activatedAudience => activatedAudience !== id);
2438
+ this.activatedAudiences = this.activatedAudiences.filter(activatedAudience => activatedAudience !== id);
2442
2439
  instance.dispatch({
2443
- type: 'profile',
2444
- profile: lastProfile
2440
+ type: experience_js.PROFILE_CHANGE,
2441
+ profile: this.lastProfile
2445
2442
  });
2446
2443
  };
2447
2444
  const buildPreviewPlugin = () => ({
2448
2445
  open: () => open(),
2449
2446
  close: () => close(),
2450
2447
  toggle: () => toggle(),
2451
- isOpen,
2448
+ isOpen: this.isOpen,
2452
2449
  activateAudience: id => activateAudience(id),
2453
2450
  deactivateAudience: id => deactivateAudience(id),
2454
- activatedAudiences,
2455
- audiences
2451
+ activatedAudiences: this.activatedAudiences,
2452
+ audiences: this.audiences
2456
2453
  });
2457
2454
  window.ninetailed = Object.assign({}, window.ninetailed, {
2458
- plugins: Object.assign(Object.assign({}, (_a = window.ninetailed) === null || _a === void 0 ? void 0 : _a.plugins), {
2455
+ plugins: Object.assign(Object.assign({}, (_b = window.ninetailed) === null || _b === void 0 ? void 0 : _b.plugins), {
2459
2456
  preview: buildPreviewPlugin()
2460
2457
  })
2461
2458
  });
2462
2459
  const buildNinetailed = () => {
2463
- var _a;
2460
+ var _b;
2464
2461
  return Object.assign({}, window.ninetailed, {
2465
2462
  version: '1.5.1',
2466
- plugins: Object.assign(Object.assign({}, (_a = window.ninetailed) === null || _a === void 0 ? void 0 : _a.plugins), {
2463
+ plugins: Object.assign(Object.assign({}, (_b = window.ninetailed) === null || _b === void 0 ? void 0 : _b.plugins), {
2467
2464
  preview: buildPreviewPlugin()
2468
2465
  }),
2469
2466
  credentials: {
2470
- clientId,
2471
- secret,
2472
- environment
2467
+ clientId: this.options.clientId,
2468
+ secret: this.options.secret,
2469
+ environment: this.options.environment
2473
2470
  }
2474
2471
  });
2475
2472
  };
@@ -2484,22 +2481,23 @@ const NinetailedPreviewPlugin = ({
2484
2481
  });
2485
2482
  });
2486
2483
  }
2487
- }),
2488
- profile: ({
2484
+ });
2485
+ this.loaded = () => true;
2486
+ this[_a] = ({
2489
2487
  payload
2490
2488
  }) => {
2491
- var _a;
2492
- audiences = ((_a = payload === null || payload === void 0 ? void 0 : payload.profile) === null || _a === void 0 ? void 0 : _a.audiences) || [];
2493
- lastProfile = payload.profile;
2489
+ var _b;
2490
+ this.audiences = ((_b = payload === null || payload === void 0 ? void 0 : payload.profile) === null || _b === void 0 ? void 0 : _b.audiences) || [];
2491
+ this.lastProfile = payload.profile;
2494
2492
  return Object.assign(Object.assign({}, payload), {
2495
2493
  profile: Object.assign(Object.assign({}, payload.profile), {
2496
- audiences: union__default["default"](audiences, activatedAudiences)
2494
+ audiences: union__default["default"](this.audiences, this.activatedAudiences)
2497
2495
  })
2498
2496
  });
2499
- },
2500
- loaded: () => true
2501
- };
2502
- };
2497
+ };
2498
+ }
2499
+ }
2500
+ _a = experience_js.PROFILE_CHANGE;
2503
2501
 
2504
2502
  if (typeof window === 'object' && !('process' in window)) {
2505
2503
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
package/index.js CHANGED
@@ -1,4 +1,6 @@
1
1
  import union from 'lodash/union';
2
+ import { NinetailedPlugin } from '@ninetailed/experience.js-plugin-analytics';
3
+ import { PROFILE_CHANGE } from '@ninetailed/experience.js';
2
4
 
3
5
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
4
6
 
@@ -2352,38 +2354,33 @@ class WidgetContainer {
2352
2354
  }
2353
2355
  }
2354
2356
 
2355
- const NinetailedPreviewPlugin = ({
2356
- clientId,
2357
- secret,
2358
- url,
2359
- environment,
2360
- ui
2361
- }) => {
2362
- let isOpen = false;
2363
- let activatedAudiences = [];
2364
- let audiences = [];
2365
- let lastProfile;
2366
- return {
2367
- name: 'ninetailed:preview' + Math.random(),
2368
- config: {},
2369
- initialize: ({
2357
+ var _a;
2358
+ class NinetailedPreviewPlugin extends NinetailedPlugin {
2359
+ constructor(options) {
2360
+ super();
2361
+ this.options = options;
2362
+ this.name = 'ninetailed:preview' + Math.random();
2363
+ this.isOpen = false;
2364
+ this.activatedAudiences = [];
2365
+ this.audiences = [];
2366
+ this.initialize = ({
2370
2367
  instance
2371
- }) => __awaiter(void 0, void 0, void 0, function* () {
2372
- var _a;
2368
+ }) => __awaiter(this, void 0, void 0, function* () {
2369
+ var _b;
2373
2370
  if (typeof window !== 'undefined') {
2374
2371
  const {
2375
2372
  PreviewBridge
2376
2373
  } = yield import('@ninetailed/experience.js-preview-bridge');
2377
2374
  const container = new WidgetContainer({
2378
- ui
2375
+ ui: this.options.ui
2379
2376
  });
2380
2377
  const preview = PreviewBridge({
2381
- url
2378
+ url: this.options.url
2382
2379
  });
2383
2380
  preview.render(container.element);
2384
2381
  const open = () => {
2385
2382
  container.open();
2386
- isOpen = true;
2383
+ this.isOpen = true;
2387
2384
  instance.dispatch({
2388
2385
  type: 'preview:change'
2389
2386
  });
@@ -2391,59 +2388,59 @@ const NinetailedPreviewPlugin = ({
2391
2388
  const close = () => {
2392
2389
  container.close();
2393
2390
  setTimeout(() => {
2394
- isOpen = false;
2391
+ this.isOpen = false;
2395
2392
  instance.dispatch({
2396
2393
  type: 'preview:change'
2397
2394
  });
2398
2395
  }, 700);
2399
2396
  };
2400
2397
  const toggle = () => {
2401
- if (isOpen) {
2398
+ if (this.isOpen) {
2402
2399
  close();
2403
2400
  } else {
2404
2401
  open();
2405
2402
  }
2406
2403
  };
2407
2404
  const activateAudience = id => {
2408
- activatedAudiences = union(activatedAudiences, [id]);
2405
+ this.activatedAudiences = union(this.activatedAudiences, [id]);
2409
2406
  instance.dispatch({
2410
- type: 'profile',
2411
- profile: lastProfile
2407
+ type: PROFILE_CHANGE,
2408
+ profile: this.lastProfile
2412
2409
  });
2413
2410
  };
2414
2411
  const deactivateAudience = id => {
2415
- activatedAudiences = activatedAudiences.filter(activatedAudience => activatedAudience !== id);
2412
+ this.activatedAudiences = this.activatedAudiences.filter(activatedAudience => activatedAudience !== id);
2416
2413
  instance.dispatch({
2417
- type: 'profile',
2418
- profile: lastProfile
2414
+ type: PROFILE_CHANGE,
2415
+ profile: this.lastProfile
2419
2416
  });
2420
2417
  };
2421
2418
  const buildPreviewPlugin = () => ({
2422
2419
  open: () => open(),
2423
2420
  close: () => close(),
2424
2421
  toggle: () => toggle(),
2425
- isOpen,
2422
+ isOpen: this.isOpen,
2426
2423
  activateAudience: id => activateAudience(id),
2427
2424
  deactivateAudience: id => deactivateAudience(id),
2428
- activatedAudiences,
2429
- audiences
2425
+ activatedAudiences: this.activatedAudiences,
2426
+ audiences: this.audiences
2430
2427
  });
2431
2428
  window.ninetailed = Object.assign({}, window.ninetailed, {
2432
- plugins: Object.assign(Object.assign({}, (_a = window.ninetailed) === null || _a === void 0 ? void 0 : _a.plugins), {
2429
+ plugins: Object.assign(Object.assign({}, (_b = window.ninetailed) === null || _b === void 0 ? void 0 : _b.plugins), {
2433
2430
  preview: buildPreviewPlugin()
2434
2431
  })
2435
2432
  });
2436
2433
  const buildNinetailed = () => {
2437
- var _a;
2434
+ var _b;
2438
2435
  return Object.assign({}, window.ninetailed, {
2439
2436
  version: '1.5.1',
2440
- plugins: Object.assign(Object.assign({}, (_a = window.ninetailed) === null || _a === void 0 ? void 0 : _a.plugins), {
2437
+ plugins: Object.assign(Object.assign({}, (_b = window.ninetailed) === null || _b === void 0 ? void 0 : _b.plugins), {
2441
2438
  preview: buildPreviewPlugin()
2442
2439
  }),
2443
2440
  credentials: {
2444
- clientId,
2445
- secret,
2446
- environment
2441
+ clientId: this.options.clientId,
2442
+ secret: this.options.secret,
2443
+ environment: this.options.environment
2447
2444
  }
2448
2445
  });
2449
2446
  };
@@ -2458,22 +2455,23 @@ const NinetailedPreviewPlugin = ({
2458
2455
  });
2459
2456
  });
2460
2457
  }
2461
- }),
2462
- profile: ({
2458
+ });
2459
+ this.loaded = () => true;
2460
+ this[_a] = ({
2463
2461
  payload
2464
2462
  }) => {
2465
- var _a;
2466
- audiences = ((_a = payload === null || payload === void 0 ? void 0 : payload.profile) === null || _a === void 0 ? void 0 : _a.audiences) || [];
2467
- lastProfile = payload.profile;
2463
+ var _b;
2464
+ this.audiences = ((_b = payload === null || payload === void 0 ? void 0 : payload.profile) === null || _b === void 0 ? void 0 : _b.audiences) || [];
2465
+ this.lastProfile = payload.profile;
2468
2466
  return Object.assign(Object.assign({}, payload), {
2469
2467
  profile: Object.assign(Object.assign({}, payload.profile), {
2470
- audiences: union(audiences, activatedAudiences)
2468
+ audiences: union(this.audiences, this.activatedAudiences)
2471
2469
  })
2472
2470
  });
2473
- },
2474
- loaded: () => true
2475
- };
2476
- };
2471
+ };
2472
+ }
2473
+ }
2474
+ _a = PROFILE_CHANGE;
2477
2475
 
2478
2476
  if (typeof window === 'object' && !('process' in window)) {
2479
2477
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -0,0 +1,33 @@
1
+ import { Credentials } from './types';
2
+ import { AnalyticsInstance, NinetailedPlugin } from '@ninetailed/experience.js-plugin-analytics';
3
+ import { PROFILE_CHANGE } from '@ninetailed/experience.js';
4
+ export declare const NINETAILED_PREVIEW_EVENTS: {
5
+ previewAudiences: string;
6
+ previewTraits: string;
7
+ };
8
+ declare type NinetailedPreviewPluginOptions = Credentials & {
9
+ url?: string;
10
+ environment?: string;
11
+ ui?: {
12
+ opener?: {
13
+ hide: boolean;
14
+ };
15
+ };
16
+ };
17
+ export declare class NinetailedPreviewPlugin extends NinetailedPlugin {
18
+ private readonly options;
19
+ name: string;
20
+ private isOpen;
21
+ private activatedAudiences;
22
+ private audiences;
23
+ private lastProfile?;
24
+ constructor(options: NinetailedPreviewPluginOptions);
25
+ initialize: ({ instance }: {
26
+ instance: AnalyticsInstance;
27
+ }) => Promise<void>;
28
+ loaded: () => boolean;
29
+ [PROFILE_CHANGE]: ({ payload }: {
30
+ payload: any;
31
+ }) => any;
32
+ }
33
+ export {};
@@ -1,2 +1,2 @@
1
- export * from './plugin';
1
+ export * from './NinetailedPreviewPlugin';
2
2
  export * from './types';
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@ninetailed/experience.js-plugin-preview",
3
- "version": "3.0.0-beta.32",
3
+ "version": "3.0.0-beta.34",
4
4
  "module": "./index.js",
5
5
  "main": "./index.cjs",
6
6
  "type": "module",
7
7
  "types": "./index.d.ts",
8
8
  "dependencies": {
9
- "analytics": "0.8.1",
10
- "@ninetailed/experience.js-shared": "3.0.0-beta.32",
9
+ "@ninetailed/experience.js-shared": "3.0.0-beta.34",
11
10
  "lodash": "4.17.21",
12
- "@ninetailed/experience.js-preview-bridge": "3.0.0-beta.32",
13
- "@ninetailed/experience.js": "3.0.0-beta.32"
11
+ "@ninetailed/experience.js-plugin-analytics": "0.0.1",
12
+ "@ninetailed/experience.js": "3.0.0-beta.34",
13
+ "@ninetailed/experience.js-preview-bridge": "3.0.0-beta.34"
14
14
  },
15
15
  "peerDependencies": {}
16
16
  }
@@ -1,17 +0,0 @@
1
- import { AnalyticsPlugin } from 'analytics';
2
- import { Credentials } from './types';
3
- export declare const NINETAILED_PREVIEW_EVENTS: {
4
- previewAudiences: string;
5
- previewTraits: string;
6
- };
7
- declare type NinetailedPreviewPluginOptions = Credentials & {
8
- url?: string;
9
- environment?: string;
10
- ui?: {
11
- opener?: {
12
- hide: boolean;
13
- };
14
- };
15
- };
16
- export declare const NinetailedPreviewPlugin: ({ clientId, secret, url, environment, ui, }: NinetailedPreviewPluginOptions) => AnalyticsPlugin;
17
- export {};