@streamlayer/sdk-web-features 0.10.37 → 0.11.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/lib/index.d.ts CHANGED
@@ -1,15 +1,14 @@
1
1
  import { FeatureType } from '@streamlayer/sdk-web-types';
2
2
  import { AbstractFeature, FeatureSource, FeatureProps, StreamLayerContext, SingleStore } from '@streamlayer/sdk-web-interfaces';
3
- import { Highlights, Gamification } from '@streamlayer/feature-gamification';
4
- export type Features = Feature | Gamification | Highlights;
3
+ import { Gamification } from '@streamlayer/feature-gamification';
4
+ export type Features = Feature | Gamification;
5
5
  export declare const AvailableFeatures: {
6
6
  12: boolean;
7
- 14: boolean;
8
7
  };
9
8
  export declare class Feature extends AbstractFeature<undefined> {
10
9
  constructor(overlay: FeatureProps, source: FeatureSource);
11
10
  }
12
- export declare const initFeature: (overlay: FeatureProps, source: FeatureSource, instance: StreamLayerContext) => Feature | Gamification | Highlights;
11
+ export declare const initFeature: (overlay: FeatureProps, source: FeatureSource, instance: StreamLayerContext) => Feature | Gamification;
13
12
  export { FeatureSource } from '@streamlayer/sdk-web-interfaces';
14
13
  declare module '@streamlayer/sdk-web-interfaces' {
15
14
  interface StreamLayerContext {
@@ -22,9 +21,9 @@ declare module '@streamlayer/sdk-web-interfaces' {
22
21
  }
23
22
  interface StreamLayerSDK {
24
23
  getFeatures: () => Map<FeatureType, Features>;
25
- getFeature: <T extends FeatureType = FeatureType>(featureType: T) => (T extends FeatureType.GAMES ? Gamification : T extends FeatureType.HIGHLIGHTS ? Highlights : Feature) | undefined;
24
+ getFeature: <T extends FeatureType = FeatureType>(featureType: T) => (T extends FeatureType.GAMES ? Gamification : Feature) | undefined;
26
25
  getActiveFeature: SingleStore<FeatureType>['getStore'];
27
- closeFeature: () => void;
26
+ closeFeature: (destroy?: boolean) => void;
28
27
  }
29
28
  }
30
29
  export declare const features: (instance: StreamLayerContext, opts: unknown, done: () => void) => void;
package/lib/index.js CHANGED
@@ -1,9 +1,8 @@
1
1
  import { FeatureType } from '@streamlayer/sdk-web-types';
2
2
  import { AbstractFeature, FeatureSource, SingleStore, createSingleStore, } from '@streamlayer/sdk-web-interfaces';
3
- import { Highlights, Gamification } from '@streamlayer/feature-gamification';
3
+ import { Gamification } from '@streamlayer/feature-gamification';
4
4
  export const AvailableFeatures = {
5
5
  [FeatureType.GAMES]: true,
6
- [FeatureType.HIGHLIGHTS]: true,
7
6
  };
8
7
  export class Feature extends AbstractFeature {
9
8
  constructor(overlay, source) {
@@ -14,9 +13,6 @@ export const initFeature = (overlay, source, instance) => {
14
13
  if (overlay.type === FeatureType.GAMES) {
15
14
  return new Gamification(overlay, source, instance);
16
15
  }
17
- if (overlay.type === FeatureType.HIGHLIGHTS) {
18
- return new Highlights(overlay, source, instance);
19
- }
20
16
  return new Feature(overlay, source);
21
17
  };
22
18
  export { FeatureSource } from '@streamlayer/sdk-web-interfaces';
@@ -31,15 +27,23 @@ export const features = (instance, opts, done) => {
31
27
  instance.sdk.openFeature = (featureType) => {
32
28
  instance.activeFeature.setValue(featureType);
33
29
  };
34
- instance.sdk.closeFeature = () => {
35
- instance.activeFeature.setValue(FeatureType.UNSET);
30
+ instance.sdk.closeFeature = (destroy = false) => {
31
+ if (destroy) {
32
+ const activeFeature = instance.activeFeature.getValue();
33
+ instance.activeFeature.setValue(FeatureType.UNSET);
34
+ if (activeFeature) {
35
+ instance.features.delete(activeFeature);
36
+ }
37
+ }
36
38
  };
37
39
  /**
38
40
  * A distinct object instance is created and initialized for each overlay.
39
41
  */
40
42
  instance.initFeature = (overlay, source = FeatureSource.ORGANIZATION) => {
41
- const feature = initFeature(overlay, source, instance);
42
- instance.features.set(overlay.type, feature);
43
+ if (overlay.type in AvailableFeatures && !instance.features.has(overlay.type)) {
44
+ const feature = initFeature(overlay, source, instance);
45
+ instance.features.set(overlay.type, feature);
46
+ }
43
47
  };
44
48
  instance.updateFeature = (overlay, source) => {
45
49
  instance.features.get(overlay.type)?.update(overlay, source);
@@ -72,9 +76,9 @@ export const features = (instance, opts, done) => {
72
76
  const processSettings = (source, settings) => {
73
77
  if (!settings?.overlays)
74
78
  return;
75
- if (source === FeatureSource.STREAM) {
76
- instance.features.clear();
77
- }
79
+ // initialize features only for stream settings, wait stream settings to avoid unnecessary initialization
80
+ if (instance.contextConfig?.skipOrganizationSettings && source === FeatureSource.ORGANIZATION)
81
+ return;
78
82
  for (const overlay of settings.overlays) {
79
83
  if (overlay.sdkEnable !== true) {
80
84
  continue;
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@streamlayer/sdk-web-features",
3
3
  "peerDependencies": {
4
- "@streamlayer/sdk-web-interfaces": "^0.0.1",
4
+ "@streamlayer/sdk-web-interfaces": "^0.1.0",
5
5
  "@streamlayer/sdk-web-types": "^0.1.0",
6
- "@streamlayer/feature-gamification": "^0.29.0",
7
- "@streamlayer/sdk-web-core": "^0.0.7"
6
+ "@streamlayer/feature-gamification": "^0.30.0",
7
+ "@streamlayer/sdk-web-core": "^0.1.0"
8
8
  },
9
9
  "devDependencies": {
10
10
  "tslib": "^2.6.2"
11
11
  },
12
- "version": "0.10.37",
12
+ "version": "0.11.0",
13
13
  "type": "module",
14
14
  "main": "./lib/index.js",
15
15
  "typings": "./lib/index.d.ts",