@streamlayer/sdk-web-core 0.17.7 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/auth/bypass/index.js +0 -4
- package/lib/auth/index.d.ts +2 -1
- package/lib/auth/index.js +9 -3
- package/lib/index.d.ts +1 -1
- package/lib/index.js +6 -1
- package/lib/store/index.d.ts +9 -2
- package/lib/store/index.js +1 -1
- package/lib/store/init.js +12 -1
- package/package.json +6 -6
package/lib/auth/bypass/index.js
CHANGED
|
@@ -60,8 +60,6 @@ export class BypassAuth extends AbstractAuthenticationProvider {
|
|
|
60
60
|
*/
|
|
61
61
|
softLogout = () => {
|
|
62
62
|
const storage = new UserStorage();
|
|
63
|
-
this.$coreStore.getValues().user.setValue();
|
|
64
|
-
this.$coreStore.getValues().userToken.setValue();
|
|
65
63
|
this.transport.setAuth('', '');
|
|
66
64
|
storage.setToken('');
|
|
67
65
|
void this.reLogin();
|
|
@@ -78,11 +76,9 @@ export class BypassAuth extends AbstractAuthenticationProvider {
|
|
|
78
76
|
const prevUserToken = storage.getToken();
|
|
79
77
|
const prevUserExternalToken = storage.getExternalToken();
|
|
80
78
|
this.$coreStore.getValues().userKey.setValue(prevUserExternalToken);
|
|
81
|
-
this.$coreStore.getValues().userToken.setValue(prevUserToken);
|
|
82
79
|
if (prevUserToken) {
|
|
83
80
|
this.saveUser(prevUserToken, '');
|
|
84
81
|
return this.me().then((user) => {
|
|
85
|
-
console.log('user', user);
|
|
86
82
|
if (user?.id) {
|
|
87
83
|
const userId = user.id;
|
|
88
84
|
this.saveUser(prevUserToken, userId);
|
package/lib/auth/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StreamLayerContext } from '@streamlayer/sdk-web-interfaces';
|
|
2
|
-
import { CoreStores } from '../store/store';
|
|
2
|
+
import { CoreStores, StoreObj } from '../store/store';
|
|
3
3
|
import { UserStorage } from '../storage';
|
|
4
4
|
import { BypassAuth } from './bypass';
|
|
5
5
|
declare module '@streamlayer/sdk-web-interfaces' {
|
|
@@ -7,6 +7,7 @@ declare module '@streamlayer/sdk-web-interfaces' {
|
|
|
7
7
|
authorizationBypass: (schema: string, userKey: string) => Promise<void>;
|
|
8
8
|
logout: () => void;
|
|
9
9
|
getUserStore: () => CoreStores['user'];
|
|
10
|
+
userId: StoreObj['user']['getAtomStore'];
|
|
10
11
|
isUserAuthorized: BypassAuth['isAuthenticated'];
|
|
11
12
|
}
|
|
12
13
|
interface StreamLayerContext {
|
package/lib/auth/index.js
CHANGED
|
@@ -13,15 +13,21 @@ export const bypass = (instance, opts, done) => {
|
|
|
13
13
|
void instance.auth.reLogin();
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
|
+
instance.sdk.userId = instance.stores.user.getAtomStore;
|
|
16
17
|
instance.sdk.authorizationBypass = async (schema, userKey) => {
|
|
17
18
|
if (storage.getSchema() === schema &&
|
|
18
19
|
storage.getExternalToken() === userKey &&
|
|
19
20
|
instance.transport.getHeader('authorization')) {
|
|
20
21
|
return;
|
|
21
22
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
try {
|
|
24
|
+
await instance.auth.login(schema, userKey);
|
|
25
|
+
storage.setSchema(schema);
|
|
26
|
+
storage.setExternalToken(userKey);
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
instance.sdk.logout();
|
|
30
|
+
}
|
|
25
31
|
};
|
|
26
32
|
instance.sdk.logout = () => {
|
|
27
33
|
instance.auth.logout();
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -19,7 +19,8 @@ export const core = (instance, opts, done) => {
|
|
|
19
19
|
* On initialize we subscribe to store and launch listeners
|
|
20
20
|
* that activate data downloading over the network
|
|
21
21
|
*/
|
|
22
|
-
instance.sdk.initializeApp = async () => {
|
|
22
|
+
instance.sdk.initializeApp = async (contextConfig) => {
|
|
23
|
+
instance.contextConfig = contextConfig;
|
|
23
24
|
if (instance.stores.enabled.get() === 'on') {
|
|
24
25
|
return { enabled: true };
|
|
25
26
|
}
|
|
@@ -47,7 +48,11 @@ export const core = (instance, opts, done) => {
|
|
|
47
48
|
}
|
|
48
49
|
instance.stores.enabled.setValue();
|
|
49
50
|
instance.stores.status.setValue(CoreStatus.DISABLED);
|
|
51
|
+
instance.stores.slStreamId.setValue();
|
|
52
|
+
instance.stores.providerStreamId.setValue();
|
|
53
|
+
instance.sdk.closeFeature(true);
|
|
50
54
|
instance.storeUnsubscribe();
|
|
55
|
+
instance.transport.disconnect();
|
|
51
56
|
};
|
|
52
57
|
/**
|
|
53
58
|
* Configure the "event id" using the "provider," enabling subscribed stores to
|
package/lib/store/index.d.ts
CHANGED
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
import { StreamLayerContext } from '@streamlayer/sdk-web-interfaces';
|
|
2
|
-
import { CoreStore, CoreStores, StoreObj
|
|
2
|
+
import { CoreStore, CoreStores, StoreObj } from './store';
|
|
3
3
|
declare module '@streamlayer/sdk-web-interfaces' {
|
|
4
4
|
interface StreamLayerSDK {
|
|
5
|
-
sdkStore:
|
|
5
|
+
sdkStore: CoreStores;
|
|
6
6
|
enabled: CoreStores['enabled'];
|
|
7
7
|
status: CoreStores['status'];
|
|
8
8
|
organizationStore: () => CoreStores['organizationSettings'];
|
|
9
9
|
streamStore: () => CoreStores['streamSettings'];
|
|
10
10
|
}
|
|
11
|
+
interface ContextConfig {
|
|
12
|
+
skipOrganizationSettings?: boolean;
|
|
13
|
+
}
|
|
14
|
+
interface StreamLayerContext {
|
|
15
|
+
contextConfig?: ContextConfig;
|
|
16
|
+
}
|
|
11
17
|
interface StreamLayerContext {
|
|
12
18
|
store: CoreStore;
|
|
13
19
|
stores: StoreObj;
|
|
14
20
|
storeSubscribe: () => void;
|
|
15
21
|
storeUnsubscribe: () => void;
|
|
22
|
+
contextConfig?: ContextConfig;
|
|
16
23
|
}
|
|
17
24
|
}
|
|
18
25
|
/**
|
package/lib/store/index.js
CHANGED
|
@@ -7,7 +7,7 @@ export const store = (instance, opts, done) => {
|
|
|
7
7
|
instance.stores = instance.store.getValues();
|
|
8
8
|
instance.sdk.enabled = instance.stores.enabled.getStore();
|
|
9
9
|
instance.sdk.status = instance.stores.status.getStore();
|
|
10
|
-
instance.sdk.sdkStore = instance.store.getStore();
|
|
10
|
+
instance.sdk.sdkStore = Object.fromEntries(Object.entries(instance.stores).map(([key, store]) => [key, store.getStore()]));
|
|
11
11
|
instance.sdk.organizationStore = () => instance.stores.organizationSettings.getStore();
|
|
12
12
|
instance.sdk.streamStore = () => instance.stores.streamSettings.getStore();
|
|
13
13
|
instance.storeUnsubscribe = () => {
|
package/lib/store/init.js
CHANGED
|
@@ -16,7 +16,18 @@ const initializeUserStores = (transport) => {
|
|
|
16
16
|
// sl user key
|
|
17
17
|
const userToken = new SingleStore(createSingleStore(storage.getToken()), 'userToken');
|
|
18
18
|
// sl user data
|
|
19
|
-
const user = new ApiStore(queries.$user(userToken.getStore(), transport), 'user', (data) =>
|
|
19
|
+
const user = new ApiStore(queries.$user(userToken.getStore(), transport), 'user', ({ data, error, loading }, prev) => {
|
|
20
|
+
if (error) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
if (data?.data?.id) {
|
|
24
|
+
return data.data.id;
|
|
25
|
+
}
|
|
26
|
+
else if (loading === false) {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
return prev;
|
|
30
|
+
});
|
|
20
31
|
// sl user settings
|
|
21
32
|
const userSettings = new ApiStore(queries.$userSettings(userToken.getStore(), transport), 'userSettings');
|
|
22
33
|
return {
|
package/package.json
CHANGED
|
@@ -5,12 +5,12 @@
|
|
|
5
5
|
},
|
|
6
6
|
"peerDependencies": {
|
|
7
7
|
"@nanostores/query": "^0.2.8",
|
|
8
|
+
"@streamlayer/sl-eslib": "^5.63.3",
|
|
8
9
|
"nanostores": "^0.9.5",
|
|
9
|
-
"@streamlayer/
|
|
10
|
-
"@streamlayer/sdk-web-interfaces": "^0.
|
|
11
|
-
"@streamlayer/sdk-web-storage": "^0.
|
|
12
|
-
"@streamlayer/sdk-web-
|
|
13
|
-
"@streamlayer/sdk-web-types": "^0.20.0"
|
|
10
|
+
"@streamlayer/sdk-web-api": "^0.19.0",
|
|
11
|
+
"@streamlayer/sdk-web-interfaces": "^0.19.0",
|
|
12
|
+
"@streamlayer/sdk-web-storage": "^0.3.11",
|
|
13
|
+
"@streamlayer/sdk-web-types": "^0.21.0"
|
|
14
14
|
},
|
|
15
15
|
"exports": {
|
|
16
16
|
".": {
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"default": "./lib/auth/index.js"
|
|
40
40
|
}
|
|
41
41
|
},
|
|
42
|
-
"version": "0.
|
|
42
|
+
"version": "0.18.0",
|
|
43
43
|
"type": "module",
|
|
44
44
|
"main": "./lib/index.js",
|
|
45
45
|
"module": "./lib/index.js",
|