@streamlayer/sdk-web 0.3.0 → 0.15.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 CHANGED
@@ -1,20 +1,25 @@
1
1
  {
2
2
  "name": "@streamlayer/sdk-web",
3
- "version": "0.3.0",
4
3
  "dependencies": {
5
- "@swc/helpers": "~0.5.0",
4
+ "@streamlayer/sdk-web-api": "*",
5
+ "@streamlayer/sdk-web-interfaces": "*",
6
6
  "@streamlayer/sdk-web-types": "*",
7
- "nanostores": "^0.9.3"
7
+ "@swc/helpers": "*",
8
+ "avvio": "*"
8
9
  },
10
+ "version": "0.15.0",
9
11
  "type": "module",
10
12
  "main": "./src/index.js",
11
13
  "typings": "./src/index.d.ts",
14
+ "exports": {
15
+ "import": "./src/main.js",
16
+ "default": "./src/main.js"
17
+ },
12
18
  "files": [
13
19
  "src/"
14
20
  ],
15
- "exports": {
16
- ".": {
17
- "require": "./src/index.js"
18
- }
19
- }
21
+ "devDependencies": {
22
+ "webpack": "*"
23
+ },
24
+ "module": "./src/index.js"
20
25
  }
@@ -0,0 +1,22 @@
1
+ import { AbstractAuthenticationProvider } from '@streamlayer/sdk-web-interfaces';
2
+ import { Transport } from '@streamlayer/sdk-web-api';
3
+ import { CoreStore } from '../../store/store';
4
+ /**
5
+ * An authorization service manages user access by providing login, logout,
6
+ * authentication checks, and the ability to revoke access.
7
+ * Subscribed to $userStore and automatically updates the auth header for the Transport.
8
+ */
9
+ export declare class BypassAuth extends AbstractAuthenticationProvider {
10
+ private readonly $coreStore;
11
+ private readonly transport;
12
+ private readonly $bypassLogin;
13
+ constructor(store: CoreStore, transport: Transport);
14
+ me: () => Promise<any>;
15
+ login: (schema: string, userKey: string) => Promise<any>;
16
+ isAuthenticated: () => Promise<any>;
17
+ logout: () => void;
18
+ /**
19
+ * subscribe to user store and set auth header to the Transport on user update
20
+ */
21
+ private subscribe;
22
+ }
@@ -0,0 +1,49 @@
1
+ import { AbstractAuthenticationProvider } from '@streamlayer/sdk-web-interfaces';
2
+ import { queries } from '@streamlayer/sdk-web-api';
3
+ /**
4
+ * An authorization service manages user access by providing login, logout,
5
+ * authentication checks, and the ability to revoke access.
6
+ * Subscribed to $userStore and automatically updates the auth header for the Transport.
7
+ */ export class BypassAuth extends AbstractAuthenticationProvider {
8
+ constructor(store, transport){
9
+ super();
10
+ this.me = async ()=>{
11
+ const res = await this.$coreStore.getStoreItem('user').getValue();
12
+ return res?.data;
13
+ };
14
+ this.login = async (schema, userKey)=>{
15
+ this.$coreStore.getStoreItem('userKey').setValue(userKey);
16
+ await this.$bypassLogin.mutate({
17
+ schema,
18
+ userKey,
19
+ init: false
20
+ });
21
+ return this.me();
22
+ };
23
+ this.isAuthenticated = ()=>{
24
+ return this.me();
25
+ };
26
+ this.logout = ()=>{
27
+ this.$coreStore.getStoreItem('user').setValue();
28
+ this.$coreStore.getStoreItem('userKey').setValue();
29
+ this.$coreStore.getStoreItem('userToken').setValue();
30
+ this.transport.setAuth('');
31
+ };
32
+ /**
33
+ * subscribe to user store and set auth header to the Transport on user update
34
+ */ this.subscribe = ()=>{
35
+ this.$bypassLogin.subscribe((user, key)=>{
36
+ if (key === 'data') {
37
+ this.transport.setAuth(user?.data?.meta?.jwt);
38
+ this.$coreStore.getStoreItem('userToken').setValue(user?.data?.meta?.jwt);
39
+ }
40
+ });
41
+ };
42
+ this.$coreStore = store;
43
+ this.transport = transport;
44
+ this.$bypassLogin = queries.$bypassLogin(this.transport);
45
+ this.subscribe();
46
+ }
47
+ }
48
+
49
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../packages/sdk-web/src/auth/bypass/index.ts"],"sourcesContent":["import { AbstractAuthenticationProvider } from '@streamlayer/sdk-web-interfaces'\nimport { queries, Transport } from '@streamlayer/sdk-web-api'\n\nimport { CoreStore } from '../../store/store'\n\n/**\n * An authorization service manages user access by providing login, logout,\n * authentication checks, and the ability to revoke access.\n * Subscribed to $userStore and automatically updates the auth header for the Transport.\n */\nexport class BypassAuth extends AbstractAuthenticationProvider {\n private readonly $coreStore: CoreStore\n private readonly transport: Transport\n private readonly $bypassLogin: ReturnType<typeof queries.$bypassLogin>\n\n constructor(store: CoreStore, transport: Transport) {\n super()\n this.$coreStore = store\n this.transport = transport\n this.$bypassLogin = queries.$bypassLogin(this.transport)\n\n this.subscribe()\n }\n\n public me = async () => {\n const res = await this.$coreStore.getStoreItem('user').getValue()\n\n return res?.data\n }\n\n public login = async (schema: string, userKey: string) => {\n this.$coreStore.getStoreItem('userKey').setValue(userKey)\n\n await this.$bypassLogin.mutate({ schema, userKey, init: false })\n\n return this.me()\n }\n\n public isAuthenticated = () => {\n return this.me()\n }\n\n public logout = () => {\n this.$coreStore.getStoreItem('user').setValue()\n this.$coreStore.getStoreItem('userKey').setValue()\n this.$coreStore.getStoreItem('userToken').setValue()\n this.transport.setAuth('')\n }\n\n /**\n * subscribe to user store and set auth header to the Transport on user update\n */\n private subscribe = () => {\n this.$bypassLogin.subscribe((user, key) => {\n if (key === 'data') {\n this.transport.setAuth(user?.data?.meta?.jwt)\n this.$coreStore.getStoreItem('userToken').setValue(user?.data?.meta?.jwt)\n }\n })\n }\n}\n"],"names":["AbstractAuthenticationProvider","queries","BypassAuth","constructor","store","transport","me","res","$coreStore","getStoreItem","getValue","data","login","schema","userKey","setValue","$bypassLogin","mutate","init","isAuthenticated","logout","setAuth","subscribe","user","key","meta","jwt"],"mappings":"AAAA,SAASA,8BAA8B,QAAQ,kCAAiC;AAChF,SAASC,OAAO,QAAmB,2BAA0B;AAI7D;;;;CAIC,GACD,OAAO,MAAMC,mBAAmBF;IAK9BG,YAAYC,KAAgB,EAAEC,SAAoB,CAAE;QAClD,KAAK;aAQAC,KAAK;YACV,MAAMC,MAAM,MAAM,IAAI,CAACC,UAAU,CAACC,YAAY,CAAC,QAAQC,QAAQ;YAE/D,OAAOH,KAAKI;QACd;aAEOC,QAAQ,OAAOC,QAAgBC;YACpC,IAAI,CAACN,UAAU,CAACC,YAAY,CAAC,WAAWM,QAAQ,CAACD;YAEjD,MAAM,IAAI,CAACE,YAAY,CAACC,MAAM,CAAC;gBAAEJ;gBAAQC;gBAASI,MAAM;YAAM;YAE9D,OAAO,IAAI,CAACZ,EAAE;QAChB;aAEOa,kBAAkB;YACvB,OAAO,IAAI,CAACb,EAAE;QAChB;aAEOc,SAAS;YACd,IAAI,CAACZ,UAAU,CAACC,YAAY,CAAC,QAAQM,QAAQ;YAC7C,IAAI,CAACP,UAAU,CAACC,YAAY,CAAC,WAAWM,QAAQ;YAChD,IAAI,CAACP,UAAU,CAACC,YAAY,CAAC,aAAaM,QAAQ;YAClD,IAAI,CAACV,SAAS,CAACgB,OAAO,CAAC;QACzB;QAEA;;GAEC,QACOC,YAAY;YAClB,IAAI,CAACN,YAAY,CAACM,SAAS,CAAC,CAACC,MAAMC;gBACjC,IAAIA,QAAQ,QAAQ;oBAClB,IAAI,CAACnB,SAAS,CAACgB,OAAO,CAACE,MAAMZ,MAAMc,MAAMC;oBACzC,IAAI,CAAClB,UAAU,CAACC,YAAY,CAAC,aAAaM,QAAQ,CAACQ,MAAMZ,MAAMc,MAAMC;gBACvE;YACF;QACF;QA1CE,IAAI,CAAClB,UAAU,GAAGJ;QAClB,IAAI,CAACC,SAAS,GAAGA;QACjB,IAAI,CAACW,YAAY,GAAGf,QAAQe,YAAY,CAAC,IAAI,CAACX,SAAS;QAEvD,IAAI,CAACiB,SAAS;IAChB;AAsCF"}
@@ -0,0 +1,12 @@
1
+ import { StreamLayerContext } from '../';
2
+ import { kAuth } from '../keys';
3
+ import { BypassAuth } from './bypass';
4
+ declare module '../core' {
5
+ interface StreamLayerSDK {
6
+ [kAuth]: BypassAuth;
7
+ authorizationBypass: (schema: string, userKey: string) => Promise<void>;
8
+ logout: () => void;
9
+ isUserAuthorized: BypassAuth['isAuthenticated'];
10
+ }
11
+ }
12
+ export declare const bypass: (instance: StreamLayerContext, opts: any, done: any) => void;
@@ -0,0 +1,17 @@
1
+ import { kAuth } from '../keys';
2
+ import { BypassAuth } from './bypass';
3
+ export const bypass = (instance, opts, done)=>{
4
+ instance.sdk[kAuth] = new BypassAuth(instance.sdk.sdkStore(), instance.sdk.transport);
5
+ instance.sdk.authorizationBypass = async (schema, userKey)=>{
6
+ await instance.sdk[kAuth].login(schema, userKey);
7
+ };
8
+ instance.sdk.logout = ()=>{
9
+ instance.sdk[kAuth].logout();
10
+ };
11
+ instance.sdk.isUserAuthorized = ()=>{
12
+ return instance.sdk[kAuth].isAuthenticated();
13
+ };
14
+ done();
15
+ };
16
+
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../packages/sdk-web/src/auth/index.ts"],"sourcesContent":["import { StreamLayerContext } from '../'\nimport { kAuth } from '../keys'\n\nimport { BypassAuth } from './bypass'\n\ndeclare module '../core' {\n interface StreamLayerSDK {\n [kAuth]: BypassAuth\n authorizationBypass: (schema: string, userKey: string) => Promise<void>\n logout: () => void\n isUserAuthorized: BypassAuth['isAuthenticated']\n }\n}\n\nexport const bypass = (instance: StreamLayerContext, opts, done) => {\n instance.sdk[kAuth] = new BypassAuth(instance.sdk.sdkStore(), instance.sdk.transport)\n\n instance.sdk.authorizationBypass = async (schema: string, userKey: string) => {\n await instance.sdk[kAuth].login(schema, userKey)\n }\n\n instance.sdk.logout = () => {\n instance.sdk[kAuth].logout()\n }\n\n instance.sdk.isUserAuthorized = () => {\n return instance.sdk[kAuth].isAuthenticated()\n }\n\n done()\n}\n"],"names":["kAuth","BypassAuth","bypass","instance","opts","done","sdk","sdkStore","transport","authorizationBypass","schema","userKey","login","logout","isUserAuthorized","isAuthenticated"],"mappings":"AACA,SAASA,KAAK,QAAQ,UAAS;AAE/B,SAASC,UAAU,QAAQ,WAAU;AAWrC,OAAO,MAAMC,SAAS,CAACC,UAA8BC,MAAMC;IACzDF,SAASG,GAAG,CAACN,MAAM,GAAG,IAAIC,WAAWE,SAASG,GAAG,CAACC,QAAQ,IAAIJ,SAASG,GAAG,CAACE,SAAS;IAEpFL,SAASG,GAAG,CAACG,mBAAmB,GAAG,OAAOC,QAAgBC;QACxD,MAAMR,SAASG,GAAG,CAACN,MAAM,CAACY,KAAK,CAACF,QAAQC;IAC1C;IAEAR,SAASG,GAAG,CAACO,MAAM,GAAG;QACpBV,SAASG,GAAG,CAACN,MAAM,CAACa,MAAM;IAC5B;IAEAV,SAASG,GAAG,CAACQ,gBAAgB,GAAG;QAC9B,OAAOX,SAASG,GAAG,CAACN,MAAM,CAACe,eAAe;IAC5C;IAEAV;AACF,EAAC"}
package/src/core.d.ts ADDED
@@ -0,0 +1,29 @@
1
+ /**
2
+ * The main application instance is the core of a application. It includes:
3
+ * Store: Manages data storage.
4
+ * Public Methods: Provides a way to interact with the application.
5
+ * Connect Features: Handles communication between components throught store.
6
+ * Connect Transport: Handles communication with api.
7
+ * Dependency Injection: Incorporates other necessary instances.
8
+ * Error Handling: Manages errors and logs them.
9
+ * Security: Implements authentication and authorization.
10
+ */
11
+ export declare class StreamLayerSDK {
12
+ /**
13
+ * On initialize we subscribe to store and launch listeners
14
+ * that activate data downloading over the network
15
+ */
16
+ initializeApp: () => Promise<{
17
+ enabled: boolean;
18
+ err?: undefined;
19
+ } | {
20
+ err: any;
21
+ enabled?: undefined;
22
+ }>;
23
+ disableApp: () => void;
24
+ /**
25
+ * Configure the "event id" using the "provider," enabling subscribed stores to
26
+ * trigger their logic in response to a new event.
27
+ */
28
+ createEventSession: (providerStreamId: string) => void;
29
+ }
package/src/core.js ADDED
@@ -0,0 +1,55 @@
1
+ import { kStore, kStoreSubscribe, kStoreUnsubscribe } from './keys';
2
+ import { CoreStatus } from './store/store';
3
+ /**
4
+ * The main application instance is the core of a application. It includes:
5
+ * Store: Manages data storage.
6
+ * Public Methods: Provides a way to interact with the application.
7
+ * Connect Features: Handles communication between components throught store.
8
+ * Connect Transport: Handles communication with api.
9
+ * Dependency Injection: Incorporates other necessary instances.
10
+ * Error Handling: Manages errors and logs them.
11
+ * Security: Implements authentication and authorization.
12
+ */ export class StreamLayerSDK {
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 ()=>{
18
+ this[kStoreSubscribe]();
19
+ this[kStore].getStoreItem('enabled').setValue('on');
20
+ this[kStore].getStoreItem('status').setValue(CoreStatus.INITIALIZATION);
21
+ try {
22
+ const organizationSettings = await this[kStore].getStoreItem('organizationSettings').getValue();
23
+ if (organizationSettings) {
24
+ this[kStore].getStoreItem('status').setValue(CoreStatus.READY);
25
+ return {
26
+ enabled: !!organizationSettings
27
+ };
28
+ }
29
+ this[kStore].getStoreItem('status').setValue(CoreStatus.FAILED);
30
+ return {
31
+ err: 'failed'
32
+ };
33
+ } catch (err) {
34
+ this[kStore].getStoreItem('enabled').setValue();
35
+ this[kStore].getStoreItem('status').setValue(CoreStatus.FAILED);
36
+ return {
37
+ err
38
+ };
39
+ }
40
+ };
41
+ this.disableApp = ()=>{
42
+ this[kStore].getStoreItem('enabled').setValue();
43
+ this[kStore].getStoreItem('status').setValue(CoreStatus.DISABLED);
44
+ this[kStoreUnsubscribe]();
45
+ };
46
+ /**
47
+ * Configure the "event id" using the "provider," enabling subscribed stores to
48
+ * trigger their logic in response to a new event.
49
+ */ this.createEventSession = (providerStreamId)=>{
50
+ this[kStore].getStoreItem('providerStreamId').setValue(providerStreamId);
51
+ };
52
+ }
53
+ }
54
+
55
+ //# sourceMappingURL=core.js.map
@@ -0,0 +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;AAE1C;;;;;;;;;CASC,GACD,OAAO,MAAMC;;QACX;;;GAGC,QACMC,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;QAEA;;;GAGC,QACMe,qBAAqB,CAACC;YAC3B,IAAI,CAAClB,OAAO,CAACM,YAAY,CAAC,oBAAoBC,QAAQ,CAACW;QACzD;;AACF"}
@@ -0,0 +1,3 @@
1
+ export declare const environment: {
2
+ production: boolean;
3
+ };
@@ -0,0 +1,7 @@
1
+ // This file can be replaced during build by using the `fileReplacements` array.
2
+ // When building for production, this file is replaced with `environment.prod.ts`.
3
+ export const environment = {
4
+ production: false
5
+ };
6
+
7
+ //# sourceMappingURL=environment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../packages/sdk-web/src/environments/environment.ts"],"sourcesContent":["// This file can be replaced during build by using the `fileReplacements` array.\n// When building for production, this file is replaced with `environment.prod.ts`.\n\nexport const environment = {\n production: false,\n}\n"],"names":["environment","production"],"mappings":"AAAA,gFAAgF;AAChF,kFAAkF;AAElF,OAAO,MAAMA,cAAc;IACzBC,YAAY;AACd,EAAC"}
@@ -0,0 +1,3 @@
1
+ export declare const environment: {
2
+ production: boolean;
3
+ };
@@ -0,0 +1,5 @@
1
+ export const environment = {
2
+ production: true
3
+ };
4
+
5
+ //# sourceMappingURL=environment.prod.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../packages/sdk-web/src/environments/environment.prod.ts"],"sourcesContent":["export const environment = {\n production: true,\n}\n"],"names":["environment","production"],"mappings":"AAAA,OAAO,MAAMA,cAAc;IACzBC,YAAY;AACd,EAAC"}
@@ -0,0 +1,14 @@
1
+ import { FeatureConfig } from '@streamlayer/sdk-web-types';
2
+ import { AbstractFeature } from '@streamlayer/sdk-web-interfaces';
3
+ import { StreamLayerContext } from '../';
4
+ import { kFeatures, kFeatureInit } from '../keys';
5
+ declare module '../core' {
6
+ interface StreamLayerSDK {
7
+ [kFeatures]: Map<FeatureConfig['name'], Feature>;
8
+ [kFeatureInit]: (overlay: FeatureConfig) => void;
9
+ }
10
+ }
11
+ export declare class Feature extends AbstractFeature {
12
+ }
13
+ export declare const initFeature: (overlay: FeatureConfig) => Feature;
14
+ export declare const features: (instance: StreamLayerContext, opts: any, done: any) => void;
@@ -0,0 +1,19 @@
1
+ import { AbstractFeature } from '@streamlayer/sdk-web-interfaces';
2
+ import { kFeatures, kFeatureInit } from '../keys';
3
+ export class Feature extends AbstractFeature {
4
+ }
5
+ export const initFeature = (overlay)=>{
6
+ return new Feature(overlay);
7
+ };
8
+ export const features = (instance, opts, done)=>{
9
+ instance.sdk[kFeatures] = new Map();
10
+ /**
11
+ * A distinct object instance is created and initialized for each overlay.
12
+ */ instance.sdk[kFeatureInit] = (overlay)=>{
13
+ const feature = initFeature(overlay);
14
+ instance.sdk[kFeatures].set(overlay.name, feature);
15
+ };
16
+ done();
17
+ };
18
+
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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\n }\n}\n\nexport class Feature extends AbstractFeature {}\n\nexport const initFeature = (overlay: FeatureConfig) => {\n return new Feature(overlay)\n}\n\nexport const features = (instance: StreamLayerContext, opts, done) => {\n instance.sdk[kFeatures] = new Map()\n\n /**\n * A distinct object instance is created and initialized for each overlay.\n */\n instance.sdk[kFeatureInit] = (overlay: FeatureConfig) => {\n const feature = initFeature(overlay)\n\n instance.sdk[kFeatures].set(overlay.name, feature)\n }\n\n done()\n}\n"],"names":["AbstractFeature","kFeatures","kFeatureInit","Feature","initFeature","overlay","features","instance","opts","done","sdk","Map","feature","set","name"],"mappings":"AACA,SAASA,eAAe,QAAQ,kCAAiC;AAGjE,SAASC,SAAS,EAAEC,YAAY,QAAQ,UAAS;AASjD,OAAO,MAAMC,gBAAgBH;AAAiB;AAE9C,OAAO,MAAMI,cAAc,CAACC;IAC1B,OAAO,IAAIF,QAAQE;AACrB,EAAC;AAED,OAAO,MAAMC,WAAW,CAACC,UAA8BC,MAAMC;IAC3DF,SAASG,GAAG,CAACT,UAAU,GAAG,IAAIU;IAE9B;;GAEC,GACDJ,SAASG,GAAG,CAACR,aAAa,GAAG,CAACG;QAC5B,MAAMO,UAAUR,YAAYC;QAE5BE,SAASG,GAAG,CAACT,UAAU,CAACY,GAAG,CAACR,QAAQS,IAAI,EAAEF;IAC5C;IAEAH;AACF,EAAC"}
package/src/index.d.ts CHANGED
@@ -1 +1,18 @@
1
- export * from './lib/core';
1
+ import { Transport } from '@streamlayer/sdk-web-api';
2
+ import avvio from 'avvio';
3
+ import './store';
4
+ import './auth';
5
+ import { StreamLayerSDK } from './core';
6
+ export type { CoreStoreInterface } from './store/store';
7
+ export { StreamLayerSDK };
8
+ export interface StreamLayerContext {
9
+ sdk: StreamLayerSDK;
10
+ }
11
+ declare module './core' {
12
+ interface StreamLayerSDK {
13
+ transport: Transport;
14
+ }
15
+ }
16
+ export type StreamLayerSDKStore = ReturnType<ReturnType<StreamLayerSDK['sdkStore']>['getStore']>;
17
+ export type StreamLayerPlugin = (instance: StreamLayerContext, opts: any, done: any) => void;
18
+ export declare function StreamLayer(sdkKey: string): avvio.Avvio<StreamLayerContext>;
package/src/index.js CHANGED
@@ -1,3 +1,36 @@
1
- export * from './lib/core';
1
+ import { Transport } from '@streamlayer/sdk-web-api';
2
+ import avvio from 'avvio';
3
+ import './store';
4
+ import './auth';
5
+ import { features } from './features';
6
+ import { store } from './store';
7
+ import { StreamLayerSDK } from './core';
8
+ import { bypass } from './auth';
9
+ export { StreamLayerSDK };
10
+ export function StreamLayer(sdkKey) {
11
+ const streamLayer = avvio(Object.create(null), {
12
+ autostart: false
13
+ });
14
+ streamLayer.use((instance, opts, done)=>{
15
+ instance.sdk = new StreamLayerSDK();
16
+ done();
17
+ });
18
+ streamLayer.use((instance, opts, done)=>{
19
+ instance.sdk.transport = new Transport();
20
+ instance.sdk.transport.setSdkKey(sdkKey);
21
+ done();
22
+ });
23
+ streamLayer.use(store);
24
+ streamLayer.use(bypass);
25
+ streamLayer.use(features);
26
+ streamLayer.after(async (err, context, done)=>{
27
+ await context.sdk.initializeApp();
28
+ done();
29
+ });
30
+ streamLayer.onClose(()=>{
31
+ console.log('close');
32
+ });
33
+ return streamLayer;
34
+ }
2
35
 
