@streamlayer/sdk-web 0.16.0 → 0.17.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/package.json +1 -1
- package/src/core.d.ts +3 -0
- package/src/core.js +6 -4
- package/src/core.js.map +1 -1
- package/src/features/index.d.ts +4 -3
- package/src/features/index.js +21 -5
- package/src/features/index.js.map +1 -1
- package/src/keys.d.ts +2 -0
- package/src/keys.js +2 -0
- package/src/keys.js.map +1 -1
- package/src/store/index.js +24 -5
- package/src/store/index.js.map +1 -1
- package/src/store/store.d.ts +1 -1
package/package.json
CHANGED
package/src/core.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Feature } from './features';
|
|
1
2
|
/**
|
|
2
3
|
* The main application instance is the core of a application. It includes:
|
|
3
4
|
* Store: Manages data storage.
|
|
@@ -13,6 +14,7 @@ export declare class StreamLayerSDK {
|
|
|
13
14
|
* On initialize we subscribe to store and launch listeners
|
|
14
15
|
* that activate data downloading over the network
|
|
15
16
|
*/
|
|
17
|
+
getFeatures: () => Map<string, Feature>;
|
|
16
18
|
initializeApp: () => Promise<{
|
|
17
19
|
enabled: boolean;
|
|
18
20
|
err?: undefined;
|
|
@@ -21,6 +23,7 @@ export declare class StreamLayerSDK {
|
|
|
21
23
|
enabled?: undefined;
|
|
22
24
|
}>;
|
|
23
25
|
disableApp: () => void;
|
|
26
|
+
invalidateSettings: () => void;
|
|
24
27
|
/**
|
|
25
28
|
* Configure the "event id" using the "provider," enabling subscribed stores to
|
|
26
29
|
* trigger their logic in response to a new event.
|
package/src/core.js
CHANGED
|
@@ -11,10 +11,7 @@ import { CoreStatus } from './store/store';
|
|
|
11
11
|
* Security: Implements authentication and authorization.
|
|
12
12
|
*/ export class StreamLayerSDK {
|
|
13
13
|
constructor(){
|
|
14
|
-
|
|
15
|
-
* On initialize we subscribe to store and launch listeners
|
|
16
|
-
* that activate data downloading over the network
|
|
17
|
-
*/ this.initializeApp = async ()=>{
|
|
14
|
+
this.initializeApp = async ()=>{
|
|
18
15
|
this[kStoreSubscribe]();
|
|
19
16
|
this[kStore].getStoreItem('enabled').setValue('on');
|
|
20
17
|
this[kStore].getStoreItem('status').setValue(CoreStatus.INITIALIZATION);
|
|
@@ -43,6 +40,11 @@ import { CoreStatus } from './store/store';
|
|
|
43
40
|
this[kStore].getStoreItem('status').setValue(CoreStatus.DISABLED);
|
|
44
41
|
this[kStoreUnsubscribe]();
|
|
45
42
|
};
|
|
43
|
+
this.invalidateSettings = ()=>{
|
|
44
|
+
this.transport.nanoquery.utils.invalidateKeys(()=>{
|
|
45
|
+
return true;
|
|
46
|
+
});
|
|
47
|
+
};
|
|
46
48
|
/**
|
|
47
49
|
* Configure the "event id" using the "provider," enabling subscribed stores to
|
|
48
50
|
* trigger their logic in response to a new event.
|
package/src/core.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../packages/sdk-web/src/core.ts"],"sourcesContent":["import { kStore, kStoreSubscribe, kStoreUnsubscribe } from './keys'\nimport { CoreStatus } from './store/store'\n\n/**\n * The main application instance is the core of a application. It includes:\n * Store: Manages data storage.\n * Public Methods: Provides a way to interact with the application.\n * Connect Features: Handles communication between components throught store.\n * Connect Transport: Handles communication with api.\n * Dependency Injection: Incorporates other necessary instances.\n * Error Handling: Manages errors and logs them.\n * Security: Implements authentication and authorization.\n */\nexport class StreamLayerSDK {\n /**\n * On initialize we subscribe to store and launch listeners\n * that activate data downloading over the network\n */\n public initializeApp = async () => {\n this[kStoreSubscribe]()\n this[kStore].getStoreItem('enabled').setValue('on')\n this[kStore].getStoreItem('status').setValue(CoreStatus.INITIALIZATION)\n\n try {\n const organizationSettings = await this[kStore].getStoreItem('organizationSettings').getValue()\n\n if (organizationSettings) {\n this[kStore].getStoreItem('status').setValue(CoreStatus.READY)\n\n return { enabled: !!organizationSettings }\n }\n\n this[kStore].getStoreItem('status').setValue(CoreStatus.FAILED)\n\n return { err: 'failed' }\n } catch (err) {\n this[kStore].getStoreItem('enabled').setValue()\n this[kStore].getStoreItem('status').setValue(CoreStatus.FAILED)\n\n return { err }\n }\n }\n\n public disableApp = () => {\n this[kStore].getStoreItem('enabled').setValue()\n this[kStore].getStoreItem('status').setValue(CoreStatus.DISABLED)\n this[kStoreUnsubscribe]()\n }\n\n /**\n * Configure the \"event id\" using the \"provider,\" enabling subscribed stores to\n * trigger their logic in response to a new event.\n */\n public createEventSession = (providerStreamId: string) => {\n this[kStore].getStoreItem('providerStreamId').setValue(providerStreamId)\n }\n}\n"],"names":["kStore","kStoreSubscribe","kStoreUnsubscribe","CoreStatus","StreamLayerSDK","initializeApp","getStoreItem","setValue","INITIALIZATION","organizationSettings","getValue","READY","enabled","FAILED","err","disableApp","DISABLED","createEventSession","providerStreamId"],"mappings":"AAAA,SAASA,MAAM,EAAEC,eAAe,EAAEC,iBAAiB,QAAQ,SAAQ;AACnE,SAASC,UAAU,QAAQ,gBAAe;
|
|
1
|
+
{"version":3,"sources":["../../../../packages/sdk-web/src/core.ts"],"sourcesContent":["import { kStore, kStoreSubscribe, kStoreUnsubscribe } from './keys'\nimport { CoreStatus } from './store/store'\nimport { Feature } from './features'\n\n/**\n * The main application instance is the core of a application. It includes:\n * Store: Manages data storage.\n * Public Methods: Provides a way to interact with the application.\n * Connect Features: Handles communication between components throught store.\n * Connect Transport: Handles communication with api.\n * Dependency Injection: Incorporates other necessary instances.\n * Error Handling: Manages errors and logs them.\n * Security: Implements authentication and authorization.\n */\nexport class StreamLayerSDK {\n /**\n * On initialize we subscribe to store and launch listeners\n * that activate data downloading over the network\n */\n getFeatures: () => Map<string, Feature>\n\n public initializeApp = async () => {\n this[kStoreSubscribe]()\n this[kStore].getStoreItem('enabled').setValue('on')\n this[kStore].getStoreItem('status').setValue(CoreStatus.INITIALIZATION)\n\n try {\n const organizationSettings = await this[kStore].getStoreItem('organizationSettings').getValue()\n\n if (organizationSettings) {\n this[kStore].getStoreItem('status').setValue(CoreStatus.READY)\n\n return { enabled: !!organizationSettings }\n }\n\n this[kStore].getStoreItem('status').setValue(CoreStatus.FAILED)\n\n return { err: 'failed' }\n } catch (err) {\n this[kStore].getStoreItem('enabled').setValue()\n this[kStore].getStoreItem('status').setValue(CoreStatus.FAILED)\n\n return { err }\n }\n }\n\n public disableApp = () => {\n this[kStore].getStoreItem('enabled').setValue()\n this[kStore].getStoreItem('status').setValue(CoreStatus.DISABLED)\n this[kStoreUnsubscribe]()\n }\n\n public invalidateSettings = () => {\n this.transport.nanoquery.utils.invalidateKeys(() => {\n return true\n })\n }\n\n /**\n * Configure the \"event id\" using the \"provider,\" enabling subscribed stores to\n * trigger their logic in response to a new event.\n */\n public createEventSession = (providerStreamId: string) => {\n this[kStore].getStoreItem('providerStreamId').setValue(providerStreamId)\n }\n}\n"],"names":["kStore","kStoreSubscribe","kStoreUnsubscribe","CoreStatus","StreamLayerSDK","initializeApp","getStoreItem","setValue","INITIALIZATION","organizationSettings","getValue","READY","enabled","FAILED","err","disableApp","DISABLED","invalidateSettings","transport","nanoquery","utils","invalidateKeys","createEventSession","providerStreamId"],"mappings":"AAAA,SAASA,MAAM,EAAEC,eAAe,EAAEC,iBAAiB,QAAQ,SAAQ;AACnE,SAASC,UAAU,QAAQ,gBAAe;AAG1C;;;;;;;;;CASC,GACD,OAAO,MAAMC;;aAOJC,gBAAgB;YACrB,IAAI,CAACJ,gBAAgB;YACrB,IAAI,CAACD,OAAO,CAACM,YAAY,CAAC,WAAWC,QAAQ,CAAC;YAC9C,IAAI,CAACP,OAAO,CAACM,YAAY,CAAC,UAAUC,QAAQ,CAACJ,WAAWK,cAAc;YAEtE,IAAI;gBACF,MAAMC,uBAAuB,MAAM,IAAI,CAACT,OAAO,CAACM,YAAY,CAAC,wBAAwBI,QAAQ;gBAE7F,IAAID,sBAAsB;oBACxB,IAAI,CAACT,OAAO,CAACM,YAAY,CAAC,UAAUC,QAAQ,CAACJ,WAAWQ,KAAK;oBAE7D,OAAO;wBAAEC,SAAS,CAAC,CAACH;oBAAqB;gBAC3C;gBAEA,IAAI,CAACT,OAAO,CAACM,YAAY,CAAC,UAAUC,QAAQ,CAACJ,WAAWU,MAAM;gBAE9D,OAAO;oBAAEC,KAAK;gBAAS;YACzB,EAAE,OAAOA,KAAK;gBACZ,IAAI,CAACd,OAAO,CAACM,YAAY,CAAC,WAAWC,QAAQ;gBAC7C,IAAI,CAACP,OAAO,CAACM,YAAY,CAAC,UAAUC,QAAQ,CAACJ,WAAWU,MAAM;gBAE9D,OAAO;oBAAEC;gBAAI;YACf;QACF;aAEOC,aAAa;YAClB,IAAI,CAACf,OAAO,CAACM,YAAY,CAAC,WAAWC,QAAQ;YAC7C,IAAI,CAACP,OAAO,CAACM,YAAY,CAAC,UAAUC,QAAQ,CAACJ,WAAWa,QAAQ;YAChE,IAAI,CAACd,kBAAkB;QACzB;aAEOe,qBAAqB;YAC1B,IAAI,CAACC,SAAS,CAACC,SAAS,CAACC,KAAK,CAACC,cAAc,CAAC;gBAC5C,OAAO;YACT;QACF;QAEA;;;GAGC,QACMC,qBAAqB,CAACC;YAC3B,IAAI,CAACvB,OAAO,CAACM,YAAY,CAAC,oBAAoBC,QAAQ,CAACgB;QACzD;;AACF"}
|
package/src/features/index.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { FeatureConfig } from '@streamlayer/sdk-web-types';
|
|
2
|
-
import { AbstractFeature } from '@streamlayer/sdk-web-interfaces';
|
|
2
|
+
import { AbstractFeature, FeatureSource } from '@streamlayer/sdk-web-interfaces';
|
|
3
3
|
import { StreamLayerContext } from '../';
|
|
4
4
|
import { kFeatures, kFeatureInit } from '../keys';
|
|
5
5
|
declare module '../core' {
|
|
6
6
|
interface StreamLayerSDK {
|
|
7
7
|
[kFeatures]: Map<FeatureConfig['name'], Feature>;
|
|
8
|
-
[kFeatureInit]: (overlay: FeatureConfig) => void
|
|
8
|
+
[kFeatureInit]: (overlay: FeatureConfig, source: FeatureSource) => Promise<void>;
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
export declare class Feature extends AbstractFeature {
|
|
12
12
|
}
|
|
13
|
-
export declare const initFeature: (overlay: FeatureConfig) => Feature;
|
|
13
|
+
export declare const initFeature: (overlay: FeatureConfig, source: FeatureSource) => Feature;
|
|
14
|
+
export { FeatureSource } from '@streamlayer/sdk-web-interfaces';
|
|
14
15
|
export declare const features: (instance: StreamLayerContext, opts: any, done: any) => void;
|
package/src/features/index.js
CHANGED
|
@@ -1,18 +1,34 @@
|
|
|
1
1
|
import { AbstractFeature } from '@streamlayer/sdk-web-interfaces';
|
|
2
|
-
import { kFeatures, kFeatureInit } from '../keys';
|
|
2
|
+
import { kFeatures, kFeatureInit, kFeatureUpdate, kFeatureDestroy } from '../keys';
|
|
3
3
|
export class Feature extends AbstractFeature {
|
|
4
4
|
}
|
|
5
|
-
export const initFeature = (overlay)=>{
|
|
6
|
-
return new Feature(overlay);
|
|
5
|
+
export const initFeature = (overlay, source)=>{
|
|
6
|
+
return new Feature(overlay, source);
|
|
7
7
|
};
|
|
8
|
+
export { FeatureSource } from '@streamlayer/sdk-web-interfaces';
|
|
8
9
|
export const features = (instance, opts, done)=>{
|
|
9
10
|
instance.sdk[kFeatures] = new Map();
|
|
10
11
|
/**
|
|
11
12
|
* A distinct object instance is created and initialized for each overlay.
|
|
12
|
-
*/ instance.sdk
|
|
13
|
-
|
|
13
|
+
*/ instance.sdk.getFeatures = ()=>{
|
|
14
|
+
return instance.sdk[kFeatures];
|
|
15
|
+
};
|
|
16
|
+
instance.sdk[kFeatureInit] = async (overlay, source)=>{
|
|
17
|
+
if (instance.sdk[kFeatures].has(overlay.name)) {
|
|
18
|
+
await instance.sdk[kFeatureUpdate](overlay, source);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const feature = initFeature(overlay, source);
|
|
14
22
|
instance.sdk[kFeatures].set(overlay.name, feature);
|
|
15
23
|
};
|
|
24
|
+
// eslint-disable-next-line require-await
|
|
25
|
+
instance.sdk[kFeatureUpdate] = async (overlay, source)=>{
|
|
26
|
+
instance.sdk[kFeatures].get(overlay.name).update(overlay, source);
|
|
27
|
+
};
|
|
28
|
+
// eslint-disable-next-line require-await
|
|
29
|
+
instance.sdk[kFeatureDestroy] = async (overlay)=>{
|
|
30
|
+
instance.sdk[kFeatures].delete(overlay.name);
|
|
31
|
+
};
|
|
16
32
|
done();
|
|
17
33
|
};
|
|
18
34
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../packages/sdk-web/src/features/index.ts"],"sourcesContent":["import { FeatureConfig } from '@streamlayer/sdk-web-types'\nimport { AbstractFeature } from '@streamlayer/sdk-web-interfaces'\n\nimport { StreamLayerContext } from '../'\nimport { kFeatures, kFeatureInit } from '../keys'\n\ndeclare module '../core' {\n interface StreamLayerSDK {\n [kFeatures]: Map<FeatureConfig['name'], Feature>\n [kFeatureInit]: (overlay: FeatureConfig) => void
|
|
1
|
+
{"version":3,"sources":["../../../../../packages/sdk-web/src/features/index.ts"],"sourcesContent":["import { FeatureConfig } from '@streamlayer/sdk-web-types'\nimport { AbstractFeature, FeatureSource } from '@streamlayer/sdk-web-interfaces'\n\nimport { StreamLayerContext } from '../'\nimport { kFeatures, kFeatureInit, kFeatureUpdate, kFeatureDestroy } from '../keys'\n\ndeclare module '../core' {\n interface StreamLayerSDK {\n [kFeatures]: Map<FeatureConfig['name'], Feature>\n [kFeatureInit]: (overlay: FeatureConfig, source: FeatureSource) => Promise<void>\n }\n}\n\nexport class Feature extends AbstractFeature {}\nexport const initFeature = (overlay: FeatureConfig, source: FeatureSource) => {\n return new Feature(overlay, source)\n}\nexport { FeatureSource } from '@streamlayer/sdk-web-interfaces'\n\nexport const features = (instance: StreamLayerContext, opts, done) => {\n instance.sdk[kFeatures] = new Map()\n /**\n * A distinct object instance is created and initialized for each overlay.\n */\n instance.sdk.getFeatures = () => {\n return instance.sdk[kFeatures]\n }\n\n instance.sdk[kFeatureInit] = async (overlay: FeatureConfig, source: FeatureSource) => {\n if (instance.sdk[kFeatures].has(overlay.name)) {\n await instance.sdk[kFeatureUpdate](overlay, source)\n\n return\n }\n\n const feature = initFeature(overlay, source)\n\n instance.sdk[kFeatures].set(overlay.name, feature)\n }\n // eslint-disable-next-line require-await\n instance.sdk[kFeatureUpdate] = async (overlay: FeatureConfig, source: FeatureSource) => {\n instance.sdk[kFeatures].get(overlay.name).update(overlay, source)\n }\n\n // eslint-disable-next-line require-await\n instance.sdk[kFeatureDestroy] = async (overlay: FeatureConfig) => {\n instance.sdk[kFeatures].delete(overlay.name)\n }\n\n done()\n}\n"],"names":["AbstractFeature","kFeatures","kFeatureInit","kFeatureUpdate","kFeatureDestroy","Feature","initFeature","overlay","source","FeatureSource","features","instance","opts","done","sdk","Map","getFeatures","has","name","feature","set","get","update","delete"],"mappings":"AACA,SAASA,eAAe,QAAuB,kCAAiC;AAGhF,SAASC,SAAS,EAAEC,YAAY,EAAEC,cAAc,EAAEC,eAAe,QAAQ,UAAS;AASlF,OAAO,MAAMC,gBAAgBL;AAAiB;AAC9C,OAAO,MAAMM,cAAc,CAACC,SAAwBC;IAClD,OAAO,IAAIH,QAAQE,SAASC;AAC9B,EAAC;AACD,SAASC,aAAa,QAAQ,kCAAiC;AAE/D,OAAO,MAAMC,WAAW,CAACC,UAA8BC,MAAMC;IAC3DF,SAASG,GAAG,CAACb,UAAU,GAAG,IAAIc;IAC9B;;GAEC,GACDJ,SAASG,GAAG,CAACE,WAAW,GAAG;QACzB,OAAOL,SAASG,GAAG,CAACb,UAAU;IAChC;IAEAU,SAASG,GAAG,CAACZ,aAAa,GAAG,OAAOK,SAAwBC;QAC1D,IAAIG,SAASG,GAAG,CAACb,UAAU,CAACgB,GAAG,CAACV,QAAQW,IAAI,GAAG;YAC7C,MAAMP,SAASG,GAAG,CAACX,eAAe,CAACI,SAASC;YAE5C;QACF;QAEA,MAAMW,UAAUb,YAAYC,SAASC;QAErCG,SAASG,GAAG,CAACb,UAAU,CAACmB,GAAG,CAACb,QAAQW,IAAI,EAAEC;IAC5C;IACA,yCAAyC;IACzCR,SAASG,GAAG,CAACX,eAAe,GAAG,OAAOI,SAAwBC;QAC5DG,SAASG,GAAG,CAACb,UAAU,CAACoB,GAAG,CAACd,QAAQW,IAAI,EAAEI,MAAM,CAACf,SAASC;IAC5D;IAEA,yCAAyC;IACzCG,SAASG,GAAG,CAACV,gBAAgB,GAAG,OAAOG;QACrCI,SAASG,GAAG,CAACb,UAAU,CAACsB,MAAM,CAAChB,QAAQW,IAAI;IAC7C;IAEAL;AACF,EAAC"}
|
package/src/keys.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export declare const kAuth: unique symbol;
|
|
2
2
|
export declare const kFeatures: unique symbol;
|
|
3
3
|
export declare const kFeatureInit: unique symbol;
|
|
4
|
+
export declare const kFeatureUpdate: unique symbol;
|
|
5
|
+
export declare const kFeatureDestroy: unique symbol;
|
|
4
6
|
export declare const kStore: unique symbol;
|
|
5
7
|
export declare const kStoreSubscribe: unique symbol;
|
|
6
8
|
export declare const kStoreUnsubscribe: unique symbol;
|
package/src/keys.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export const kAuth = Symbol('sdk-auth');
|
|
2
2
|
export const kFeatures = Symbol('sdk-features');
|
|
3
3
|
export const kFeatureInit = Symbol('sdk-features:initFeature');
|
|
4
|
+
export const kFeatureUpdate = Symbol('sdk-features:updateFeature');
|
|
5
|
+
export const kFeatureDestroy = Symbol('sdk-features:destroyFeature');
|
|
4
6
|
export const kStore = Symbol('sdk-store');
|
|
5
7
|
export const kStoreSubscribe = Symbol('sdk-store:storeSubscribe');
|
|
6
8
|
export const kStoreUnsubscribe = Symbol('sdk-store:storeUnsubscribe');
|
package/src/keys.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../packages/sdk-web/src/keys.ts"],"sourcesContent":["export const kAuth = Symbol('sdk-auth')\n\nexport const kFeatures = Symbol('sdk-features')\nexport const kFeatureInit = Symbol('sdk-features:initFeature')\n\nexport const kStore = Symbol('sdk-store')\nexport const kStoreSubscribe = Symbol('sdk-store:storeSubscribe')\nexport const kStoreUnsubscribe = Symbol('sdk-store:storeUnsubscribe')\n"],"names":["kAuth","Symbol","kFeatures","kFeatureInit","kStore","kStoreSubscribe","kStoreUnsubscribe"],"mappings":"AAAA,OAAO,MAAMA,QAAQC,OAAO,YAAW;AAEvC,OAAO,MAAMC,YAAYD,OAAO,gBAAe;AAC/C,OAAO,MAAME,eAAeF,OAAO,4BAA2B;
|
|
1
|
+
{"version":3,"sources":["../../../../packages/sdk-web/src/keys.ts"],"sourcesContent":["export const kAuth = Symbol('sdk-auth')\n\nexport const kFeatures = Symbol('sdk-features')\nexport const kFeatureInit = Symbol('sdk-features:initFeature')\nexport const kFeatureUpdate = Symbol('sdk-features:updateFeature')\nexport const kFeatureDestroy = Symbol('sdk-features:destroyFeature')\n\nexport const kStore = Symbol('sdk-store')\nexport const kStoreSubscribe = Symbol('sdk-store:storeSubscribe')\nexport const kStoreUnsubscribe = Symbol('sdk-store:storeUnsubscribe')\n"],"names":["kAuth","Symbol","kFeatures","kFeatureInit","kFeatureUpdate","kFeatureDestroy","kStore","kStoreSubscribe","kStoreUnsubscribe"],"mappings":"AAAA,OAAO,MAAMA,QAAQC,OAAO,YAAW;AAEvC,OAAO,MAAMC,YAAYD,OAAO,gBAAe;AAC/C,OAAO,MAAME,eAAeF,OAAO,4BAA2B;AAC9D,OAAO,MAAMG,iBAAiBH,OAAO,8BAA6B;AAClE,OAAO,MAAMI,kBAAkBJ,OAAO,+BAA8B;AAEpE,OAAO,MAAMK,SAASL,OAAO,aAAY;AACzC,OAAO,MAAMM,kBAAkBN,OAAO,4BAA2B;AACjE,OAAO,MAAMO,oBAAoBP,OAAO,8BAA6B"}
|
package/src/store/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FeatureSource } from '@streamlayer/sdk-web-interfaces';
|
|
1
2
|
import { kStore, kStoreSubscribe, kStoreUnsubscribe, kFeatureInit } from '../keys';
|
|
2
3
|
import { CoreStore } from './store';
|
|
3
4
|
/**
|
|
@@ -10,6 +11,17 @@ import { CoreStore } from './store';
|
|
|
10
11
|
* based on their dependencies. In certain cases, specific logic is
|
|
11
12
|
* directly invoked in response to changes in the store.
|
|
12
13
|
*/ instance.sdk[kStoreSubscribe] = ()=>{
|
|
14
|
+
const processSettings = (source, settings)=>{
|
|
15
|
+
if (!settings.data) return;
|
|
16
|
+
const featureNames = new Set();
|
|
17
|
+
for (const overlay of settings.data.overlays){
|
|
18
|
+
const featureName = overlay.name;
|
|
19
|
+
featureNames.add(featureName);
|
|
20
|
+
instance.sdk[kFeatureInit](overlay, source).catch((initError)=>{
|
|
21
|
+
console.error(`Error initializing feature "${featureName}": ${initError}`);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
};
|
|
13
25
|
const subscribes = {
|
|
14
26
|
/**
|
|
15
27
|
* During the initial SDK initialization, it's imperative to initialize features first,
|
|
@@ -19,12 +31,19 @@ import { CoreStore } from './store';
|
|
|
19
31
|
* has already been initialized. If it has, events related to
|
|
20
32
|
* that feature should be skipped. Conversely, if a feature is
|
|
21
33
|
* missing in the new settings, it should be deinitialized.
|
|
22
|
-
*/ organizationSettings: (orgSettings
|
|
23
|
-
if (
|
|
34
|
+
*/ organizationSettings: (orgSettings)=>{
|
|
35
|
+
if (orgSettings.data) {
|
|
36
|
+
try {
|
|
37
|
+
processSettings(FeatureSource.ORGANIZATION, orgSettings);
|
|
38
|
+
} catch (err) {
|
|
39
|
+
console.log(err);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
streamSettings: (streamSettings)=>{
|
|
44
|
+
if (streamSettings.data) {
|
|
24
45
|
try {
|
|
25
|
-
|
|
26
|
-
instance.sdk[kFeatureInit](overlay);
|
|
27
|
-
}
|
|
46
|
+
processSettings(FeatureSource.STREAM, streamSettings);
|
|
28
47
|
} catch (err) {
|
|
29
48
|
console.log(err);
|
|
30
49
|
}
|
package/src/store/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../packages/sdk-web/src/store/index.ts"],"sourcesContent":["import { StreamLayerContext } from '../'\nimport { kStore, kStoreSubscribe, kStoreUnsubscribe, kFeatureInit } from '../keys'\n\nimport { CoreStore, StoreListeners } from './store'\n\ndeclare module '../core' {\n interface StreamLayerSDK {\n [kStore]: CoreStore\n sdkStore: () => CoreStore\n [kStoreSubscribe]: () => void\n [kStoreUnsubscribe]: () => void\n }\n}\n\n/**\n * store plugin, connect store to sdk\n */\nexport const store = (instance: StreamLayerContext, opts, done) => {\n instance.sdk[kStore] = new CoreStore(instance.sdk.transport)\n\n instance.sdk.sdkStore = () => instance.sdk[kStore]\n\n /**\n * Essentially, features and stores establish subscriptions to other stores\n * based on their dependencies. In certain cases, specific logic is\n * directly invoked in response to changes in the store.\n */\n instance.sdk[kStoreSubscribe] = () => {\n const subscribes: Partial<StoreListeners> = {\n /**\n * During the initial SDK initialization, it's imperative to initialize features first,\n * followed by their direct subscriptions to store fields.\n * This section is currently in development, and it's\n * essential to implement checks to determine whether a feature\n * has already been initialized. If it has, events related to\n * that feature should be skipped. Conversely, if a feature is\n * missing in the new settings, it should be deinitialized.\n */\n organizationSettings: (orgSettings
|
|
1
|
+
{"version":3,"sources":["../../../../../packages/sdk-web/src/store/index.ts"],"sourcesContent":["import { FeatureSource } from '@streamlayer/sdk-web-interfaces'\n\nimport { StreamLayerContext } from '../'\nimport { kStore, kStoreSubscribe, kStoreUnsubscribe, kFeatureInit } from '../keys'\n\nimport { CoreStore, StoreListeners } from './store'\n\ndeclare module '../core' {\n interface StreamLayerSDK {\n [kStore]: CoreStore\n sdkStore: () => CoreStore\n [kStoreSubscribe]: () => void\n [kStoreUnsubscribe]: () => void\n }\n}\n\n/**\n * store plugin, connect store to sdk\n */\nexport const store = (instance: StreamLayerContext, opts, done) => {\n instance.sdk[kStore] = new CoreStore(instance.sdk.transport)\n\n instance.sdk.sdkStore = () => instance.sdk[kStore]\n\n /**\n * Essentially, features and stores establish subscriptions to other stores\n * based on their dependencies. In certain cases, specific logic is\n * directly invoked in response to changes in the store.\n */\n instance.sdk[kStoreSubscribe] = () => {\n const processSettings = (source, settings) => {\n if (!settings.data) return\n\n const featureNames = new Set()\n\n for (const overlay of settings.data.overlays) {\n const featureName = overlay.name\n\n featureNames.add(featureName)\n\n instance.sdk[kFeatureInit](overlay, source).catch((initError) => {\n console.error(`Error initializing feature \"${featureName}\": ${initError}`)\n })\n }\n }\n\n const subscribes: Partial<StoreListeners> = {\n /**\n * During the initial SDK initialization, it's imperative to initialize features first,\n * followed by their direct subscriptions to store fields.\n * This section is currently in development, and it's\n * essential to implement checks to determine whether a feature\n * has already been initialized. If it has, events related to\n * that feature should be skipped. Conversely, if a feature is\n * missing in the new settings, it should be deinitialized.\n */\n organizationSettings: (orgSettings) => {\n if (orgSettings.data) {\n try {\n processSettings(FeatureSource.ORGANIZATION, orgSettings)\n } catch (err) {\n console.log(err)\n }\n }\n },\n streamSettings: (streamSettings) => {\n if (streamSettings.data) {\n try {\n processSettings(FeatureSource.STREAM, streamSettings)\n } catch (err) {\n console.log(err)\n }\n }\n },\n }\n\n instance.sdk[kStore].subscribe(subscribes)\n }\n\n instance.sdk[kStoreUnsubscribe] = () => {\n instance.sdk[kStore].unsubscribe()\n }\n\n done()\n}\n"],"names":["FeatureSource","kStore","kStoreSubscribe","kStoreUnsubscribe","kFeatureInit","CoreStore","store","instance","opts","done","sdk","transport","sdkStore","processSettings","source","settings","data","featureNames","Set","overlay","overlays","featureName","name","add","catch","initError","console","error","subscribes","organizationSettings","orgSettings","ORGANIZATION","err","log","streamSettings","STREAM","subscribe","unsubscribe"],"mappings":"AAAA,SAASA,aAAa,QAAQ,kCAAiC;AAG/D,SAASC,MAAM,EAAEC,eAAe,EAAEC,iBAAiB,EAAEC,YAAY,QAAQ,UAAS;AAElF,SAASC,SAAS,QAAwB,UAAS;AAWnD;;CAEC,GACD,OAAO,MAAMC,QAAQ,CAACC,UAA8BC,MAAMC;IACxDF,SAASG,GAAG,CAACT,OAAO,GAAG,IAAII,UAAUE,SAASG,GAAG,CAACC,SAAS;IAE3DJ,SAASG,GAAG,CAACE,QAAQ,GAAG,IAAML,SAASG,GAAG,CAACT,OAAO;IAElD;;;;GAIC,GACDM,SAASG,GAAG,CAACR,gBAAgB,GAAG;QAC9B,MAAMW,kBAAkB,CAACC,QAAQC;YAC/B,IAAI,CAACA,SAASC,IAAI,EAAE;YAEpB,MAAMC,eAAe,IAAIC;YAEzB,KAAK,MAAMC,WAAWJ,SAASC,IAAI,CAACI,QAAQ,CAAE;gBAC5C,MAAMC,cAAcF,QAAQG,IAAI;gBAEhCL,aAAaM,GAAG,CAACF;gBAEjBd,SAASG,GAAG,CAACN,aAAa,CAACe,SAASL,QAAQU,KAAK,CAAC,CAACC;oBACjDC,QAAQC,KAAK,CAAC,CAAC,4BAA4B,EAAEN,YAAY,GAAG,EAAEI,UAAU,CAAC;gBAC3E;YACF;QACF;QAEA,MAAMG,aAAsC;YAC1C;;;;;;;;OAQC,GACDC,sBAAsB,CAACC;gBACrB,IAAIA,YAAYd,IAAI,EAAE;oBACpB,IAAI;wBACFH,gBAAgBb,cAAc+B,YAAY,EAAED;oBAC9C,EAAE,OAAOE,KAAK;wBACZN,QAAQO,GAAG,CAACD;oBACd;gBACF;YACF;YACAE,gBAAgB,CAACA;gBACf,IAAIA,eAAelB,IAAI,EAAE;oBACvB,IAAI;wBACFH,gBAAgBb,cAAcmC,MAAM,EAAED;oBACxC,EAAE,OAAOF,KAAK;wBACZN,QAAQO,GAAG,CAACD;oBACd;gBACF;YACF;QACF;QAEAzB,SAASG,GAAG,CAACT,OAAO,CAACmC,SAAS,CAACR;IACjC;IAEArB,SAASG,GAAG,CAACP,kBAAkB,GAAG;QAChCI,SAASG,GAAG,CAACT,OAAO,CAACoC,WAAW;IAClC;IAEA5B;AACF,EAAC"}
|
package/src/store/store.d.ts
CHANGED
|
@@ -61,7 +61,7 @@ export type CoreStoreInstance = ReturnType<typeof mergeStores<StoreObj>>;
|
|
|
61
61
|
export declare class CoreStore extends AbstractStore<CoreStoreInstance> {
|
|
62
62
|
private stores;
|
|
63
63
|
constructor(transport: Transport);
|
|
64
|
-
getStoreItem: <T extends "enabled" | "status" | "providerStreamId" | "slStreamId" | "streamSettings" | "user" | "
|
|
64
|
+
getStoreItem: <T extends "userKey" | "enabled" | "status" | "providerStreamId" | "slStreamId" | "streamSettings" | "user" | "userToken" | "userSettings" | "organizationSettings" | "organizationAdvertising" = "userKey" | "enabled" | "status" | "providerStreamId" | "slStreamId" | "streamSettings" | "user" | "userToken" | "userSettings" | "organizationSettings" | "organizationAdvertising">(key: T) => {
|
|
65
65
|
readonly enabled: SingleStore<unknown, import("nanostores").WritableAtom<"on">>;
|
|
66
66
|
readonly status: SingleStore<unknown, import("nanostores").WritableAtom<CoreStatus>>;
|
|
67
67
|
readonly providerStreamId: SingleStore<unknown, import("nanostores").WritableAtom<string>>;
|