@amityco/ts-sdk-react-native 7.9.3-172f3f5.0 → 7.10.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/.env +26 -26
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/core/errors.d.ts +3 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/core/errors.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/core/errors.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/domains/client.d.ts +11 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/domains/client.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/domains/client.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/domains/user.d.ts +6 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/domains/user.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/domains/user.js +6 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/domains/user.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/index.d.ts +1 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/index.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/index.js +1 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/index.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/categoryRepository/api/getCategory.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/categoryRepository/api/getCategory.js +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/categoryRepository/api/getCategory.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/activeUser.d.ts +1 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/activeUser.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/activeUser.js +1 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/activeUser.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/createClient.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/createClient.js +3 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/createClient.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/getBotToken.d.ts +21 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/getBotToken.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/getBotToken.js +27 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/getBotToken.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/getCurrentUser.d.ts +2 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/getCurrentUser.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/getCurrentUser.js +21 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/getCurrentUser.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/getCurrentUserType.d.ts +3 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/getCurrentUserType.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/getCurrentUserType.js +16 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/getCurrentUserType.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/getToken.d.ts +1 -3
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/getToken.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/getToken.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/getVisitorToken.d.ts +24 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/getVisitorToken.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/getVisitorToken.js +30 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/getVisitorToken.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/index.d.ts +4 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/index.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/index.js +4 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/index.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/login.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/login.js +4 -4
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/login.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/loginAsBot.d.ts +24 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/loginAsBot.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/loginAsBot.js +95 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/loginAsBot.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/loginAsVisitor.d.ts +26 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/loginAsVisitor.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/loginAsVisitor.js +92 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/loginAsVisitor.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/renewal.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/renewal.js +35 -2
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/renewal.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/utils/setBotClientToken.d.ts +16 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/utils/setBotClientToken.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/utils/setBotClientToken.js +29 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/utils/setBotClientToken.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/utils/setClientToken.d.ts +2 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/utils/setClientToken.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/utils/setClientToken.js +2 -2
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/utils/setClientToken.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/utils/setCurrentUser.d.ts +5 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/utils/setCurrentUser.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/utils/setCurrentUser.js +9 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/utils/setCurrentUser.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/utils/setVisitorClientToken.d.ts +21 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/utils/setVisitorClientToken.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/utils/setVisitorClientToken.js +34 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/utils/setVisitorClientToken.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/core/transports/http.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/core/transports/http.js +4 -4
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/core/transports/http.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/tsconfig.tsbuildinfo +1 -1
- package/dist/@types/core/errors.d.ts +3 -1
- package/dist/@types/core/errors.d.ts.map +1 -1
- package/dist/@types/domains/client.d.ts +11 -0
- package/dist/@types/domains/client.d.ts.map +1 -1
- package/dist/@types/domains/user.d.ts +6 -0
- package/dist/@types/domains/user.d.ts.map +1 -1
- package/dist/@types/index.d.ts +1 -0
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/categoryRepository/api/getCategory.d.ts.map +1 -1
- package/dist/client/api/activeUser.d.ts +1 -0
- package/dist/client/api/activeUser.d.ts.map +1 -1
- package/dist/client/api/createClient.d.ts.map +1 -1
- package/dist/client/api/getBotToken.d.ts +21 -0
- package/dist/client/api/getBotToken.d.ts.map +1 -0
- package/dist/client/api/getCurrentUser.d.ts +2 -0
- package/dist/client/api/getCurrentUser.d.ts.map +1 -0
- package/dist/client/api/getCurrentUserType.d.ts +3 -0
- package/dist/client/api/getCurrentUserType.d.ts.map +1 -0
- package/dist/client/api/getToken.d.ts +1 -3
- package/dist/client/api/getToken.d.ts.map +1 -1
- package/dist/client/api/getVisitorToken.d.ts +24 -0
- package/dist/client/api/getVisitorToken.d.ts.map +1 -0
- package/dist/client/api/index.d.ts +4 -0
- package/dist/client/api/index.d.ts.map +1 -1
- package/dist/client/api/login.d.ts.map +1 -1
- package/dist/client/api/loginAsBot.d.ts +24 -0
- package/dist/client/api/loginAsBot.d.ts.map +1 -0
- package/dist/client/api/loginAsVisitor.d.ts +26 -0
- package/dist/client/api/loginAsVisitor.d.ts.map +1 -0
- package/dist/client/api/renewal.d.ts.map +1 -1
- package/dist/client/utils/setBotClientToken.d.ts +16 -0
- package/dist/client/utils/setBotClientToken.d.ts.map +1 -0
- package/dist/client/utils/setClientToken.d.ts +2 -1
- package/dist/client/utils/setClientToken.d.ts.map +1 -1
- package/dist/client/utils/setCurrentUser.d.ts +5 -0
- package/dist/client/utils/setCurrentUser.d.ts.map +1 -0
- package/dist/client/utils/setVisitorClientToken.d.ts +21 -0
- package/dist/client/utils/setVisitorClientToken.d.ts.map +1 -0
- package/dist/core/transports/http.d.ts.map +1 -1
- package/dist/index.cjs.js +394 -40
- package/dist/index.esm.js +395 -41
- package/dist/index.umd.js +3 -3
- package/package.json +1 -1
- package/src/@types/core/errors.ts +2 -0
- package/src/@types/domains/client.ts +17 -0
- package/src/@types/domains/user.ts +8 -0
- package/src/@types/index.ts +1 -0
- package/src/categoryRepository/api/getCategory.ts +3 -1
- package/src/client/api/activeUser.ts +1 -0
- package/src/client/api/createClient.ts +3 -5
- package/src/client/api/getBotToken.ts +44 -0
- package/src/client/api/getCurrentUser.ts +32 -0
- package/src/client/api/getCurrentUserType.ts +23 -0
- package/src/client/api/getToken.ts +1 -1
- package/src/client/api/getVisitorToken.ts +47 -0
- package/src/client/api/index.ts +6 -0
- package/src/client/api/login.ts +5 -4
- package/src/client/api/loginAsBot.ts +125 -0
- package/src/client/api/loginAsVisitor.ts +129 -0
- package/src/client/api/renewal.ts +42 -2
- package/src/client/utils/setBotClientToken.ts +35 -0
- package/src/client/utils/setClientToken.ts +2 -2
- package/src/client/utils/setCurrentUser.ts +15 -0
- package/src/client/utils/setVisitorClientToken.ts +40 -0
- package/src/core/transports/http.ts +5 -4
- package/tsconfig.tsbuildinfo +1 -1
package/package.json
CHANGED
|
@@ -90,6 +90,8 @@ declare global {
|
|
|
90
90
|
getMarkerSyncConsistentMode: () => boolean;
|
|
91
91
|
|
|
92
92
|
prefixDeviceIdKey?: string;
|
|
93
|
+
|
|
94
|
+
getVisitorDeviceId: () => Promise<string>;
|
|
93
95
|
};
|
|
94
96
|
|
|
95
97
|
type Device = {
|
|
@@ -108,10 +110,20 @@ declare global {
|
|
|
108
110
|
expiresAt: string;
|
|
109
111
|
};
|
|
110
112
|
|
|
113
|
+
type SessionResponse = Tokens & {
|
|
114
|
+
users: Amity.RawUser[];
|
|
115
|
+
userType: Amity.UserType;
|
|
116
|
+
};
|
|
117
|
+
|
|
111
118
|
type AccessTokenRenewal = {
|
|
112
119
|
renew: () => void;
|
|
113
120
|
renewWithAuthToken: (authToken: string) => void;
|
|
114
121
|
unableToRetrieveAuthToken: () => void;
|
|
122
|
+
renewWithAuthSignature: ({
|
|
123
|
+
authSignature,
|
|
124
|
+
authSignatureExpiresAt,
|
|
125
|
+
}: Amity.ConnectClientAsVisitorParams) => void;
|
|
126
|
+
unableToRetrieveAuthSignature: () => void;
|
|
115
127
|
};
|
|
116
128
|
|
|
117
129
|
interface SessionHandler {
|
|
@@ -164,6 +176,11 @@ declare global {
|
|
|
164
176
|
deviceId?: Amity.Device['deviceId'];
|
|
165
177
|
};
|
|
166
178
|
|
|
179
|
+
type ConnectClientAsVisitorParams = {
|
|
180
|
+
authSignature?: string;
|
|
181
|
+
authSignatureExpiresAt?: string;
|
|
182
|
+
};
|
|
183
|
+
|
|
167
184
|
type ConnectClientConfig = {
|
|
168
185
|
disableRTE: boolean;
|
|
169
186
|
};
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { AmityUserSearchMatchType } from '~/userRepository';
|
|
2
2
|
|
|
3
|
+
export const enum UserTypeEnum {
|
|
4
|
+
SIGNED_IN = 'signed-in',
|
|
5
|
+
VISITOR = 'visitor',
|
|
6
|
+
BOT = 'bot',
|
|
7
|
+
}
|
|
8
|
+
|
|
3
9
|
export {};
|
|
4
10
|
|
|
5
11
|
declare global {
|
|
@@ -29,6 +35,8 @@ declare global {
|
|
|
29
35
|
| 'onUnflagged'
|
|
30
36
|
| 'onFlagCleared';
|
|
31
37
|
|
|
38
|
+
type UserType = `${UserTypeEnum}`;
|
|
39
|
+
|
|
32
40
|
type RawUser = {
|
|
33
41
|
_id: string;
|
|
34
42
|
userId: string;
|
package/src/@types/index.ts
CHANGED
|
@@ -37,7 +37,9 @@ export const getCategory = async (
|
|
|
37
37
|
const { categories } = data;
|
|
38
38
|
|
|
39
39
|
return {
|
|
40
|
-
data: LinkedObject.category(
|
|
40
|
+
data: LinkedObject.category(
|
|
41
|
+
(categories ?? []).find(category => category.categoryId === categoryId)!,
|
|
42
|
+
),
|
|
41
43
|
cachedAt,
|
|
42
44
|
};
|
|
43
45
|
};
|
|
@@ -3,11 +3,7 @@ import { VERSION } from '~/version';
|
|
|
3
3
|
import { createLogger } from '~/core/debug';
|
|
4
4
|
|
|
5
5
|
import { API_REGIONS, computeUrl } from '~/client/utils/endpoints';
|
|
6
|
-
import {
|
|
7
|
-
createHttpTransport,
|
|
8
|
-
createMqttTransport,
|
|
9
|
-
createWebsocketTransport,
|
|
10
|
-
} from '~/core/transports';
|
|
6
|
+
import { createHttpTransport, createMqttTransport } from '~/core/transports';
|
|
11
7
|
|
|
12
8
|
import { createEventEmitter } from '~/core/events';
|
|
13
9
|
|
|
@@ -22,6 +18,7 @@ import { getFeedSettings } from './getFeedSettings';
|
|
|
22
18
|
import { accessTokenExpiryWatcher } from './accessTokenExpiryWatcher';
|
|
23
19
|
import { getMarkerSyncConsistentMode } from '../utils/markerSyncEngine';
|
|
24
20
|
import { onRTEConnectionStateChange } from './onRTEConnectionStateChange';
|
|
21
|
+
import { getDeviceId } from '~/core/device';
|
|
25
22
|
|
|
26
23
|
const DEFAULT_DEBUG_SESSION = 'amity';
|
|
27
24
|
|
|
@@ -122,6 +119,7 @@ export const createClient = (
|
|
|
122
119
|
validateTexts,
|
|
123
120
|
getFeedSettings,
|
|
124
121
|
getSocialSettings,
|
|
122
|
+
getVisitorDeviceId: getDeviceId,
|
|
125
123
|
getMessagePreviewSetting,
|
|
126
124
|
|
|
127
125
|
onRTEConnectionStateChange,
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { getActiveClient } from './activeClient';
|
|
2
|
+
|
|
3
|
+
import { getDeviceInfo } from '~/core/device';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Retrieves a pair of {@link Amity.Tokens} necessary for connection
|
|
7
|
+
*
|
|
8
|
+
* @param param get bot token param
|
|
9
|
+
* @param params.deviceId The user's device Id (can be manually set for native users)
|
|
10
|
+
* @param options get bot token options
|
|
11
|
+
* @param options.setAccessTokenCookie The authentication token - necessary when network option is set to secure
|
|
12
|
+
* @return The accessToken for the given userId
|
|
13
|
+
*
|
|
14
|
+
* @category Client API
|
|
15
|
+
* @hidden
|
|
16
|
+
*/
|
|
17
|
+
export const getBotToken = async ({
|
|
18
|
+
params,
|
|
19
|
+
options,
|
|
20
|
+
}: {
|
|
21
|
+
params: { deviceId: string };
|
|
22
|
+
options?: { setAccessTokenCookie?: boolean };
|
|
23
|
+
}) => {
|
|
24
|
+
const client = getActiveClient();
|
|
25
|
+
client.log('client/api/getBotToken');
|
|
26
|
+
|
|
27
|
+
const deviceInfo = getDeviceInfo();
|
|
28
|
+
|
|
29
|
+
const { data } = await client.http.post<Amity.SessionResponse>(
|
|
30
|
+
'/api/v5/sessions/bot',
|
|
31
|
+
{
|
|
32
|
+
...params,
|
|
33
|
+
deviceInfo,
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
headers: {
|
|
37
|
+
'X-API-Key': client.apiKey,
|
|
38
|
+
'set-access-token-cookie': options?.setAccessTokenCookie || false,
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
return data;
|
|
44
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ASCError } from '~/core/errors';
|
|
2
|
+
import { getActiveClient } from './activeClient';
|
|
3
|
+
import { pullFromCache } from '~/cache/api';
|
|
4
|
+
import { userLinkedObject } from '~/utils/linkedObject/userLinkedObject';
|
|
5
|
+
|
|
6
|
+
/* begin_public_function
|
|
7
|
+
id: client.get_current_user
|
|
8
|
+
*/
|
|
9
|
+
export const getCurrentUser = (): Amity.User => {
|
|
10
|
+
const client = getActiveClient();
|
|
11
|
+
|
|
12
|
+
if (!client) {
|
|
13
|
+
throw new ASCError(
|
|
14
|
+
'Connect client first',
|
|
15
|
+
Amity.ClientError.UNKNOWN_ERROR,
|
|
16
|
+
Amity.ErrorLevel.FATAL,
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const cache = pullFromCache<Amity.User>(['user', 'get', client.userId])?.data!;
|
|
21
|
+
|
|
22
|
+
if (!cache) {
|
|
23
|
+
throw new ASCError(
|
|
24
|
+
'Connect client first',
|
|
25
|
+
Amity.ClientError.UNKNOWN_ERROR,
|
|
26
|
+
Amity.ErrorLevel.FATAL,
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return userLinkedObject(cache);
|
|
31
|
+
};
|
|
32
|
+
/* end_public_function */
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ASCError } from '~/core/errors';
|
|
2
|
+
|
|
3
|
+
let currentUserType: Amity.UserType | null = null;
|
|
4
|
+
|
|
5
|
+
/* begin_public_function
|
|
6
|
+
id: client.get_current_user_type
|
|
7
|
+
*/
|
|
8
|
+
export const getCurrentUserType = () => {
|
|
9
|
+
if (!currentUserType) {
|
|
10
|
+
throw new ASCError(
|
|
11
|
+
'Connect client first',
|
|
12
|
+
Amity.ClientError.UNKNOWN_ERROR,
|
|
13
|
+
Amity.ErrorLevel.FATAL,
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return currentUserType!;
|
|
18
|
+
};
|
|
19
|
+
/* end_public_function */
|
|
20
|
+
|
|
21
|
+
export const setCurrentUserType = (userType: Amity.UserType) => {
|
|
22
|
+
currentUserType = userType;
|
|
23
|
+
};
|
|
@@ -31,7 +31,7 @@ export const getToken = async ({
|
|
|
31
31
|
|
|
32
32
|
const deviceInfo = getDeviceInfo();
|
|
33
33
|
|
|
34
|
-
const { data } = await client.http.post<Amity.
|
|
34
|
+
const { data } = await client.http.post<Amity.SessionResponse>(
|
|
35
35
|
'/api/v5/sessions',
|
|
36
36
|
{
|
|
37
37
|
...params,
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { getActiveClient } from './activeClient';
|
|
2
|
+
|
|
3
|
+
import { getDeviceInfo } from '~/core/device';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Retrieves a pair of {@link Amity.Tokens} necessary for connection
|
|
7
|
+
*
|
|
8
|
+
* @param params get visitor token param
|
|
9
|
+
* @param params.deviceId The user's device Id (can be manually set for native users)
|
|
10
|
+
* @param params.authSignature The authenitcation signature - necessary when network option is set to secure
|
|
11
|
+
* @param params.authSignatureExpiresAt Expire time of the authenitcation signature
|
|
12
|
+
* @param options get bot token options
|
|
13
|
+
* @param options.setAccessTokenCookie The authentication token - necessary when network option is set to secure
|
|
14
|
+
* @return The accessToken for the given userId
|
|
15
|
+
*
|
|
16
|
+
*
|
|
17
|
+
* @category Client API
|
|
18
|
+
* @hidden
|
|
19
|
+
*/
|
|
20
|
+
export const getVisitorToken = async ({
|
|
21
|
+
params,
|
|
22
|
+
options,
|
|
23
|
+
}: {
|
|
24
|
+
params: Amity.ConnectClientAsVisitorParams & { deviceId: string };
|
|
25
|
+
options?: { setAccessTokenCookie?: boolean };
|
|
26
|
+
}) => {
|
|
27
|
+
const client = getActiveClient();
|
|
28
|
+
client.log('client/api/getVisitorToken', params);
|
|
29
|
+
|
|
30
|
+
const deviceInfo = getDeviceInfo();
|
|
31
|
+
|
|
32
|
+
const { data } = await client.http.post<Amity.SessionResponse>(
|
|
33
|
+
'/api/v5/sessions/visitor',
|
|
34
|
+
{
|
|
35
|
+
...params,
|
|
36
|
+
deviceInfo,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
headers: {
|
|
40
|
+
'X-API-Key': client.apiKey,
|
|
41
|
+
'set-access-token-cookie': options?.setAccessTokenCookie || false,
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
return data;
|
|
47
|
+
};
|
package/src/client/api/index.ts
CHANGED
|
@@ -29,3 +29,9 @@ export * from './fetchLinkPreview';
|
|
|
29
29
|
export * from './getSocialSettings';
|
|
30
30
|
|
|
31
31
|
export * from './getShareableLinkConfiguration';
|
|
32
|
+
|
|
33
|
+
export * from './loginAsVisitor';
|
|
34
|
+
export * from './loginAsBot';
|
|
35
|
+
|
|
36
|
+
export * from './getCurrentUser';
|
|
37
|
+
export * from './getCurrentUserType';
|
package/src/client/api/login.ts
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import { modifyMqttConnection } from '~/client/utils/modifyMqttConnection';
|
|
3
3
|
/* eslint-disable require-atomic-updates */
|
|
4
4
|
import { getDeviceId } from '~/core/device';
|
|
5
|
-
import { proxyWebsocketEvents } from '~/core/events';
|
|
6
5
|
import { onChannelDeleted } from '~/channelRepository/events/onChannelDeleted';
|
|
7
6
|
import { onChannelMemberBanned } from '~/channelRepository/events/onChannelMemberBanned';
|
|
8
7
|
|
|
@@ -29,6 +28,8 @@ import { removeChannelMarkerCache } from '../utils/removeChannelMarkerCache';
|
|
|
29
28
|
import { initializeMessagePreviewSetting } from '../utils/messagePreviewEngine';
|
|
30
29
|
import { ASCError } from '~/core/errors';
|
|
31
30
|
import SessionWatcher from '../utils/SessionWatcher';
|
|
31
|
+
import { setCurrentUserType } from './getCurrentUserType';
|
|
32
|
+
import { setCurrentUser } from '../utils/setCurrentUser';
|
|
32
33
|
|
|
33
34
|
/*
|
|
34
35
|
* declared earlier to accomodate case when logging in with a different user
|
|
@@ -91,7 +92,7 @@ export const login = async (
|
|
|
91
92
|
const defaultDeviceId = await getDeviceId();
|
|
92
93
|
|
|
93
94
|
try {
|
|
94
|
-
const { users } = await setClientToken({
|
|
95
|
+
const { users, userType } = await setClientToken({
|
|
95
96
|
params: {
|
|
96
97
|
...params,
|
|
97
98
|
displayName: params?.displayName,
|
|
@@ -117,7 +118,7 @@ export const login = async (
|
|
|
117
118
|
return false;
|
|
118
119
|
}
|
|
119
120
|
|
|
120
|
-
if (user.
|
|
121
|
+
if (user.isGlobalBan) {
|
|
121
122
|
terminateClient(Amity.TokenTerminationReason.GLOBAL_BAN);
|
|
122
123
|
return false;
|
|
123
124
|
}
|
|
@@ -132,7 +133,7 @@ export const login = async (
|
|
|
132
133
|
*/
|
|
133
134
|
unsubWatcher = client.accessTokenExpiryWatcher(sessionHandler);
|
|
134
135
|
|
|
135
|
-
|
|
136
|
+
setCurrentUser({ user, userType });
|
|
136
137
|
} catch (error) {
|
|
137
138
|
/*
|
|
138
139
|
* if getting token failed session state reverts to initial state when app
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/* eslint-disable no-param-reassign */
|
|
2
|
+
import { modifyMqttConnection } from '~/client/utils/modifyMqttConnection';
|
|
3
|
+
/* eslint-disable require-atomic-updates */
|
|
4
|
+
import { getDeviceId } from '~/core/device';
|
|
5
|
+
import { logout } from './logout';
|
|
6
|
+
|
|
7
|
+
import { getActiveClient } from './activeClient';
|
|
8
|
+
import { terminateClient } from './terminateClient';
|
|
9
|
+
import { setActiveUser } from './activeUser';
|
|
10
|
+
|
|
11
|
+
import { onTokenExpired } from '../events/onTokenExpired';
|
|
12
|
+
import { onTokenTerminated } from '../events/onTokenTerminated';
|
|
13
|
+
import { initializeMessagePreviewSetting } from '../utils/messagePreviewEngine';
|
|
14
|
+
|
|
15
|
+
import SessionWatcher from '../utils/SessionWatcher';
|
|
16
|
+
import { setBotClientToken } from '../utils/setBotClientToken';
|
|
17
|
+
import { setCurrentUser } from '../utils/setCurrentUser';
|
|
18
|
+
|
|
19
|
+
/*
|
|
20
|
+
* declared earlier to accomodate case when logging in with a different user
|
|
21
|
+
* than the one already connected, in which case the existing subscriptions need
|
|
22
|
+
* to be cleared
|
|
23
|
+
*/
|
|
24
|
+
const subscriptions: Amity.Unsubscriber[] = [];
|
|
25
|
+
|
|
26
|
+
/* begin_public_function
|
|
27
|
+
id: client.loginAsBot
|
|
28
|
+
*/
|
|
29
|
+
/**
|
|
30
|
+
* ```js
|
|
31
|
+
* import { loginAsBot } from '@amityco/ts-sdk/client/api'
|
|
32
|
+
* const success = await loginAsBot({
|
|
33
|
+
sessionHandler: {
|
|
34
|
+
sessionWillRenewAccessToken(renewal: Amity.AccessTokenRenewal) {
|
|
35
|
+
...
|
|
36
|
+
}
|
|
37
|
+
* })
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* Connects an {@link Amity.Client} instance to ASC servers
|
|
41
|
+
*
|
|
42
|
+
* @param params. the connect parameters
|
|
43
|
+
* @param params.sessionHandler
|
|
44
|
+
* @returns a success boolean if connected
|
|
45
|
+
*
|
|
46
|
+
* @category Client API
|
|
47
|
+
* @async
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
export const loginAsBot = async (params: {
|
|
51
|
+
sessionHandler: Amity.SessionHandler;
|
|
52
|
+
}): Promise<boolean> => {
|
|
53
|
+
const client = getActiveClient();
|
|
54
|
+
let unsubWatcher: Amity.Unsubscriber;
|
|
55
|
+
|
|
56
|
+
client.log('client/api/connectClient', {
|
|
57
|
+
apiKey: client.apiKey,
|
|
58
|
+
sessionState: client.sessionState,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// generate deviceId
|
|
62
|
+
const deviceId = await getDeviceId();
|
|
63
|
+
let user: Amity.RawUser;
|
|
64
|
+
|
|
65
|
+
try {
|
|
66
|
+
const { users, userType } = await setBotClientToken({
|
|
67
|
+
params: {
|
|
68
|
+
deviceId,
|
|
69
|
+
},
|
|
70
|
+
options: {
|
|
71
|
+
setAccessTokenCookie: true,
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
[user] = users;
|
|
76
|
+
|
|
77
|
+
client.userId = user.userId;
|
|
78
|
+
|
|
79
|
+
client.sessionHandler = params.sessionHandler;
|
|
80
|
+
|
|
81
|
+
/*
|
|
82
|
+
* Cannot push to subscriptions as watcher needs to continue working even if
|
|
83
|
+
* token expires
|
|
84
|
+
*/
|
|
85
|
+
unsubWatcher = client.accessTokenExpiryWatcher(params.sessionHandler);
|
|
86
|
+
|
|
87
|
+
setCurrentUser({ user, userType });
|
|
88
|
+
} catch (error) {
|
|
89
|
+
/*
|
|
90
|
+
* if getting token failed session state reverts to initial state when app
|
|
91
|
+
* is first launched
|
|
92
|
+
*/
|
|
93
|
+
SessionWatcher.getInstance().setSessionState(Amity.SessionStates.NOT_LOGGED_IN);
|
|
94
|
+
|
|
95
|
+
// pass error down tree so the calling function handle it
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
await initializeMessagePreviewSetting();
|
|
100
|
+
|
|
101
|
+
if (subscriptions.length === 0) {
|
|
102
|
+
// handling internal SDK events
|
|
103
|
+
subscriptions.push(
|
|
104
|
+
onTokenTerminated(_ => {
|
|
105
|
+
terminateClient();
|
|
106
|
+
|
|
107
|
+
subscriptions.forEach(fn => fn());
|
|
108
|
+
|
|
109
|
+
unsubWatcher();
|
|
110
|
+
}),
|
|
111
|
+
|
|
112
|
+
onTokenExpired(state => {
|
|
113
|
+
SessionWatcher.getInstance().setSessionState(state);
|
|
114
|
+
|
|
115
|
+
logout();
|
|
116
|
+
|
|
117
|
+
subscriptions.forEach(fn => fn());
|
|
118
|
+
}),
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return true;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/* end_public_function */
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/* eslint-disable no-param-reassign */
|
|
2
|
+
import { modifyMqttConnection } from '~/client/utils/modifyMqttConnection';
|
|
3
|
+
/* eslint-disable require-atomic-updates */
|
|
4
|
+
import { getDeviceId } from '~/core/device';
|
|
5
|
+
import { logout } from './logout';
|
|
6
|
+
|
|
7
|
+
import { getActiveClient } from './activeClient';
|
|
8
|
+
import { terminateClient } from './terminateClient';
|
|
9
|
+
|
|
10
|
+
import { onTokenExpired } from '../events/onTokenExpired';
|
|
11
|
+
import { onTokenTerminated } from '../events/onTokenTerminated';
|
|
12
|
+
import { initializeMessagePreviewSetting } from '../utils/messagePreviewEngine';
|
|
13
|
+
|
|
14
|
+
import SessionWatcher from '../utils/SessionWatcher';
|
|
15
|
+
import { setVisitorClientToken } from '../utils/setVisitorClientToken';
|
|
16
|
+
import { setCurrentUser } from '../utils/setCurrentUser';
|
|
17
|
+
|
|
18
|
+
/*
|
|
19
|
+
* declared earlier to accomodate case when logging in with a different user
|
|
20
|
+
* than the one already connected, in which case the existing subscriptions need
|
|
21
|
+
* to be cleared
|
|
22
|
+
*/
|
|
23
|
+
const subscriptions: Amity.Unsubscriber[] = [];
|
|
24
|
+
|
|
25
|
+
/* begin_public_function
|
|
26
|
+
id: client.loginAsVisitor
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* ```js
|
|
30
|
+
* import { loginAsVisitor } from '@amityco/ts-sdk/client/api'
|
|
31
|
+
* const success = await loginAsVisitor({
|
|
32
|
+
sessionHandler: {
|
|
33
|
+
sessionWillRenewAccessToken(renewal: Amity.AccessTokenRenewal) {
|
|
34
|
+
...
|
|
35
|
+
}
|
|
36
|
+
* })
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* Connects an {@link Amity.Client} instance to ASC servers
|
|
40
|
+
*
|
|
41
|
+
* @param params. the connect parameters
|
|
42
|
+
* @param params.authSignature The authenitcation signature - necessary when network option is set to secure
|
|
43
|
+
* @param params.authSignatureExpiresAt Expire time of the authenitcation signature
|
|
44
|
+
* @param params.sessionHandler
|
|
45
|
+
* @returns a success boolean if connected
|
|
46
|
+
*
|
|
47
|
+
* @category Client API
|
|
48
|
+
* @async
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
export const loginAsVisitor = async (
|
|
52
|
+
params: Amity.ConnectClientAsVisitorParams & {
|
|
53
|
+
sessionHandler: Amity.SessionHandler;
|
|
54
|
+
},
|
|
55
|
+
): Promise<boolean> => {
|
|
56
|
+
const client = getActiveClient();
|
|
57
|
+
let unsubWatcher: Amity.Unsubscriber;
|
|
58
|
+
client.log('client/api/connectClient', {
|
|
59
|
+
apiKey: client.apiKey,
|
|
60
|
+
sessionState: client.sessionState,
|
|
61
|
+
...params,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// generate deviceId
|
|
65
|
+
const deviceId = await getDeviceId();
|
|
66
|
+
let user: Amity.RawUser;
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
const { users, userType } = await setVisitorClientToken({
|
|
70
|
+
params: {
|
|
71
|
+
...params,
|
|
72
|
+
deviceId,
|
|
73
|
+
},
|
|
74
|
+
options: {
|
|
75
|
+
setAccessTokenCookie: true,
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
[user] = users;
|
|
80
|
+
|
|
81
|
+
client.userId = user.userId;
|
|
82
|
+
|
|
83
|
+
client.sessionHandler = params.sessionHandler;
|
|
84
|
+
|
|
85
|
+
/*
|
|
86
|
+
* Cannot push to subscriptions as watcher needs to continue working even if
|
|
87
|
+
* token expires
|
|
88
|
+
*/
|
|
89
|
+
unsubWatcher = client.accessTokenExpiryWatcher(params.sessionHandler);
|
|
90
|
+
|
|
91
|
+
setCurrentUser({ user, userType });
|
|
92
|
+
} catch (error) {
|
|
93
|
+
/*
|
|
94
|
+
* if getting token failed session state reverts to initial state when app
|
|
95
|
+
* is first launched
|
|
96
|
+
*/
|
|
97
|
+
SessionWatcher.getInstance().setSessionState(Amity.SessionStates.NOT_LOGGED_IN);
|
|
98
|
+
|
|
99
|
+
// pass error down tree so the calling function handle it
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
await initializeMessagePreviewSetting();
|
|
104
|
+
|
|
105
|
+
if (subscriptions.length === 0) {
|
|
106
|
+
// handling internal SDK events
|
|
107
|
+
subscriptions.push(
|
|
108
|
+
onTokenTerminated(_ => {
|
|
109
|
+
terminateClient();
|
|
110
|
+
|
|
111
|
+
subscriptions.forEach(fn => fn());
|
|
112
|
+
|
|
113
|
+
unsubWatcher();
|
|
114
|
+
}),
|
|
115
|
+
|
|
116
|
+
onTokenExpired(state => {
|
|
117
|
+
SessionWatcher.getInstance().setSessionState(state);
|
|
118
|
+
|
|
119
|
+
logout();
|
|
120
|
+
|
|
121
|
+
subscriptions.forEach(fn => fn());
|
|
122
|
+
}),
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return true;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
/* end_public_function */
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { getDeviceId } from '~/core/device';
|
|
2
2
|
import { ACCESS_TOKEN_WATCHER_INTERVAL } from '~/utils/constants';
|
|
3
3
|
|
|
4
|
-
import { getActiveUser } from './activeUser';
|
|
5
4
|
import { setClientToken as refreshToken } from '../utils/setClientToken';
|
|
5
|
+
import { setVisitorClientToken as refreshVisitorToken } from '../utils/setVisitorClientToken';
|
|
6
6
|
import { getActiveClient } from './activeClient';
|
|
7
7
|
import { login } from './login';
|
|
8
|
+
import { loginAsVisitor } from './loginAsVisitor';
|
|
9
|
+
import { getCurrentUser } from './getCurrentUser';
|
|
8
10
|
|
|
9
11
|
/* begin_public_function
|
|
10
12
|
id: client.renew_access_token
|
|
@@ -30,7 +32,7 @@ export const renewal = (): Amity.AccessTokenRenewal => {
|
|
|
30
32
|
* Per instance of Renewal, only one renewal is allowed
|
|
31
33
|
*/
|
|
32
34
|
const renewToken = async (authToken?: Amity.ConnectClientParams['authToken']): Promise<void> => {
|
|
33
|
-
const { userId, displayName } =
|
|
35
|
+
const { userId, displayName } = getCurrentUser();
|
|
34
36
|
const deviceId = await getDeviceId();
|
|
35
37
|
|
|
36
38
|
const params = { userId, displayName, authToken, deviceId };
|
|
@@ -53,6 +55,30 @@ export const renewal = (): Amity.AccessTokenRenewal => {
|
|
|
53
55
|
if (renewTimeoutId) clearTimeout(renewTimeoutId);
|
|
54
56
|
};
|
|
55
57
|
|
|
58
|
+
const renewVisitorToken = async ({
|
|
59
|
+
authSignature,
|
|
60
|
+
authSignatureExpiresAt,
|
|
61
|
+
}: Amity.ConnectClientAsVisitorParams): Promise<void> => {
|
|
62
|
+
const deviceId = await getDeviceId();
|
|
63
|
+
|
|
64
|
+
if (client.sessionState === Amity.SessionStates.TOKEN_EXPIRED && client.sessionHandler) {
|
|
65
|
+
await loginAsVisitor({ sessionHandler: client.sessionHandler });
|
|
66
|
+
} else {
|
|
67
|
+
// about to expire
|
|
68
|
+
|
|
69
|
+
await refreshVisitorToken({
|
|
70
|
+
params: { authSignature, authSignatureExpiresAt, deviceId },
|
|
71
|
+
options: {
|
|
72
|
+
setAccessTokenCookie: true,
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
tokenRenewed = true;
|
|
78
|
+
|
|
79
|
+
if (renewTimeoutId) clearTimeout(renewTimeoutId);
|
|
80
|
+
};
|
|
81
|
+
|
|
56
82
|
return {
|
|
57
83
|
renew: () => {
|
|
58
84
|
if (tokenRenewed) {
|
|
@@ -75,6 +101,20 @@ export const renewal = (): Amity.AccessTokenRenewal => {
|
|
|
75
101
|
client.sessionHandler?.sessionWillRenewAccessToken(renewal());
|
|
76
102
|
}, ACCESS_TOKEN_WATCHER_INTERVAL);
|
|
77
103
|
},
|
|
104
|
+
|
|
105
|
+
renewWithAuthSignature: (params: Amity.ConnectClientAsVisitorParams) => {
|
|
106
|
+
if (tokenRenewed) {
|
|
107
|
+
console.log("'renew' method can be called only once per renewal instance");
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
renewVisitorToken(params);
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
unableToRetrieveAuthSignature: () => {
|
|
114
|
+
renewTimeoutId = setTimeout(() => {
|
|
115
|
+
client.sessionHandler?.sessionWillRenewAccessToken(renewal());
|
|
116
|
+
}, ACCESS_TOKEN_WATCHER_INTERVAL);
|
|
117
|
+
},
|
|
78
118
|
};
|
|
79
119
|
};
|
|
80
120
|
/* end_public_function */
|