3
36
  //# sourceMappingURL=index.js.map
package/src/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../packages/sdk-web/src/index.ts"],"sourcesContent":["export * from './lib/core'\n"],"names":[],"mappings":"AAAA,cAAc,aAAY"}
1
+ {"version":3,"sources":["../../../../packages/sdk-web/src/index.ts"],"sourcesContent":["import { Transport } from '@streamlayer/sdk-web-api'\n\nimport avvio from 'avvio'\n\nimport './store'\nimport './auth'\n\nimport { features } from './features'\nimport { store } from './store'\nimport { StreamLayerSDK } from './core'\nimport { bypass } from './auth'\n\nexport type { CoreStoreInterface } from './store/store'\nexport { StreamLayerSDK }\n\nexport interface StreamLayerContext {\n sdk: StreamLayerSDK\n}\n\ndeclare module './core' {\n interface StreamLayerSDK {\n transport: Transport\n }\n}\n\nexport type StreamLayerSDKStore = ReturnType<ReturnType<StreamLayerSDK['sdkStore']>['getStore']>\n\nexport type StreamLayerPlugin = (instance: StreamLayerContext, opts, done) => void\n\nexport function StreamLayer(sdkKey: string) {\n const streamLayer = avvio<StreamLayerContext>(Object.create(null), { autostart: false })\n\n streamLayer.use((instance, opts, done) => {\n instance.sdk = new StreamLayerSDK()\n done()\n })\n\n streamLayer.use((instance: StreamLayerContext, opts, done) => {\n instance.sdk.transport = new Transport()\n instance.sdk.transport.setSdkKey(sdkKey)\n done()\n })\n\n streamLayer.use(store)\n streamLayer.use(bypass)\n streamLayer.use(features)\n\n streamLayer.after(async (err, context: StreamLayerContext, done) => {\n await context.sdk.initializeApp()\n done()\n })\n\n streamLayer.onClose(() => {\n console.log('close')\n })\n\n return streamLayer\n}\n"],"names":["Transport","avvio","features","store","StreamLayerSDK","bypass","StreamLayer","sdkKey","streamLayer","Object","create","autostart","use","instance","opts","done","sdk","transport","setSdkKey","after","err","context","initializeApp","onClose","console","log"],"mappings":"AAAA,SAASA,SAAS,QAAQ,2BAA0B;AAEpD,OAAOC,WAAW,QAAO;AAEzB,OAAO,UAAS;AAChB,OAAO,SAAQ;AAEf,SAASC,QAAQ,QAAQ,aAAY;AACrC,SAASC,KAAK,QAAQ,UAAS;AAC/B,SAASC,cAAc,QAAQ,SAAQ;AACvC,SAASC,MAAM,QAAQ,SAAQ;AAG/B,SAASD,cAAc,GAAE;AAgBzB,OAAO,SAASE,YAAYC,MAAc;IACxC,MAAMC,cAAcP,MAA0BQ,OAAOC,MAAM,CAAC,OAAO;QAAEC,WAAW;IAAM;IAEtFH,YAAYI,GAAG,CAAC,CAACC,UAAUC,MAAMC;QAC/BF,SAASG,GAAG,GAAG,IAAIZ;QACnBW;IACF;IAEAP,YAAYI,GAAG,CAAC,CAACC,UAA8BC,MAAMC;QACnDF,SAASG,GAAG,CAACC,SAAS,GAAG,IAAIjB;QAC7Ba,SAASG,GAAG,CAACC,SAAS,CAACC,SAAS,CAACX;QACjCQ;IACF;IAEAP,YAAYI,GAAG,CAACT;IAChBK,YAAYI,GAAG,CAACP;IAChBG,YAAYI,GAAG,CAACV;IAEhBM,YAAYW,KAAK,CAAC,OAAOC,KAAKC,SAA6BN;QACzD,MAAMM,QAAQL,GAAG,CAACM,aAAa;QAC/BP;IACF;IAEAP,YAAYe,OAAO,CAAC;QAClBC,QAAQC,GAAG,CAAC;IACd;IAEA,OAAOjB;AACT"}
package/src/keys.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ export declare const kAuth: unique symbol;
2
+ export declare const kFeatures: unique symbol;
3
+ export declare const kFeatureInit: unique symbol;
4
+ export declare const kStore: unique symbol;
5
+ export declare const kStoreSubscribe: unique symbol;
6
+ export declare const kStoreUnsubscribe: unique symbol;
package/src/keys.js ADDED
@@ -0,0 +1,8 @@
1
+ export const kAuth = Symbol('sdk-auth');
2
+ export const kFeatures = Symbol('sdk-features');
3
+ export const kFeatureInit = Symbol('sdk-features:initFeature');
4
+ export const kStore = Symbol('sdk-store');
5
+ export const kStoreSubscribe = Symbol('sdk-store:storeSubscribe');
6
+ export const kStoreUnsubscribe = Symbol('sdk-store:storeUnsubscribe');
7
+
8
+ //# sourceMappingURL=keys.js.map
@@ -0,0 +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;AAE9D,OAAO,MAAMG,SAASH,OAAO,aAAY;AACzC,OAAO,MAAMI,kBAAkBJ,OAAO,4BAA2B;AACjE,OAAO,MAAMK,oBAAoBL,OAAO,8BAA6B"}
@@ -0,0 +1,15 @@
1
+ import { StreamLayerContext } from '../';
2
+ import { kStore, kStoreSubscribe, kStoreUnsubscribe } from '../keys';
3
+ import { CoreStore } from './store';
4
+ declare module '../core' {
5
+ interface StreamLayerSDK {
6
+ [kStore]: CoreStore;
7
+ sdkStore: () => CoreStore;
8
+ [kStoreSubscribe]: () => void;
9
+ [kStoreUnsubscribe]: () => void;
10
+ }
11
+ }
12
+ /**
13
+ * store plugin, connect store to sdk
14
+ */
15
+ export declare const store: (instance: StreamLayerContext, opts: any, done: any) => void;
@@ -0,0 +1,42 @@
1
+ import { kStore, kStoreSubscribe, kStoreUnsubscribe, kFeatureInit } from '../keys';
2
+ import { CoreStore } from './store';
3
+ /**
4
+ * store plugin, connect store to sdk
5
+ */ export const store = (instance, opts, done)=>{
6
+ instance.sdk[kStore] = new CoreStore(instance.sdk.transport);
7
+ instance.sdk.sdkStore = ()=>instance.sdk[kStore];
8
+ /**
9
+ * Essentially, features and stores establish subscriptions to other stores
10
+ * based on their dependencies. In certain cases, specific logic is
11
+ * directly invoked in response to changes in the store.
12
+ */ instance.sdk[kStoreSubscribe] = ()=>{
13
+ const subscribes = {
14
+ /**
15
+ * During the initial SDK initialization, it's imperative to initialize features first,
16
+ * followed by their direct subscriptions to store fields.
17
+ * This section is currently in development, and it's
18
+ * essential to implement checks to determine whether a feature
19
+ * has already been initialized. If it has, events related to
20
+ * that feature should be skipped. Conversely, if a feature is
21
+ * missing in the new settings, it should be deinitialized.
22
+ */ organizationSettings: (orgSettings, changedKey)=>{
23
+ if (changedKey === 'data' && orgSettings.data) {
24
+ try {
25
+ for (const overlay of orgSettings.data.overlays){
26
+ instance.sdk[kFeatureInit](overlay);
27
+ }
28
+ } catch (err) {
29
+ console.log(err);
30
+ }
31
+ }
32
+ }
33
+ };
34
+ instance.sdk[kStore].subscribe(subscribes);
35
+ };
36
+ instance.sdk[kStoreUnsubscribe] = ()=>{
37
+ instance.sdk[kStore].unsubscribe();
38
+ };
39
+ done();
40
+ };
41
+
42
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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, changedKey) => {\n if (changedKey === 'data' && orgSettings.data) {\n try {\n for (const overlay of orgSettings.data.overlays) {\n instance.sdk[kFeatureInit](overlay)\n }\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":["kStore","kStoreSubscribe","kStoreUnsubscribe","kFeatureInit","CoreStore","store","instance","opts","done","sdk","transport","sdkStore","subscribes","organizationSettings","orgSettings","changedKey","data","overlay","overlays","err","console","log","subscribe","unsubscribe"],"mappings":"AACA,SAASA,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,aAAsC;YAC1C;;;;;;;;OAQC,GACDC,sBAAsB,CAACC,aAAaC;gBAClC,IAAIA,eAAe,UAAUD,YAAYE,IAAI,EAAE;oBAC7C,IAAI;wBACF,KAAK,MAAMC,WAAWH,YAAYE,IAAI,CAACE,QAAQ,CAAE;4BAC/CZ,SAASG,GAAG,CAACN,aAAa,CAACc;wBAC7B;oBACF,EAAE,OAAOE,KAAK;wBACZC,QAAQC,GAAG,CAACF;oBACd;gBACF;YACF;QACF;QAEAb,SAASG,GAAG,CAACT,OAAO,CAACsB,SAAS,CAACV;IACjC;IAEAN,SAASG,GAAG,CAACP,kBAAkB,GAAG;QAChCI,SAASG,GAAG,CAACT,OAAO,CAACuB,WAAW;IAClC;IAEAf;AACF,EAAC"}
@@ -0,0 +1,82 @@
1
+ import type { OrganizationSettings, OrganizationAdvertising, StreamSettings, User, UserSettings } from '@streamlayer/sdk-web-types';
2
+ import { AbstractStore, SingleStore, mergeStores, ApiStore } from '@streamlayer/sdk-web-interfaces';
3
+ import { Transport } from '@streamlayer/sdk-web-api';
4
+ export declare enum CoreStatus {
5
+ DISABLED = "disabled",
6
+ INITIALIZATION = "initialization",
7
+ READY = "ready",
8
+ FAILED = "failed",
9
+ SUSPENDED = "suspended"
10
+ }
11
+ export interface CoreStoreInterface {
12
+ enabled: string;
13
+ status: string;
14
+ userKey?: string;
15
+ userToken?: string;
16
+ organizationSettings?: OrganizationSettings;
17
+ organizationAdvertising?: OrganizationAdvertising;
18
+ streamSettings?: StreamSettings;
19
+ user?: User;
20
+ userSettings?: UserSettings;
21
+ providerStreamId?: string;
22
+ slStreamId?: string;
23
+ }
24
+ declare const initializeStore: (transport: Transport) => {
25
+ readonly enabled: SingleStore<unknown, import("nanostores").WritableAtom<"on">>;
26
+ readonly status: SingleStore<unknown, import("nanostores").WritableAtom<CoreStatus>>;
27
+ readonly providerStreamId: SingleStore<unknown, import("nanostores").WritableAtom<string>>;
28
+ readonly slStreamId: ApiStore<any>;
29
+ readonly streamSettings: ApiStore<any>;
30
+ readonly user: ApiStore<any>;
31
+ readonly userKey: SingleStore<unknown, import("nanostores").WritableAtom<string>>;
32
+ readonly userToken: SingleStore<unknown, import("nanostores").WritableAtom<string>>;
33
+ readonly userSettings: ApiStore<any>;
34
+ readonly organizationSettings: ApiStore<any>;
35
+ readonly organizationAdvertising: ApiStore<any>;
36
+ };
37
+ type StoreObj = ReturnType<typeof initializeStore>;
38
+ export type CoreStores = {
39
+ [Index in keyof StoreObj]: ReturnType<StoreObj[Index]['getStore']>;
40
+ };
41
+ export type CoreStoreInstance = ReturnType<typeof mergeStores<StoreObj>>;
42
+ /**
43
+ * @description main app store
44
+ */
45
+ export declare class CoreStore extends AbstractStore<CoreStoreInstance> {
46
+ private stores;
47
+ constructor(transport: Transport);
48
+ getStoreItem: <T extends "enabled" | "status" | "providerStreamId" | "slStreamId" | "streamSettings" | "user" | "userKey" | "userToken" | "userSettings" | "organizationSettings" | "organizationAdvertising" = "enabled" | "status" | "providerStreamId" | "slStreamId" | "streamSettings" | "user" | "userKey" | "userToken" | "userSettings" | "organizationSettings" | "organizationAdvertising">(key: T) => {
49
+ readonly enabled: SingleStore<unknown, import("nanostores").WritableAtom<"on">>;
50
+ readonly status: SingleStore<unknown, import("nanostores").WritableAtom<CoreStatus>>;
51
+ readonly providerStreamId: SingleStore<unknown, import("nanostores").WritableAtom<string>>;
52
+ readonly slStreamId: ApiStore<any>;
53
+ readonly streamSettings: ApiStore<any>;
54
+ readonly user: ApiStore<any>;
55
+ readonly userKey: SingleStore<unknown, import("nanostores").WritableAtom<string>>;
56
+ readonly userToken: SingleStore<unknown, import("nanostores").WritableAtom<string>>;
57
+ readonly userSettings: ApiStore<any>;
58
+ readonly organizationSettings: ApiStore<any>;
59
+ readonly organizationAdvertising: ApiStore<any>;
60
+ }[T];
61
+ getValue(): unknown;
62
+ getValues(): {
63
+ readonly enabled: SingleStore<unknown, import("nanostores").WritableAtom<"on">>;
64
+ readonly status: SingleStore<unknown, import("nanostores").WritableAtom<CoreStatus>>;
65
+ readonly providerStreamId: SingleStore<unknown, import("nanostores").WritableAtom<string>>;
66
+ readonly slStreamId: ApiStore<any>;
67
+ readonly streamSettings: ApiStore<any>;
68
+ readonly user: ApiStore<any>;
69
+ readonly userKey: SingleStore<unknown, import("nanostores").WritableAtom<string>>;
70
+ readonly userToken: SingleStore<unknown, import("nanostores").WritableAtom<string>>;
71
+ readonly userSettings: ApiStore<any>;
72
+ readonly organizationSettings: ApiStore<any>;
73
+ readonly organizationAdvertising: ApiStore<any>;
74
+ };
75
+ setValue(): void;
76
+ subscribe: (subscribes: Partial<StoreListeners>) => void;
77
+ unsubscribe: () => void;
78
+ }
79
+ export type StoreListeners = {
80
+ [Index in keyof StoreObj]: Parameters<StoreObj[Index]['subscribe']>[0];
81
+ };
82
+ export {};
@@ -0,0 +1,85 @@
1
+ import { AbstractStore, createSingleStore, SingleStore, mergeStores, ApiStore } from '@streamlayer/sdk-web-interfaces';
2
+ import { queries } from '@streamlayer/sdk-web-api';
3
+ export var CoreStatus;
4
+ (function(CoreStatus) {
5
+ CoreStatus["DISABLED"] = "disabled";
6
+ CoreStatus["INITIALIZATION"] = "initialization";
7
+ CoreStatus["READY"] = "ready";
8
+ CoreStatus["FAILED"] = "failed";
9
+ CoreStatus["SUSPENDED"] = "suspended";
10
+ })(CoreStatus || (CoreStatus = {}));
11
+ const initializeStore = (transport)=>{
12
+ // sdk toggle
13
+ const enabled = new SingleStore(createSingleStore());
14
+ // sdk status
15
+ const status = new SingleStore(createSingleStore("disabled"));
16
+ // host user key
17
+ const userKey = new SingleStore(createSingleStore());
18
+ // sl user key
19
+ const userToken = new SingleStore(createSingleStore());
20
+ // host event id
21
+ const providerStreamId = new SingleStore(createSingleStore());
22
+ // sl event id
23
+ const slStreamId = new ApiStore(queries.$retrieveEventId(providerStreamId.getStore(), transport), (data)=>data.data);
24
+ // sl user data
25
+ const user = new ApiStore(queries.$user(userToken.getStore(), transport));
26
+ // sl user settings
27
+ const userSettings = new ApiStore(queries.$userSettings(userToken.getStore(), transport));
28
+ // sl stream settings
29
+ const streamSettings = new ApiStore(queries.$streamSettings(slStreamId.getAtomStore(), transport));
30
+ // sl organization settings
31
+ const organizationSettings = new ApiStore(queries.$organizationSettings(enabled.getStore(), transport), (data)=>data?.data?.id);
32
+ // sl organization advertising
33
+ const organizationAdvertising = new ApiStore(queries.$organizationAdvertising(organizationSettings.getAtomStore(), transport));
34
+ return {
35
+ enabled,
36
+ status,
37
+ providerStreamId,
38
+ slStreamId,
39
+ streamSettings,
40
+ user,
41
+ userKey,
42
+ userToken,
43
+ userSettings,
44
+ organizationSettings,
45
+ organizationAdvertising
46
+ };
47
+ };
48
+ /**
49
+ * @description main app store
50
+ */ export class CoreStore extends AbstractStore {
51
+ constructor(transport){
52
+ const storesObj = initializeStore(transport);
53
+ const store = mergeStores(storesObj);
54
+ super(store);
55
+ this.getStoreItem = (key)=>{
56
+ return this.stores[key];
57
+ };
58
+ this.subscribe = (subscribes)=>{
59
+ for(const storeKey in this.stores){
60
+ if (subscribes[storeKey]) {
61
+ // wrong type infer
62
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
63
+ // @ts-ignore
64
+ this.stores[storeKey].subscribe(subscribes[storeKey]);
65
+ }
66
+ }
67
+ };
68
+ this.unsubscribe = ()=>{
69
+ const store = this.getStore();
70
+ return store.off();
71
+ };
72
+ this.stores = storesObj;
73
+ }
74
+ getValue() {
75
+ throw new Error('Not implemented');
76
+ }
77
+ getValues() {
78
+ return this.stores;
79
+ }
80
+ setValue() {
81
+ throw new Error('Not implemented');
82
+ }
83
+ }
84
+
85
+ //# sourceMappingURL=store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../packages/sdk-web/src/store/store.ts"],"sourcesContent":["import type {\n OrganizationSettings,\n OrganizationAdvertising,\n StreamSettings,\n User,\n UserSettings,\n} from '@streamlayer/sdk-web-types'\nimport { AbstractStore, createSingleStore, SingleStore, mergeStores, ApiStore } from '@streamlayer/sdk-web-interfaces'\nimport { queries, Transport } from '@streamlayer/sdk-web-api'\n\nexport enum CoreStatus {\n DISABLED = 'disabled',\n INITIALIZATION = 'initialization',\n READY = 'ready',\n FAILED = 'failed',\n SUSPENDED = 'suspended',\n}\n\nexport interface CoreStoreInterface {\n enabled: string\n status: string\n userKey?: string\n userToken?: string\n organizationSettings?: OrganizationSettings\n organizationAdvertising?: OrganizationAdvertising\n streamSettings?: StreamSettings\n user?: User\n userSettings?: UserSettings\n providerStreamId?: string\n slStreamId?: string\n}\n\nconst initializeStore = (transport: Transport) => {\n // sdk toggle\n const enabled = new SingleStore(createSingleStore<'on'>())\n // sdk status\n const status = new SingleStore(createSingleStore<CoreStatus>(CoreStatus.DISABLED))\n // host user key\n const userKey = new SingleStore(createSingleStore<string>())\n // sl user key\n const userToken = new SingleStore(createSingleStore<string>())\n // host event id\n const providerStreamId = new SingleStore(createSingleStore<string>())\n // sl event id\n const slStreamId = new ApiStore(queries.$retrieveEventId(providerStreamId.getStore(), transport), (data) => data.data)\n // sl user data\n const user = new ApiStore(queries.$user(userToken.getStore(), transport))\n // sl user settings\n const userSettings = new ApiStore(queries.$userSettings(userToken.getStore(), transport))\n // sl stream settings\n const streamSettings = new ApiStore(queries.$streamSettings(slStreamId.getAtomStore(), transport))\n // sl organization settings\n const organizationSettings = new ApiStore(\n queries.$organizationSettings(enabled.getStore(), transport),\n (data) => data?.data?.id,\n )\n // sl organization advertising\n const organizationAdvertising = new ApiStore(\n queries.$organizationAdvertising(organizationSettings.getAtomStore(), transport),\n )\n\n return {\n enabled,\n status,\n providerStreamId,\n slStreamId,\n streamSettings,\n user,\n userKey,\n userToken,\n userSettings,\n organizationSettings,\n organizationAdvertising,\n } as const\n}\n\ntype StoreObj = ReturnType<typeof initializeStore>\nexport type CoreStores = {\n [Index in keyof StoreObj]: ReturnType<StoreObj[Index]['getStore']>\n}\nexport type CoreStoreInstance = ReturnType<typeof mergeStores<StoreObj>>\n\n/**\n * @description main app store\n */\nexport class CoreStore extends AbstractStore<CoreStoreInstance> {\n private stores: StoreObj\n\n constructor(transport: Transport) {\n const storesObj = initializeStore(transport)\n const store = mergeStores<typeof storesObj>(storesObj)\n\n super(store)\n\n this.stores = storesObj\n }\n\n getStoreItem = <T extends keyof StoreObj = keyof StoreObj>(key: T): StoreObj[T] => {\n return this.stores[key]\n }\n\n getValue(): unknown {\n throw new Error('Not implemented')\n }\n\n getValues() {\n return this.stores\n }\n\n setValue() {\n throw new Error('Not implemented')\n }\n\n subscribe = (subscribes: Partial<StoreListeners>) => {\n for (const storeKey in this.stores) {\n if (subscribes[storeKey]) {\n // wrong type infer\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n this.stores[storeKey].subscribe(subscribes[storeKey])\n }\n }\n }\n\n unsubscribe = () => {\n const store = this.getStore()\n\n return store.off()\n }\n}\n\nexport type StoreListeners = {\n [Index in keyof StoreObj]: Parameters<StoreObj[Index]['subscribe']>[0]\n}\n"],"names":["AbstractStore","createSingleStore","SingleStore","mergeStores","ApiStore","queries","CoreStatus","initializeStore","transport","enabled","status","userKey","userToken","providerStreamId","slStreamId","$retrieveEventId","getStore","data","user","$user","userSettings","$userSettings","streamSettings","$streamSettings","getAtomStore","organizationSettings","$organizationSettings","id","organizationAdvertising","$organizationAdvertising","CoreStore","constructor","storesObj","store","getStoreItem","key","stores","subscribe","subscribes","storeKey","unsubscribe","off","getValue","Error","getValues","setValue"],"mappings":"AAOA,SAASA,aAAa,EAAEC,iBAAiB,EAAEC,WAAW,EAAEC,WAAW,EAAEC,QAAQ,QAAQ,kCAAiC;AACtH,SAASC,OAAO,QAAmB,2BAA0B;;UAEjDC;;;;;;GAAAA,eAAAA;AAsBZ,MAAMC,kBAAkB,CAACC;IACvB,aAAa;IACb,MAAMC,UAAU,IAAIP,YAAYD;IAChC,aAAa;IACb,MAAMS,SAAS,IAAIR,YAAYD;IAC/B,gBAAgB;IAChB,MAAMU,UAAU,IAAIT,YAAYD;IAChC,cAAc;IACd,MAAMW,YAAY,IAAIV,YAAYD;IAClC,gBAAgB;IAChB,MAAMY,mBAAmB,IAAIX,YAAYD;IACzC,cAAc;IACd,MAAMa,aAAa,IAAIV,SAASC,QAAQU,gBAAgB,CAACF,iBAAiBG,QAAQ,IAAIR,YAAY,CAACS,OAASA,KAAKA,IAAI;IACrH,eAAe;IACf,MAAMC,OAAO,IAAId,SAASC,QAAQc,KAAK,CAACP,UAAUI,QAAQ,IAAIR;IAC9D,mBAAmB;IACnB,MAAMY,eAAe,IAAIhB,SAASC,QAAQgB,aAAa,CAACT,UAAUI,QAAQ,IAAIR;IAC9E,qBAAqB;IACrB,MAAMc,iBAAiB,IAAIlB,SAASC,QAAQkB,eAAe,CAACT,WAAWU,YAAY,IAAIhB;IACvF,2BAA2B;IAC3B,MAAMiB,uBAAuB,IAAIrB,SAC/BC,QAAQqB,qBAAqB,CAACjB,QAAQO,QAAQ,IAAIR,YAClD,CAACS,OAASA,MAAMA,MAAMU;IAExB,8BAA8B;IAC9B,MAAMC,0BAA0B,IAAIxB,SAClCC,QAAQwB,wBAAwB,CAACJ,qBAAqBD,YAAY,IAAIhB;IAGxE,OAAO;QACLC;QACAC;QACAG;QACAC;QACAQ;QACAJ;QACAP;QACAC;QACAQ;QACAK;QACAG;IACF;AACF;AAQA;;CAEC,GACD,OAAO,MAAME,kBAAkB9B;IAG7B+B,YAAYvB,SAAoB,CAAE;QAChC,MAAMwB,YAAYzB,gBAAgBC;QAClC,MAAMyB,QAAQ9B,YAA8B6B;QAE5C,KAAK,CAACC;aAKRC,eAAe,CAA4CC;YACzD,OAAO,IAAI,CAACC,MAAM,CAACD,IAAI;QACzB;aAcAE,YAAY,CAACC;YACX,IAAK,MAAMC,YAAY,IAAI,CAACH,MAAM,CAAE;gBAClC,IAAIE,UAAU,CAACC,SAAS,EAAE;oBACxB,mBAAmB;oBACnB,6DAA6D;oBAC7D,aAAa;oBACb,IAAI,CAACH,MAAM,CAACG,SAAS,CAACF,SAAS,CAACC,UAAU,CAACC,SAAS;gBACtD;YACF;QACF;aAEAC,cAAc;YACZ,MAAMP,QAAQ,IAAI,CAACjB,QAAQ;YAE3B,OAAOiB,MAAMQ,GAAG;QAClB;QAlCE,IAAI,CAACL,MAAM,GAAGJ;IAChB;IAMAU,WAAoB;QAClB,MAAM,IAAIC,MAAM;IAClB;IAEAC,YAAY;QACV,OAAO,IAAI,CAACR,MAAM;IACpB;IAEAS,WAAW;QACT,MAAM,IAAIF,MAAM;IAClB;AAkBF"}
package/src/lib/core.d.ts DELETED
@@ -1,17 +0,0 @@
1
- import { CoreStore } from './store';
2
- export declare class StreamLayerSDK {
3
- private sdkKey;
4
- private store;
5
- constructor(sdkKey: string);
6
- get sdkStore(): import("nanostores").MapStore<CoreStore>;
7
- initializeApp: () => void;
8
- disableApp: () => void;
9
- createEventSession: (providerStreamId: string) => void;
10
- authorizationBypass: () => void;
11
- logout: () => void;
12
- isUserAuthorized: () => boolean;
13
- private getOrganizationSettings;
14
- private getStreamSettings;
15
- private storeSubscribe;
16
- private storeUnsubscribe;
17
- }
package/src/lib/core.js DELETED
@@ -1,71 +0,0 @@
1
- import { $coreStore } from './store';
2
- export class StreamLayerSDK {
3
- constructor(sdkKey){
4
- this.store = $coreStore;
5
- this.initializeApp = ()=>{
6
- this.storeSubscribe();
7
- this.store.setKey('enabled', true);
8
- };
9
- this.disableApp = ()=>{
10
- this.store.setKey('enabled', false);
11
- this.storeUnsubscribe();
12
- };
13
- this.createEventSession = (providerStreamId)=>{
14
- const slStreamId = `sl-${providerStreamId}` // await api.resolveEventId(providerStreamId)
15
- ;
16
- this.store.setKey('providerStreamId', providerStreamId);
17
- this.store.setKey('slStreamId', slStreamId);
18
- };
19
- this.authorizationBypass = ()=>{
20
- const user = {
21
- id: 'test'
22
- };
23
- this.store.setKey('user', user);
24
- };
25
- this.logout = ()=>{
26
- this.store.setKey('user', undefined);
27
- };
28
- this.isUserAuthorized = ()=>{
29
- return Boolean(this.store.get().user);
30
- };
31
- this.getOrganizationSettings = ()=>{
32
- const settings = {} // await api.getOrganizationSettings()
33
- ;
34
- this.store.setKey('organizationSettings', settings);
35
- };
36
- this.getStreamSettings = (streamId)=>{
37
- const settings = {} // await api.getStreamSettings(this.store.slStreamId)
38
- ;
39
- this.store.setKey('streamSettings', settings);
40
- };
41
- this.storeSubscribe = ()=>{
42
- const subscribes = {
43
- enabled: (enabled)=>{
44
- if (enabled) {
45
- this.getOrganizationSettings();
46
- }
47
- },
48
- slStreamId: (streamId)=>{
49
- if (streamId) {
50
- this.getStreamSettings(streamId);
51
- } else {
52
- this.store.setKey('streamSettings', undefined);
53
- }
54
- }
55
- };
56
- this.store.listen((store, storeKey)=>{
57
- console.log(`${storeKey} new value ${store[storeKey]}`);
58
- subscribes[storeKey]?.(store[storeKey]);
59
- });
60
- };
61
- this.storeUnsubscribe = ()=>{
62
- this.store.off();
63
- };
64
- this.sdkKey = sdkKey;
65
- }
66
- get sdkStore() {
67
- return this.store;
68
- }
69
- }
70
-
71
- //# sourceMappingURL=core.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../../packages/sdk-web/src/lib/core.ts"],"sourcesContent":["import { $coreStore, CoreStore } from './store'\n\nexport class StreamLayerSDK {\n private sdkKey: string\n private store = $coreStore\n\n constructor(sdkKey: string) {\n this.sdkKey = sdkKey\n }\n\n get sdkStore() {\n return this.store\n }\n\n public initializeApp = () => {\n this.storeSubscribe()\n this.store.setKey('enabled', true)\n }\n\n public disableApp = () => {\n this.store.setKey('enabled', false)\n this.storeUnsubscribe()\n }\n\n public createEventSession = (providerStreamId: string) => {\n const slStreamId = `sl-${providerStreamId}` // await api.resolveEventId(providerStreamId)\n\n this.store.setKey('providerStreamId', providerStreamId)\n this.store.setKey('slStreamId', slStreamId)\n }\n\n public authorizationBypass = () => {\n const user = { id: 'test' }\n\n this.store.setKey('user', user)\n }\n\n public logout = () => {\n this.store.setKey('user', undefined)\n }\n\n public isUserAuthorized = () => {\n return Boolean(this.store.get().user)\n }\n\n private getOrganizationSettings = () => {\n const settings: any = {} // await api.getOrganizationSettings()\n\n this.store.setKey('organizationSettings', settings)\n }\n\n private getStreamSettings = (streamId: string) => {\n const settings = {} // await api.getStreamSettings(this.store.slStreamId)\n\n this.store.setKey('streamSettings', settings)\n }\n\n private storeSubscribe = () => {\n const subscribes: Partial<\n Record<keyof CoreStore, (...args: any[]) => void>\n > = {\n enabled: (enabled) => {\n if (enabled) {\n this.getOrganizationSettings()\n }\n },\n slStreamId: (streamId: string) => {\n if (streamId) {\n this.getStreamSettings(streamId)\n } else {\n this.store.setKey('streamSettings', undefined)\n }\n },\n }\n\n this.store.listen((store, storeKey) => {\n console.log(`${storeKey} new value ${store[storeKey]}`)\n subscribes[storeKey]?.(store[storeKey])\n })\n }\n\n private storeUnsubscribe = () => {\n this.store.off()\n }\n}\n"],"names":["$coreStore","StreamLayerSDK","constructor","sdkKey","store","initializeApp","storeSubscribe","setKey","disableApp","storeUnsubscribe","createEventSession","providerStreamId","slStreamId","authorizationBypass","user","id","logout","undefined","isUserAuthorized","Boolean","get","getOrganizationSettings","settings","getStreamSettings","streamId","subscribes","enabled","listen","storeKey","console","log","off","sdkStore"],"mappings":"AAAA,SAASA,UAAU,QAAmB,UAAS;AAE/C,OAAO,MAAMC;IAIXC,YAAYC,MAAc,CAAE;aAFpBC,QAAQJ;aAUTK,gBAAgB,IAAM;YAC3B,IAAI,CAACC,cAAc;YACnB,IAAI,CAACF,KAAK,CAACG,MAAM,CAAC,WAAW,IAAI;QACnC;aAEOC,aAAa,IAAM;YACxB,IAAI,CAACJ,KAAK,CAACG,MAAM,CAAC,WAAW,KAAK;YAClC,IAAI,CAACE,gBAAgB;QACvB;aAEOC,qBAAqB,CAACC,mBAA6B;YACxD,MAAMC,aAAa,CAAC,GAAG,EAAED,iBAAiB,CAAC,CAAC,6CAA6C;;YAEzF,IAAI,CAACP,KAAK,CAACG,MAAM,CAAC,oBAAoBI;YACtC,IAAI,CAACP,KAAK,CAACG,MAAM,CAAC,cAAcK;QAClC;aAEOC,sBAAsB,IAAM;YACjC,MAAMC,OAAO;gBAAEC,IAAI;YAAO;YAE1B,IAAI,CAACX,KAAK,CAACG,MAAM,CAAC,QAAQO;QAC5B;aAEOE,SAAS,IAAM;YACpB,IAAI,CAACZ,KAAK,CAACG,MAAM,CAAC,QAAQU;QAC5B;aAEOC,mBAAmB,IAAM;YAC9B,OAAOC,QAAQ,IAAI,CAACf,KAAK,CAACgB,GAAG,GAAGN,IAAI;QACtC;aAEQO,0BAA0B,IAAM;YACtC,MAAMC,WAAgB,CAAC,EAAE,sCAAsC;;YAE/D,IAAI,CAAClB,KAAK,CAACG,MAAM,CAAC,wBAAwBe;QAC5C;aAEQC,oBAAoB,CAACC,WAAqB;YAChD,MAAMF,WAAW,CAAC,EAAE,qDAAqD;;YAEzE,IAAI,CAAClB,KAAK,CAACG,MAAM,CAAC,kBAAkBe;QACtC;aAEQhB,iBAAiB,IAAM;YAC7B,MAAMmB,aAEF;gBACFC,SAAS,CAACA,UAAY;oBACpB,IAAIA,SAAS;wBACX,IAAI,CAACL,uBAAuB;oBAC9B,CAAC;gBACH;gBACAT,YAAY,CAACY,WAAqB;oBAChC,IAAIA,UAAU;wBACZ,IAAI,CAACD,iBAAiB,CAACC;oBACzB,OAAO;wBACL,IAAI,CAACpB,KAAK,CAACG,MAAM,CAAC,kBAAkBU;oBACtC,CAAC;gBACH;YACF;YAEA,IAAI,CAACb,KAAK,CAACuB,MAAM,CAAC,CAACvB,OAAOwB,WAAa;gBACrCC,QAAQC,GAAG,CAAC,CAAC,EAAEF,SAAS,WAAW,EAAExB,KAAK,CAACwB,SAAS,CAAC,CAAC;gBACtDH,UAAU,CAACG,SAAS,GAAGxB,KAAK,CAACwB,SAAS;YACxC;QACF;aAEQnB,mBAAmB,IAAM;YAC/B,IAAI,CAACL,KAAK,CAAC2B,GAAG;QAChB;QA5EE,IAAI,CAAC5B,MAAM,GAAGA;IAChB;IAEA,IAAI6B,WAAW;QACb,OAAO,IAAI,CAAC5B,KAAK;IACnB;AAwEF,CAAC"}
@@ -1,11 +0,0 @@
1
- import type { OrganizationSettings } from '@streamlayer/sdk-web-types';
2
- export interface CoreStore {
3
- enabled: boolean;
4
- organizationSettings?: OrganizationSettings;
5
- streamSettings?: Record<string, any>;
6
- user?: Record<string, any>;
7
- test?: Record<string, any>;
8
- providerStreamId?: string;
9
- slStreamId?: string;
10
- }
11
- export declare const $coreStore: import("nanostores").MapStore<CoreStore>;
@@ -1,6 +0,0 @@
1
- import { map } from 'nanostores';
2
- export const $coreStore = map({
3
- enabled: false
4
- });
5
-
6
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../../../packages/sdk-web/src/lib/store/index.ts"],"sourcesContent":["import type { OrganizationSettings } from '@streamlayer/sdk-web-types'\n\nimport { map } from 'nanostores'\n\nexport interface CoreStore {\n enabled: boolean\n organizationSettings?: OrganizationSettings\n streamSettings?: Record<string, any>\n user?: Record<string, any>\n test?: Record<string, any>\n providerStreamId?: string\n slStreamId?: string\n}\n\nexport const $coreStore = map<CoreStore>({\n enabled: false,\n})\n"],"names":["map","$coreStore","enabled"],"mappings":"AAEA,SAASA,GAAG,QAAQ,aAAY;AAYhC,OAAO,MAAMC,aAAaD,IAAe;IACvCE,SAAS,KAAK;AAChB,GAAE"}