@streamlayer/sdk-web-core 0.1.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/README.md +7 -0
- package/package.json +42 -0
- package/src/auth/bypass/index.d.ts +22 -0
- package/src/auth/bypass/index.js +49 -0
- package/src/auth/bypass/index.js.map +1 -0
- package/src/auth/index.d.ts +15 -0
- package/src/auth/index.js +25 -0
- package/src/auth/index.js.map +1 -0
- package/src/environments/environment.d.ts +3 -0
- package/src/environments/environment.js +6 -0
- package/src/environments/environment.js.map +1 -0
- package/src/environments/environment.prod.d.ts +3 -0
- package/src/environments/environment.prod.js +4 -0
- package/src/environments/environment.prod.js.map +1 -0
- package/src/index.d.ts +22 -0
- package/src/index.js +52 -0
- package/src/index.js.map +1 -0
- package/src/notifications/index.d.ts +17 -0
- package/src/notifications/index.js +11 -0
- package/src/notifications/index.js.map +1 -0
- package/src/notifications/notifications.d.ts +19 -0
- package/src/notifications/notifications.js +29 -0
- package/src/notifications/notifications.js.map +1 -0
- package/src/store/index.d.ts +17 -0
- package/src/store/index.js +70 -0
- package/src/store/index.js.map +1 -0
- package/src/store/store.d.ts +140 -0
- package/src/store/store.js +97 -0
- package/src/store/store.js.map +1 -0
package/README.md
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@streamlayer/sdk-web-core",
|
|
3
|
+
"dependencies": {
|
|
4
|
+
"@streamlayer/sdk-web-api": "workspace:^",
|
|
5
|
+
"@streamlayer/sdk-web-features": "*",
|
|
6
|
+
"@nanostores/query": "^0.2.4",
|
|
7
|
+
"nanostores": "^0.9.4",
|
|
8
|
+
"tslib": "^2.6.2"
|
|
9
|
+
},
|
|
10
|
+
"peerDependencies": {
|
|
11
|
+
"@streamlayer/sdk-web-interfaces": "workspace:^",
|
|
12
|
+
"@streamlayer/sdk-web-types": "workspace:^"
|
|
13
|
+
},
|
|
14
|
+
"version": "0.1.0",
|
|
15
|
+
"type": "module",
|
|
16
|
+
"main": "./src/index.js",
|
|
17
|
+
"module": "./src/index.js",
|
|
18
|
+
"typings": "./src/index.d.ts",
|
|
19
|
+
"files": [
|
|
20
|
+
"src/"
|
|
21
|
+
],
|
|
22
|
+
"exports": {
|
|
23
|
+
"./package.json": "./package.json",
|
|
24
|
+
".": "./src/index.js",
|
|
25
|
+
"./store": {
|
|
26
|
+
"types": "./src/store/index.js",
|
|
27
|
+
"import": "./src/store/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./auth": {
|
|
30
|
+
"types": "./src/auth/index.js",
|
|
31
|
+
"import": "./src/auth/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./notifications": {
|
|
34
|
+
"types": "./src/notifications/index.js",
|
|
35
|
+
"import": "./src/notifications/index.js"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@swc/helpers": "^0.5.2",
|
|
40
|
+
"tslib": "^2.6.2"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -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<import("@streamlayer/sl-eslib/users/users_common_pb").User | undefined>;
|
|
15
|
+
login: (schema: string, userKey: string) => Promise<import("@streamlayer/sl-eslib/users/users_common_pb").User | undefined>;
|
|
16
|
+
isAuthenticated: () => Promise<import("@streamlayer/sl-eslib/users/users_common_pb").User | undefined>;
|
|
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
|
+
*/
|
|
8
|
+
export class BypassAuth extends AbstractAuthenticationProvider {
|
|
9
|
+
$coreStore;
|
|
10
|
+
transport;
|
|
11
|
+
$bypassLogin;
|
|
12
|
+
constructor(store, transport) {
|
|
13
|
+
super();
|
|
14
|
+
this.$coreStore = store;
|
|
15
|
+
this.transport = transport;
|
|
16
|
+
this.$bypassLogin = queries.$bypassLogin(this.transport);
|
|
17
|
+
this.subscribe();
|
|
18
|
+
}
|
|
19
|
+
me = async () => {
|
|
20
|
+
const res = await this.$coreStore.getValues().user.getValue();
|
|
21
|
+
return res?.data;
|
|
22
|
+
};
|
|
23
|
+
login = async (schema, userKey) => {
|
|
24
|
+
this.$coreStore.getValues().userKey.setValue(userKey);
|
|
25
|
+
await this.$bypassLogin.mutate({ schema, userKey, init: false });
|
|
26
|
+
return this.me();
|
|
27
|
+
};
|
|
28
|
+
isAuthenticated = () => {
|
|
29
|
+
return this.me();
|
|
30
|
+
};
|
|
31
|
+
logout = () => {
|
|
32
|
+
this.$coreStore.getValues().user.setValue();
|
|
33
|
+
this.$coreStore.getValues().userKey.setValue();
|
|
34
|
+
this.$coreStore.getValues().userToken.setValue();
|
|
35
|
+
this.transport.setAuth('');
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* subscribe to user store and set auth header to the Transport on user update
|
|
39
|
+
*/
|
|
40
|
+
subscribe = () => {
|
|
41
|
+
this.$bypassLogin.subscribe((user, key) => {
|
|
42
|
+
if (key === 'data') {
|
|
43
|
+
this.transport.setAuth(user?.data?.meta?.jwt);
|
|
44
|
+
this.$coreStore.getValues().userToken.setValue(user?.data?.meta?.jwt);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/sdk-web-core/src/auth/bypass/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAE,MAAM,iCAAiC,CAAA;AAChF,OAAO,EAAE,OAAO,EAAa,MAAM,0BAA0B,CAAA;AAI7D;;;;GAIG;AACH,MAAM,OAAO,UAAW,SAAQ,8BAA8B;IAC3C,UAAU,CAAW;IACrB,SAAS,CAAW;IACpB,YAAY,CAAyC;IAEtE,YAAY,KAAgB,EAAE,SAAoB;QAChD,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,UAAU,GAAG,KAAK,CAAA;QACvB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC1B,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;QAExD,IAAI,CAAC,SAAS,EAAE,CAAA;IAClB,CAAC;IAEM,EAAE,GAAG,KAAK,IAAI,EAAE;QACrB,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAA;QAE7D,OAAO,GAAG,EAAE,IAAI,CAAA;IAClB,CAAC,CAAA;IAEM,KAAK,GAAG,KAAK,EAAE,MAAc,EAAE,OAAe,EAAE,EAAE;QACvD,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE,CAAC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bypass';
|
|
4
|
+
declare module '@streamlayer/sdk-web-interfaces' {
|
|
5
|
+
interface StreamLayerSDK {
|
|
6
|
+
authorizationBypass: (schema: string, userKey: string) => Promise<void>;
|
|
7
|
+
logout: () => void;
|
|
8
|
+
getUserStore: () => CoreStores['user'];
|
|
9
|
+
isUserAuthorized: BypassAuth['isAuthenticated'];
|
|
10
|
+
}
|
|
11
|
+
interface StreamLayerContext {
|
|
12
|
+
auth: BypassAuth;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export declare const bypass: (instance: StreamLayerContext, opts: unknown, done: () => void) => Promise<void>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { BypassAuth } from './bypass';
|
|
2
|
+
export const bypass = async (instance, opts, done) => {
|
|
3
|
+
instance.auth = new BypassAuth(instance.store, instance.transport);
|
|
4
|
+
const prevUserSchema = localStorage.getItem('sl-user-schema');
|
|
5
|
+
const prevUserToken = localStorage.getItem('sl-user-token');
|
|
6
|
+
if (prevUserSchema && prevUserToken) {
|
|
7
|
+
console.log('try to login prev user');
|
|
8
|
+
await instance.auth.login(prevUserSchema, prevUserToken);
|
|
9
|
+
}
|
|
10
|
+
instance.sdk.authorizationBypass = async (schema, userKey) => {
|
|
11
|
+
await instance.auth.login(schema, userKey);
|
|
12
|
+
localStorage.setItem('sl-user-schema', schema);
|
|
13
|
+
};
|
|
14
|
+
instance.sdk.logout = () => {
|
|
15
|
+
instance.auth.logout();
|
|
16
|
+
};
|
|
17
|
+
instance.sdk.getUserStore = () => {
|
|
18
|
+
return instance.stores.user.getStore();
|
|
19
|
+
};
|
|
20
|
+
instance.sdk.isUserAuthorized = () => {
|
|
21
|
+
return instance.auth.isAuthenticated();
|
|
22
|
+
};
|
|
23
|
+
done();
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/sdk-web-core/src/auth/index.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E,CAAA;AACR,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environment.js","sourceRoot":"","sources":["../../../../../packages/sdk-web-core/src/environments/environment.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,kFAAkF;AAElF,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,UAAU,EAAE,KAAK;CAClB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environment.prod.js","sourceRoot":"","sources":["../../../../../packages/sdk-web-core/src/environments/environment.prod.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,UAAU,EAAE,IAAI;CACjB,CAAA"}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { StreamLayerContext } from '@streamlayer/sdk-web-interfaces';
|
|
2
|
+
declare module '@streamlayer/sdk-web-interfaces' {
|
|
3
|
+
interface StreamLayerSDK {
|
|
4
|
+
initializeApp: () => Promise<{
|
|
5
|
+
enabled?: boolean;
|
|
6
|
+
err?: string;
|
|
7
|
+
}>;
|
|
8
|
+
disableApp: () => void;
|
|
9
|
+
createEventSession: (providerStreamId: string) => void;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The main application instance is the core of a application. It includes:
|
|
14
|
+
* Store: Manages data storage.
|
|
15
|
+
* Public Methods: Provides a way to interact with the application.
|
|
16
|
+
* Connect Features: Handles communication between components throught store.
|
|
17
|
+
* Connect Transport: Handles communication with api.
|
|
18
|
+
* Dependency Injection: Incorporates other necessary instances.
|
|
19
|
+
* Error Handling: Manages errors and logs them.
|
|
20
|
+
* Security: Implements authentication and authorization.
|
|
21
|
+
*/
|
|
22
|
+
export declare const core: (instance: StreamLayerContext, opts: unknown, done: () => void) => void;
|
package/src/index.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { CoreStatus } from './store/store';
|
|
2
|
+
/**
|
|
3
|
+
* The main application instance is the core of a application. It includes:
|
|
4
|
+
* Store: Manages data storage.
|
|
5
|
+
* Public Methods: Provides a way to interact with the application.
|
|
6
|
+
* Connect Features: Handles communication between components throught store.
|
|
7
|
+
* Connect Transport: Handles communication with api.
|
|
8
|
+
* Dependency Injection: Incorporates other necessary instances.
|
|
9
|
+
* Error Handling: Manages errors and logs them.
|
|
10
|
+
* Security: Implements authentication and authorization.
|
|
11
|
+
*/
|
|
12
|
+
export const core = (instance, opts, done) => {
|
|
13
|
+
instance.sdk = Object.create(null);
|
|
14
|
+
/**
|
|
15
|
+
* On initialize we subscribe to store and launch listeners
|
|
16
|
+
* that activate data downloading over the network
|
|
17
|
+
*/
|
|
18
|
+
instance.sdk.initializeApp = async () => {
|
|
19
|
+
instance.storeSubscribe();
|
|
20
|
+
instance.stores.enabled.setValue('on');
|
|
21
|
+
instance.stores.status.setValue(CoreStatus.INITIALIZATION);
|
|
22
|
+
try {
|
|
23
|
+
const organizationSettings = await instance.stores.organizationSettings.getValue();
|
|
24
|
+
if (organizationSettings) {
|
|
25
|
+
instance.stores.status.setValue(CoreStatus.READY);
|
|
26
|
+
return { enabled: !!organizationSettings };
|
|
27
|
+
}
|
|
28
|
+
instance.stores.status.setValue(CoreStatus.FAILED);
|
|
29
|
+
return { err: 'failed' };
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
instance.stores.enabled.setValue();
|
|
33
|
+
instance.stores.status.setValue(CoreStatus.FAILED);
|
|
34
|
+
return { err: `${err}` };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
instance.sdk.disableApp = () => {
|
|
38
|
+
instance.stores.enabled.setValue();
|
|
39
|
+
instance.stores.status.setValue(CoreStatus.DISABLED);
|
|
40
|
+
instance.storeUnsubscribe();
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Configure the "event id" using the "provider," enabling subscribed stores to
|
|
44
|
+
* trigger their logic in response to a new event.
|
|
45
|
+
*/
|
|
46
|
+
instance.sdk.createEventSession = (providerStreamId) => {
|
|
47
|
+
instance.stores.providerStreamId.setValue('');
|
|
48
|
+
instance.stores.providerStreamId.setValue(providerStreamId);
|
|
49
|
+
};
|
|
50
|
+
done();
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/sdk-web-core/src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAU1C;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,QAA4B,EAAE,IAAa,EAAE,IAAgB,EAAE,EAAE;IACpF,QAAQ,CAAC,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAElC;;;OAGG;IACH,QAAQ,CAAC,GAAG,CAAC,aAAa,GAAG,KAAK,IAAI,EAAE;QACtC,QAAQ,CAAC,cAAc,EAAE,CAAA;QACzB,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;QACtC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,cAAc,CAAC,CAAA;QAE1D,IAAI;YACF,MAAM,oBAAoB,GAAG,MAAM,QAAQ,CAAC,MAAM,CAAC,oBAAoB,CAAC,QAAQ,EAAE,CAAA;YAElF,IAAI,oBAAoB,EAAE;gBACxB,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;gBAEjD,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC,oBAAoB,EAAE,CAAA;aAC3C;YAED,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA;YAElD,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAA;SACzB;QAAC,OAAO,GAAG,EAAE;YACZ,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAA;YAClC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA;YAElD,OAAO,EAAE,GAAG,EAAE,GAAG,GAAG,EAAE,EAAE,CAAA;SACzB;IACH,CAAC,CAAA;IAED,QAAQ,CAAC,GAAG,CAAC,UAAU,GAAG,GAAG,EAAE;QAC7B,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAA;QAClC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;QACpD,QAAQ,CAAC,gBAAgB,EAAE,CAAA;IAC7B,CAAC,CAAA;IAED;;;OAGG;IACH,QAAQ,CAAC,GAAG,CAAC,kBAAkB,GAAG,CAAC,gBAAwB,EAAE,EAAE;QAC7D,QAAQ,CAAC,MAAM,CAAC,gBAAgB,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;QAC7C,QAAQ,CAAC,MAAM,CAAC,gBAAgB,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAA;IAC7D,CAAC,CAAA;IAED,IAAI,EAAE,CAAA;AACR,CAAC,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { StreamLayerContext } from '@streamlayer/sdk-web-interfaces';
|
|
2
|
+
import { Notifications } from './notifications';
|
|
3
|
+
export type { Nofitication } from './notifications';
|
|
4
|
+
export type NotificationsStore = ReturnType<Notifications['getQueueStore']>;
|
|
5
|
+
declare module '@streamlayer/sdk-web-interfaces' {
|
|
6
|
+
interface StreamLayerContext {
|
|
7
|
+
notifications: Notifications;
|
|
8
|
+
addNotification: Notifications['add'];
|
|
9
|
+
}
|
|
10
|
+
interface StreamLayerSDK {
|
|
11
|
+
getNotificationsStore: Notifications['getQueueStore'];
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* notifications plugin, connect notifications to sdk
|
|
16
|
+
*/
|
|
17
|
+
export declare const notifications: (instance: StreamLayerContext, opts: unknown, done: () => void) => void;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Notifications } from './notifications';
|
|
2
|
+
/**
|
|
3
|
+
* notifications plugin, connect notifications to sdk
|
|
4
|
+
*/
|
|
5
|
+
export const notifications = (instance, opts, done) => {
|
|
6
|
+
instance.notifications = new Notifications();
|
|
7
|
+
instance.addNotification = instance.notifications.add;
|
|
8
|
+
instance.sdk.getNotificationsStore = () => instance.notifications.getQueueStore();
|
|
9
|
+
done();
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/sdk-web-core/src/notifications/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAgB/C;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,QAA4B,EAAE,IAAa,EAAE,IAAgB,EAAE,EAAE;IAC7F,QAAQ,CAAC,aAAa,GAAG,IAAI,aAAa,EAAE,CAAA;IAC5C,QAAQ,CAAC,eAAe,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAA;IACrD,QAAQ,CAAC,GAAG,CAAC,qBAAqB,GAAG,GAAG,EAAE,CAAC,QAAQ,CAAC,aAAa,CAAC,aAAa,EAAE,CAAA;IAEjF,IAAI,EAAE,CAAA;AACR,CAAC,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { SingleStore } from '@streamlayer/sdk-web-interfaces';
|
|
2
|
+
export type Nofitication<T extends Record<string, unknown> = any> = {
|
|
3
|
+
variant?: 'default' | 'error' | 'success' | 'warning' | 'info';
|
|
4
|
+
autoHideDuration?: number;
|
|
5
|
+
delay?: number;
|
|
6
|
+
data?: T;
|
|
7
|
+
id: string;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* @description app notifications (inapp)
|
|
11
|
+
*/
|
|
12
|
+
export declare class Notifications {
|
|
13
|
+
queue: SingleStore<Nofitication[]>;
|
|
14
|
+
constructor();
|
|
15
|
+
add: (notification: Nofitication) => void;
|
|
16
|
+
getQueueStore: () => import("nanostores").WritableAtom<Nofitication<any>[] | undefined>;
|
|
17
|
+
isNewNotify: (id: string) => boolean;
|
|
18
|
+
markAsViewed: (id: string) => void;
|
|
19
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { SingleStore, createSingleStore } from '@streamlayer/sdk-web-interfaces';
|
|
2
|
+
/**
|
|
3
|
+
* @description app notifications (inapp)
|
|
4
|
+
*/
|
|
5
|
+
export class Notifications {
|
|
6
|
+
queue;
|
|
7
|
+
constructor() {
|
|
8
|
+
this.queue = new SingleStore(createSingleStore([]), 'notifications');
|
|
9
|
+
}
|
|
10
|
+
add = (notification) => {
|
|
11
|
+
if (this.isNewNotify(notification.id)) {
|
|
12
|
+
this.queue.getStore().set([...(this.queue.getValue() || []), notification]);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
console.log('skip notification:', notification);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
getQueueStore = () => {
|
|
19
|
+
return this.queue.getStore();
|
|
20
|
+
};
|
|
21
|
+
isNewNotify = (id) => {
|
|
22
|
+
const exist = localStorage.getItem(`opened:${id}`);
|
|
23
|
+
return !exist;
|
|
24
|
+
};
|
|
25
|
+
markAsViewed = (id) => {
|
|
26
|
+
localStorage.setItem(`opened:${id}`, id);
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=notifications.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notifications.js","sourceRoot":"","sources":["../../../../../packages/sdk-web-core/src/notifications/notifications.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAA;AAWhF;;GAEG;AACH,MAAM,OAAO,aAAa;IACxB,KAAK,CAA6B;IAElC;QACE,IAAI,CAAC,KAAK,GAAG,IAAI,WAAW,CAAC,iBAAiB,CAAiB,EAAE,CAAC,EAAE,eAAe,CAAC,CAAA;IACtF,CAAC;IAED,GAAG,GAAG,CAAC,YAA0B,EAAE,EAAE;QACnC,IAAI,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,EAAE,CAAC,EAAE;YACrC,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,EAAE,YAAY,CAAC,CAAC,CAAA;SAC5E;aAAM;YACL,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAAE,YAAY,CAAC,CAAA;SAChD;IACH,CAAC,CAAA;IAED,aAAa,GAAG,GAAG,EAAE;QACnB,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAA;IAC9B,CAAC,CAAA;IAED,WAAW,GAAG,CAAC,EAAU,EAAE,EAAE;QAC3B,MAAM,KAAK,GAAG,YAAY,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAA;QAElD,OAAO,CAAC,KAAK,CAAA;IACf,CAAC,CAAA;IAED,YAAY,GAAG,CAAC,EAAU,EAAE,EAAE;QAC5B,YAAY,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,EAAE,EAAE,CAAC,CAAA;IAC1C,CAAC,CAAA;CACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { StreamLayerContext } from '@streamlayer/sdk-web-interfaces';
|
|
2
|
+
import { CoreStore, StoreObj, CoreStoreInstance } from './store';
|
|
3
|
+
declare module '@streamlayer/sdk-web-interfaces' {
|
|
4
|
+
interface StreamLayerSDK {
|
|
5
|
+
sdkStore: CoreStoreInstance;
|
|
6
|
+
}
|
|
7
|
+
interface StreamLayerContext {
|
|
8
|
+
store: CoreStore;
|
|
9
|
+
stores: StoreObj;
|
|
10
|
+
storeSubscribe: () => void;
|
|
11
|
+
storeUnsubscribe: () => void;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* store plugin, connect store to sdk
|
|
16
|
+
*/
|
|
17
|
+
export declare const store: (instance: StreamLayerContext, opts: unknown, done: () => void) => void;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { FeatureSource } from '@streamlayer/sdk-web-interfaces';
|
|
2
|
+
import { CoreStore } from './store';
|
|
3
|
+
/**
|
|
4
|
+
* store plugin, connect store to sdk
|
|
5
|
+
*/
|
|
6
|
+
export const store = (instance, opts, done) => {
|
|
7
|
+
instance.store = new CoreStore(instance.transport);
|
|
8
|
+
instance.stores = instance.store.getValues();
|
|
9
|
+
instance.sdk.sdkStore = instance.store.getStore();
|
|
10
|
+
/**
|
|
11
|
+
* Essentially, features and stores establish subscriptions to other stores
|
|
12
|
+
* based on their dependencies. In certain cases, specific logic is
|
|
13
|
+
* directly invoked in response to changes in the store.
|
|
14
|
+
*/
|
|
15
|
+
instance.storeSubscribe = () => {
|
|
16
|
+
const processSettings = (source, settings) => {
|
|
17
|
+
if (!settings?.overlays)
|
|
18
|
+
return;
|
|
19
|
+
if (source === FeatureSource.STREAM) {
|
|
20
|
+
instance.features.clear();
|
|
21
|
+
}
|
|
22
|
+
for (const overlay of settings.overlays) {
|
|
23
|
+
const featureName = overlay.name;
|
|
24
|
+
if (!instance.features.has(featureName)) {
|
|
25
|
+
instance.initFeature(overlay, source);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
instance.updateFeature(overlay, source);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const subscribes = {
|
|
33
|
+
/**
|
|
34
|
+
* During the initial SDK initialization, it's imperative to initialize features first,
|
|
35
|
+
* followed by their direct subscriptions to store fields.
|
|
36
|
+
* This section is currently in development, and it's
|
|
37
|
+
* essential to implement checks to determine whether a feature
|
|
38
|
+
* has already been initialized. If it has, events related to
|
|
39
|
+
* that feature should be skipped. Conversely, if a feature is
|
|
40
|
+
* missing in the new settings, it should be deinitialized.
|
|
41
|
+
*/
|
|
42
|
+
organizationSettings: (orgSettings) => {
|
|
43
|
+
if (orgSettings.data) {
|
|
44
|
+
try {
|
|
45
|
+
processSettings(FeatureSource.ORGANIZATION, orgSettings.data);
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
console.log(err);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
streamSettings: (streamSettings) => {
|
|
53
|
+
if (streamSettings.data) {
|
|
54
|
+
try {
|
|
55
|
+
processSettings(FeatureSource.STREAM, streamSettings.data);
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
console.log(err);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
instance.store.subscribe(subscribes);
|
|
64
|
+
};
|
|
65
|
+
instance.storeUnsubscribe = () => {
|
|
66
|
+
instance.store.unsubscribe();
|
|
67
|
+
};
|
|
68
|
+
done();
|
|
69
|
+
};
|
|
70
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/sdk-web-core/src/store/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAsB,MAAM,iCAAiC,CAAA;AAGnF,OAAO,EAAE,SAAS,EAAmE,MAAM,SAAS,CAAA;AAepG;;GAEG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,QAA4B,EAAE,IAAa,EAAE,IAAgB,EAAE,EAAE;IACrF,QAAQ,CAAC,KAAK,GAAG,IAAI,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAA;I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AC,MAAM,EAAE,cAAc,CAAC,IAAI,CAAC,CAAA;qBAC3D;oBAAC,OAAO,GAAG,EAAE;wBACZ,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;qBACjB;iBACF;YACH,CAAC;SACF,CAAA;QAED,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC,UAAU,CAAC,CAAA;IACtC,CAAC,CAAA;IAED,QAAQ,CAAC,gBAAgB,GAAG,GAAG,EAAE;QAC/B,QAAQ,CAAC,KAAK,CAAC,WAAW,EAAE,CAAA;IAC9B,CAAC,CAAA;IAED,IAAI,EAAE,CAAA;AACR,CAAC,CAAA"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import type { OrganizationAdvertising, StreamSettings, OrganizationSettings, User, UserSettings } from '@streamlayer/sdk-web-types';
|
|
2
|
+
import { AbstractStore, SingleStore, ApiStore } from '@streamlayer/sdk-web-interfaces';
|
|
3
|
+
import { Transport } from '@streamlayer/sdk-web-api';
|
|
4
|
+
import { ReadableAtom } from 'nanostores';
|
|
5
|
+
import { FetcherValue } from '@nanostores/query';
|
|
6
|
+
export declare enum CoreStatus {
|
|
7
|
+
DISABLED = "disabled",
|
|
8
|
+
INITIALIZATION = "initialization",
|
|
9
|
+
READY = "ready",
|
|
10
|
+
FAILED = "failed",
|
|
11
|
+
SUSPENDED = "suspended"
|
|
12
|
+
}
|
|
13
|
+
export interface CoreStoreInterface {
|
|
14
|
+
enabled?: 'on';
|
|
15
|
+
status: string;
|
|
16
|
+
userKey?: string;
|
|
17
|
+
userToken?: string;
|
|
18
|
+
organizationSettings?: OrganizationSettings & {
|
|
19
|
+
id: string;
|
|
20
|
+
};
|
|
21
|
+
organizationAdvertising?: OrganizationAdvertising;
|
|
22
|
+
streamSettings?: StreamSettings;
|
|
23
|
+
user?: User;
|
|
24
|
+
userSettings?: UserSettings;
|
|
25
|
+
providerStreamId?: string;
|
|
26
|
+
slStreamId?: string;
|
|
27
|
+
}
|
|
28
|
+
declare const initializeStore: (transport: Transport) => {
|
|
29
|
+
readonly enabled: SingleStore<unknown, import("nanostores").WritableAtom<"on" | undefined>>;
|
|
30
|
+
readonly status: SingleStore<unknown, import("nanostores").WritableAtom<CoreStatus | undefined>>;
|
|
31
|
+
readonly providerStreamId: SingleStore<unknown, import("nanostores").WritableAtom<string | undefined>>;
|
|
32
|
+
readonly slStreamId: ApiStore<string | undefined, import("@nanostores/query").FetcherStore<string | undefined>>;
|
|
33
|
+
readonly streamSettings: ApiStore<import("@streamlayer/sl-eslib/sdkSettings/sdkSettings.common_pb").StreamSettings | undefined, import("@nanostores/query").FetcherStore<import("@streamlayer/sl-eslib/sdkSettings/sdkSettings.common_pb").StreamSettings | undefined>>;
|
|
34
|
+
readonly user: ApiStore<import("@streamlayer/sl-eslib/users/users_pb").MeResponse | undefined, import("@nanostores/query").FetcherStore<import("@streamlayer/sl-eslib/users/users_pb").MeResponse | undefined>>;
|
|
35
|
+
readonly userKey: SingleStore<unknown, import("nanostores").WritableAtom<string | undefined>>;
|
|
36
|
+
readonly userToken: SingleStore<unknown, import("nanostores").WritableAtom<string | undefined>>;
|
|
37
|
+
readonly userSettings: ApiStore<import("@streamlayer/sl-eslib/sdkSettings/client/client_pb").ClientSettings | undefined, import("@nanostores/query").FetcherStore<import("@streamlayer/sl-eslib/sdkSettings/client/client_pb").ClientSettings | undefined>>;
|
|
38
|
+
readonly organizationSettings: ApiStore<{
|
|
39
|
+
id: string;
|
|
40
|
+
overlays?: import("@streamlayer/sl-eslib/sdkSettings/sdkSettings.common_pb").SdkOverlay[] | undefined;
|
|
41
|
+
buttonIcon?: string | undefined;
|
|
42
|
+
tinodeHost?: string | undefined;
|
|
43
|
+
audience?: string | undefined;
|
|
44
|
+
name?: string | undefined;
|
|
45
|
+
provider?: string | undefined;
|
|
46
|
+
primaryColor?: string | undefined;
|
|
47
|
+
secondaryColor?: string | undefined;
|
|
48
|
+
moderationPrimaryColor?: string | undefined;
|
|
49
|
+
linkShareIcon?: string | undefined;
|
|
50
|
+
linkShareText?: string | undefined;
|
|
51
|
+
brandDefaults?: import("@streamlayer/sl-eslib/sdkSettings/sdkSettings.common_pb").BrandDefaults | undefined;
|
|
52
|
+
pub?: import("@streamlayer/sl-eslib/sdkSettings/sdkSettings.common_pb").JWK | undefined;
|
|
53
|
+
getstream?: import("@streamlayer/sl-eslib/sdkSettings/sdkSettings.common_pb").GetStreamSettingsClient | undefined;
|
|
54
|
+
} | undefined, import("@nanostores/query").FetcherStore<{
|
|
55
|
+
id: string;
|
|
56
|
+
overlays?: import("@streamlayer/sl-eslib/sdkSettings/sdkSettings.common_pb").SdkOverlay[] | undefined;
|
|
57
|
+
buttonIcon?: string | undefined;
|
|
58
|
+
tinodeHost?: string | undefined;
|
|
59
|
+
audience?: string | undefined;
|
|
60
|
+
name?: string | undefined;
|
|
61
|
+
provider?: string | undefined;
|
|
62
|
+
primaryColor?: string | undefined;
|
|
63
|
+
secondaryColor?: string | undefined;
|
|
64
|
+
moderationPrimaryColor?: string | undefined;
|
|
65
|
+
linkShareIcon?: string | undefined;
|
|
66
|
+
linkShareText?: string | undefined;
|
|
67
|
+
brandDefaults?: import("@streamlayer/sl-eslib/sdkSettings/sdkSettings.common_pb").BrandDefaults | undefined;
|
|
68
|
+
pub?: import("@streamlayer/sl-eslib/sdkSettings/sdkSettings.common_pb").JWK | undefined;
|
|
69
|
+
getstream?: import("@streamlayer/sl-eslib/sdkSettings/sdkSettings.common_pb").GetStreamSettingsClient | undefined;
|
|
70
|
+
} | undefined>>;
|
|
71
|
+
readonly organizationAdvertising: ApiStore<import("@streamlayer/sl-eslib/sdkSettings/sdkSettings.common_pb").Advertising | undefined, import("@nanostores/query").FetcherStore<import("@streamlayer/sl-eslib/sdkSettings/sdkSettings.common_pb").Advertising | undefined>>;
|
|
72
|
+
};
|
|
73
|
+
export type StoreObj = ReturnType<typeof initializeStore>;
|
|
74
|
+
export type CoreStores = {
|
|
75
|
+
[Index in keyof StoreObj]: ReturnType<StoreObj[Index]['getStore']>;
|
|
76
|
+
};
|
|
77
|
+
export type CoreStoresValues = {
|
|
78
|
+
[Index in keyof StoreObj]: ReturnType<StoreObj[Index]['getStore']>['value'];
|
|
79
|
+
};
|
|
80
|
+
export type CoreStoreInstance = ReadableAtom<CoreStoresValues>;
|
|
81
|
+
/**
|
|
82
|
+
* @description main app store
|
|
83
|
+
*/
|
|
84
|
+
export declare class CoreStore extends AbstractStore<CoreStoreInstance> {
|
|
85
|
+
private stores;
|
|
86
|
+
constructor(transport: Transport);
|
|
87
|
+
getValue(): unknown;
|
|
88
|
+
getValues(): {
|
|
89
|
+
readonly enabled: SingleStore<unknown, import("nanostores").WritableAtom<"on" | undefined>>;
|
|
90
|
+
readonly status: SingleStore<unknown, import("nanostores").WritableAtom<CoreStatus | undefined>>;
|
|
91
|
+
readonly providerStreamId: SingleStore<unknown, import("nanostores").WritableAtom<string | undefined>>;
|
|
92
|
+
readonly slStreamId: ApiStore<string | undefined, import("@nanostores/query").FetcherStore<string | undefined>>;
|
|
93
|
+
readonly streamSettings: ApiStore<import("@streamlayer/sl-eslib/sdkSettings/sdkSettings.common_pb").StreamSettings | undefined, import("@nanostores/query").FetcherStore<import("@streamlayer/sl-eslib/sdkSettings/sdkSettings.common_pb").StreamSettings | undefined>>;
|
|
94
|
+
readonly user: ApiStore<import("@streamlayer/sl-eslib/users/users_pb").MeResponse | undefined, import("@nanostores/query").FetcherStore<import("@streamlayer/sl-eslib/users/users_pb").MeResponse | undefined>>;
|
|
95
|
+
readonly userKey: SingleStore<unknown, import("nanostores").WritableAtom<string | undefined>>;
|
|
96
|
+
readonly userToken: SingleStore<unknown, import("nanostores").WritableAtom<string | undefined>>;
|
|
97
|
+
readonly userSettings: ApiStore<import("@streamlayer/sl-eslib/sdkSettings/client/client_pb").ClientSettings | undefined, import("@nanostores/query").FetcherStore<import("@streamlayer/sl-eslib/sdkSettings/client/client_pb").ClientSettings | undefined>>;
|
|
98
|
+
readonly organizationSettings: ApiStore<{
|
|
99
|
+
id: string;
|
|
100
|
+
overlays?: import("@streamlayer/sl-eslib/sdkSettings/sdkSettings.common_pb").SdkOverlay[] | undefined;
|
|
101
|
+
buttonIcon?: string | undefined;
|
|
102
|
+
tinodeHost?: string | undefined;
|
|
103
|
+
audience?: string | undefined;
|
|
104
|
+
name?: string | undefined;
|
|
105
|
+
provider?: string | undefined;
|
|
106
|
+
primaryColor?: string | undefined;
|
|
107
|
+
secondaryColor?: string | undefined;
|
|
108
|
+
moderationPrimaryColor?: string | undefined;
|
|
109
|
+
linkShareIcon?: string | undefined;
|
|
110
|
+
linkShareText?: string | undefined;
|
|
111
|
+
brandDefaults?: import("@streamlayer/sl-eslib/sdkSettings/sdkSettings.common_pb").BrandDefaults | undefined;
|
|
112
|
+
pub?: import("@streamlayer/sl-eslib/sdkSettings/sdkSettings.common_pb").JWK | undefined;
|
|
113
|
+
getstream?: import("@streamlayer/sl-eslib/sdkSettings/sdkSettings.common_pb").GetStreamSettingsClient | undefined;
|
|
114
|
+
} | undefined, import("@nanostores/query").FetcherStore<{
|
|
115
|
+
id: string;
|
|
116
|
+
overlays?: import("@streamlayer/sl-eslib/sdkSettings/sdkSettings.common_pb").SdkOverlay[] | undefined;
|
|
117
|
+
buttonIcon?: string | undefined;
|
|
118
|
+
tinodeHost?: string | undefined;
|
|
119
|
+
audience?: string | undefined;
|
|
120
|
+
name?: string | undefined;
|
|
121
|
+
provider?: string | undefined;
|
|
122
|
+
primaryColor?: string | undefined;
|
|
123
|
+
secondaryColor?: string | undefined;
|
|
124
|
+
moderationPrimaryColor?: string | undefined;
|
|
125
|
+
linkShareIcon?: string | undefined;
|
|
126
|
+
linkShareText?: string | undefined;
|
|
127
|
+
brandDefaults?: import("@streamlayer/sl-eslib/sdkSettings/sdkSettings.common_pb").BrandDefaults | undefined;
|
|
128
|
+
pub?: import("@streamlayer/sl-eslib/sdkSettings/sdkSettings.common_pb").JWK | undefined;
|
|
129
|
+
getstream?: import("@streamlayer/sl-eslib/sdkSettings/sdkSettings.common_pb").GetStreamSettingsClient | undefined;
|
|
130
|
+
} | undefined>>;
|
|
131
|
+
readonly organizationAdvertising: ApiStore<import("@streamlayer/sl-eslib/sdkSettings/sdkSettings.common_pb").Advertising | undefined, import("@nanostores/query").FetcherStore<import("@streamlayer/sl-eslib/sdkSettings/sdkSettings.common_pb").Advertising | undefined>>;
|
|
132
|
+
};
|
|
133
|
+
setValue(): void;
|
|
134
|
+
subscribe: (subscribes: Partial<StoreListeners>) => void;
|
|
135
|
+
unsubscribe: () => void;
|
|
136
|
+
}
|
|
137
|
+
export type StoreListeners = {
|
|
138
|
+
[Index in keyof StoreObj]: (params: FetcherValue<CoreStoreInterface[Index]>) => void;
|
|
139
|
+
};
|
|
140
|
+
export {};
|
|
@@ -0,0 +1,97 @@
|
|
|
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(), 'enabled');
|
|
14
|
+
// sdk status
|
|
15
|
+
const status = new SingleStore(createSingleStore(CoreStatus.DISABLED), 'status');
|
|
16
|
+
// host user key
|
|
17
|
+
const userKey = new SingleStore(createSingleStore(), 'userKey');
|
|
18
|
+
// sl user key
|
|
19
|
+
const userToken = new SingleStore(createSingleStore(), 'userToken');
|
|
20
|
+
userToken.listen((token) => {
|
|
21
|
+
if (token) {
|
|
22
|
+
localStorage.setItem('sl-user-token', token);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
localStorage.removeItem('sl-user-token');
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
// host event id
|
|
29
|
+
const providerStreamId = new SingleStore(createSingleStore(), 'providerStreamId');
|
|
30
|
+
// sl event id
|
|
31
|
+
const slStreamId = new ApiStore(queries.$retrieveEventId(providerStreamId.getStore(), transport), 'slStreamId', (data) => data?.data);
|
|
32
|
+
// sl user data
|
|
33
|
+
const user = new ApiStore(queries.$user(userToken.getStore(), transport), 'user', (data) => data?.data?.data?.id);
|
|
34
|
+
// sl user settings
|
|
35
|
+
const userSettings = new ApiStore(queries.$userSettings(userToken.getStore(), transport), 'userSettings');
|
|
36
|
+
// sl stream settings
|
|
37
|
+
const streamSettings = new ApiStore(queries.$streamSettings(slStreamId.getAtomStore(), transport), 'streamSettings');
|
|
38
|
+
slStreamId.getAtomStore().listen((eventId) => {
|
|
39
|
+
if (eventId === '' || eventId === undefined) {
|
|
40
|
+
streamSettings.getStore().mutate(undefined);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
// sl organization settings
|
|
44
|
+
const organizationSettings = new ApiStore(queries.$organizationSettings(enabled.getStore(), transport), 'organizationSettings', (data) => data?.data?.id);
|
|
45
|
+
// sl organization advertising
|
|
46
|
+
const organizationAdvertising = new ApiStore(queries.$organizationAdvertising(organizationSettings.getAtomStore(), transport), 'organizationAdvertising');
|
|
47
|
+
return {
|
|
48
|
+
enabled,
|
|
49
|
+
status,
|
|
50
|
+
providerStreamId,
|
|
51
|
+
slStreamId,
|
|
52
|
+
streamSettings,
|
|
53
|
+
user,
|
|
54
|
+
userKey,
|
|
55
|
+
userToken,
|
|
56
|
+
userSettings,
|
|
57
|
+
organizationSettings,
|
|
58
|
+
organizationAdvertising,
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* @description main app store
|
|
63
|
+
*/
|
|
64
|
+
export class CoreStore extends AbstractStore {
|
|
65
|
+
stores;
|
|
66
|
+
constructor(transport) {
|
|
67
|
+
const storesObj = initializeStore(transport);
|
|
68
|
+
const store = mergeStores(storesObj);
|
|
69
|
+
super(store, 'core');
|
|
70
|
+
this.stores = storesObj;
|
|
71
|
+
}
|
|
72
|
+
getValue() {
|
|
73
|
+
throw new Error('Not implemented');
|
|
74
|
+
}
|
|
75
|
+
getValues() {
|
|
76
|
+
return this.stores;
|
|
77
|
+
}
|
|
78
|
+
setValue() {
|
|
79
|
+
throw new Error('Not implemented');
|
|
80
|
+
}
|
|
81
|
+
subscribe = (subscribes) => {
|
|
82
|
+
let storeKey;
|
|
83
|
+
for (storeKey in this.stores) {
|
|
84
|
+
const fn = subscribes[storeKey];
|
|
85
|
+
if (storeKey in subscribes && fn !== undefined) {
|
|
86
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
87
|
+
// @ts-ignore
|
|
88
|
+
this.stores[storeKey].subscribe(subscribes[storeKey]);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
unsubscribe = () => {
|
|
93
|
+
const store = this.getStore();
|
|
94
|
+
return store.off();
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../../../../packages/sdk-web-core/src/store/store.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAA;AACtH,OAAO,EAAE,OAAO,EAAiC,MAAM,0BAA0B,CAAA;AAKjF,MAAM,CAAN,IAAY,UAMX;AAND,WAAY,UAAU;IACpB,mCAAqB,CAAA;IACrB,+CAAiC,CAAA;IACjC,6BAAe,CAAA;IACf,+BAAiB,CAAA;IACjB,qCAAuB,CAAA;AACzB,CAAC,EANW,UAAU,KAAV,UAAU,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