@stream-io/feeds-client 0.3.14 → 0.3.16
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/CHANGELOG.md +18 -0
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/react-bindings.js +12 -6
- package/dist/cjs/react-bindings.js.map +1 -1
- package/dist/es/index.mjs +2 -2
- package/dist/es/index.mjs.map +1 -1
- package/dist/es/react-bindings.mjs +12 -6
- package/dist/es/react-bindings.mjs.map +1 -1
- package/dist/{feeds-client-YbhVg6cF.js → feeds-client-B6L006tr.js} +42 -9
- package/dist/feeds-client-B6L006tr.js.map +1 -0
- package/dist/{feeds-client-DoDAKYaV.mjs → feeds-client-Bh01VLai.mjs} +42 -9
- package/dist/feeds-client-Bh01VLai.mjs.map +1 -0
- package/dist/types/bindings/react/hooks/feed-state-hooks/useOwnCapabilities.d.ts +1 -1
- package/dist/types/bindings/react/hooks/feed-state-hooks/useOwnCapabilities.d.ts.map +1 -1
- package/dist/types/bindings/react/hooks/useCreateFeedsClient.d.ts +3 -3
- package/dist/types/bindings/react/hooks/useCreateFeedsClient.d.ts.map +1 -1
- package/dist/types/common/ApiClient.d.ts.map +1 -1
- package/dist/types/common/ConnectionIdManager.d.ts +3 -3
- package/dist/types/common/ConnectionIdManager.d.ts.map +1 -1
- package/dist/types/common/TokenManager.d.ts +3 -3
- package/dist/types/common/TokenManager.d.ts.map +1 -1
- package/dist/types/feeds-client/feeds-client.d.ts +5 -1
- package/dist/types/feeds-client/feeds-client.d.ts.map +1 -1
- package/dist/types/gen/models/index.d.ts +2 -0
- package/dist/types/gen/models/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/bindings/react/hooks/feed-state-hooks/useOwnCapabilities.ts +2 -2
- package/src/bindings/react/hooks/useCreateFeedsClient.ts +23 -12
- package/src/common/ApiClient.ts +4 -2
- package/src/common/ConnectionIdManager.ts +9 -7
- package/src/common/TokenManager.ts +19 -3
- package/src/common/real-time/StableWSConnection.ts +1 -1
- package/src/feeds-client/feeds-client.ts +22 -1
- package/src/gen/models/index.ts +4 -0
- package/dist/feeds-client-DoDAKYaV.mjs.map +0 -1
- package/dist/feeds-client-YbhVg6cF.js.map +0 -1
|
@@ -11,6 +11,7 @@ export class TokenManager {
|
|
|
11
11
|
type: 'static' | 'provider';
|
|
12
12
|
token?: string;
|
|
13
13
|
tokenProvider?: string | (() => Promise<string>);
|
|
14
|
+
private _isAnonymous: boolean = false;
|
|
14
15
|
private readonly logger = feedsLoggerSystem.getLogger('token-manager');
|
|
15
16
|
|
|
16
17
|
constructor() {
|
|
@@ -19,15 +20,24 @@ export class TokenManager {
|
|
|
19
20
|
this.type = 'static';
|
|
20
21
|
}
|
|
21
22
|
|
|
23
|
+
get isAnonymous() {
|
|
24
|
+
return this._isAnonymous;
|
|
25
|
+
}
|
|
26
|
+
|
|
22
27
|
/**
|
|
23
28
|
* Set the static string token or token provider.
|
|
24
29
|
* Token provider should return a token string or a promise which resolves to string token.
|
|
25
30
|
*
|
|
26
|
-
* @param {TokenOrProvider} tokenOrProvider - the token or token provider.
|
|
27
|
-
* @param {UserResponse} user - the user object.
|
|
28
|
-
* @param {boolean} isAnonymous - whether the user is anonymous or not.
|
|
31
|
+
* @param {TokenOrProvider} tokenOrProvider - the token or token provider. Providing `undefined` will set the token manager to anonymous mode.
|
|
29
32
|
*/
|
|
30
33
|
setTokenOrProvider = (tokenOrProvider?: string | (() => Promise<string>)) => {
|
|
34
|
+
if (tokenOrProvider === undefined) {
|
|
35
|
+
this._isAnonymous = true;
|
|
36
|
+
tokenOrProvider = '';
|
|
37
|
+
} else {
|
|
38
|
+
this._isAnonymous = false;
|
|
39
|
+
}
|
|
40
|
+
|
|
31
41
|
if (isFunction(tokenOrProvider)) {
|
|
32
42
|
this.tokenProvider = tokenOrProvider;
|
|
33
43
|
this.type = 'provider';
|
|
@@ -44,7 +54,9 @@ export class TokenManager {
|
|
|
44
54
|
* Useful for client disconnection or switching user.
|
|
45
55
|
*/
|
|
46
56
|
reset = () => {
|
|
57
|
+
this._isAnonymous = false;
|
|
47
58
|
this.token = undefined;
|
|
59
|
+
this.tokenProvider = undefined;
|
|
48
60
|
this.loadTokenPromise = null;
|
|
49
61
|
};
|
|
50
62
|
|
|
@@ -96,6 +108,10 @@ export class TokenManager {
|
|
|
96
108
|
|
|
97
109
|
// Returns the current token, or fetches in a new one if there is no current token
|
|
98
110
|
getToken = () => {
|
|
111
|
+
if (this._isAnonymous) {
|
|
112
|
+
return '';
|
|
113
|
+
}
|
|
114
|
+
|
|
99
115
|
if (this.token) {
|
|
100
116
|
return this.token;
|
|
101
117
|
}
|
|
@@ -93,6 +93,7 @@ import { getFeed } from '../activity-with-state-updates/get-feed';
|
|
|
93
93
|
|
|
94
94
|
export type FeedsClientState = {
|
|
95
95
|
connected_user: ConnectedUser | undefined;
|
|
96
|
+
is_anonymous: boolean;
|
|
96
97
|
is_ws_connection_healthy: boolean;
|
|
97
98
|
own_capabilities_by_fid: Record<string, FeedResponse['own_capabilities']>;
|
|
98
99
|
};
|
|
@@ -136,6 +137,7 @@ export class FeedsClient extends FeedsApi {
|
|
|
136
137
|
super(apiClient);
|
|
137
138
|
this.state = new StateStore<FeedsClientState>({
|
|
138
139
|
connected_user: undefined,
|
|
140
|
+
is_anonymous: false,
|
|
139
141
|
is_ws_connection_healthy: false,
|
|
140
142
|
own_capabilities_by_fid: {},
|
|
141
143
|
});
|
|
@@ -391,7 +393,25 @@ export class FeedsClient extends FeedsApi {
|
|
|
391
393
|
this.state.partialNext({ own_capabilities_by_fid: ownCapabilitiesCache });
|
|
392
394
|
}
|
|
393
395
|
|
|
394
|
-
|
|
396
|
+
connectAnonymous = () => {
|
|
397
|
+
this.connectionIdManager.resolveConnectionidPromise();
|
|
398
|
+
this.tokenManager.setTokenOrProvider(undefined);
|
|
399
|
+
this.setGetBatchOwnCapabilitiesThrottlingInterval(
|
|
400
|
+
this.query_batch_own_capabilties_throttling_interval,
|
|
401
|
+
);
|
|
402
|
+
this.state.partialNext({
|
|
403
|
+
connected_user: undefined,
|
|
404
|
+
is_anonymous: true,
|
|
405
|
+
is_ws_connection_healthy: false,
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
return Promise.resolve();
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
connectUser = async (
|
|
412
|
+
user: UserRequest | { id: '!anon' },
|
|
413
|
+
tokenProvider?: TokenOrProvider,
|
|
414
|
+
) => {
|
|
395
415
|
if (
|
|
396
416
|
this.state.getLatestValue().connected_user !== undefined ||
|
|
397
417
|
this.wsConnection
|
|
@@ -631,6 +651,7 @@ export class FeedsClient extends FeedsApi {
|
|
|
631
651
|
await this.wsConnection?.disconnect();
|
|
632
652
|
this.wsConnection = undefined;
|
|
633
653
|
}
|
|
654
|
+
|
|
634
655
|
removeConnectionEventListeners(this.updateNetworkConnectionStatus);
|
|
635
656
|
|
|
636
657
|
this.connectionIdManager.reset();
|
package/src/gen/models/index.ts
CHANGED
|
@@ -2752,6 +2752,8 @@ export interface FeedRequest {
|
|
|
2752
2752
|
}
|
|
2753
2753
|
|
|
2754
2754
|
export interface FeedResponse {
|
|
2755
|
+
activity_count: number;
|
|
2756
|
+
|
|
2755
2757
|
created_at: Date;
|
|
2756
2758
|
|
|
2757
2759
|
description: string;
|
|
@@ -2792,6 +2794,8 @@ export interface FeedResponse {
|
|
|
2792
2794
|
}
|
|
2793
2795
|
|
|
2794
2796
|
export interface FeedSuggestionResponse {
|
|
2797
|
+
activity_count: number;
|
|
2798
|
+
|
|
2795
2799
|
created_at: Date;
|
|
2796
2800
|
|
|
2797
2801
|
description: string;
|