@amityco/ts-sdk-react-native 7.9.3-172f3f5.0 → 7.10.1-56fea22.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/.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 +393 -39
- package/dist/index.esm.js +394 -40
- 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/dist/index.esm.js
CHANGED
|
@@ -16,6 +16,13 @@ var MembershipAcceptanceTypeEnum;
|
|
|
16
16
|
MembershipAcceptanceTypeEnum["INVITATION"] = "invitation";
|
|
17
17
|
})(MembershipAcceptanceTypeEnum || (MembershipAcceptanceTypeEnum = {}));
|
|
18
18
|
|
|
19
|
+
var UserTypeEnum;
|
|
20
|
+
(function (UserTypeEnum) {
|
|
21
|
+
UserTypeEnum["SIGNED_IN"] = "signed-in";
|
|
22
|
+
UserTypeEnum["VISITOR"] = "visitor";
|
|
23
|
+
UserTypeEnum["BOT"] = "bot";
|
|
24
|
+
})(UserTypeEnum || (UserTypeEnum = {}));
|
|
25
|
+
|
|
19
26
|
const FileType = Object.freeze({
|
|
20
27
|
FILE: 'file',
|
|
21
28
|
IMAGE: 'image',
|
|
@@ -163,8 +170,8 @@ var FeedSourceEnum;
|
|
|
163
170
|
|
|
164
171
|
function getVersion() {
|
|
165
172
|
try {
|
|
166
|
-
// the string ''v7.
|
|
167
|
-
return 'v7.
|
|
173
|
+
// the string ''v7.10.0-esm'' should be replaced by actual value by @rollup/plugin-replace
|
|
174
|
+
return 'v7.10.0-esm';
|
|
168
175
|
}
|
|
169
176
|
catch (error) {
|
|
170
177
|
return '__dev__';
|
|
@@ -1347,6 +1354,7 @@ let activeUser = null;
|
|
|
1347
1354
|
*/
|
|
1348
1355
|
/**
|
|
1349
1356
|
* for internal use
|
|
1357
|
+
* @deprecated please use getCurrentUser api instead.
|
|
1350
1358
|
*/
|
|
1351
1359
|
const getActiveUser = () => {
|
|
1352
1360
|
if (!activeUser) {
|
|
@@ -1780,12 +1788,6 @@ const createHttpTransport = (endpoint) => {
|
|
|
1780
1788
|
controller.abort();
|
|
1781
1789
|
handleRequestCancelation(RequestCancelation.UserDeleted);
|
|
1782
1790
|
}
|
|
1783
|
-
if (tokenExpiry) {
|
|
1784
|
-
if (Date.now() >= Date.parse(tokenExpiry)) {
|
|
1785
|
-
controller.abort(RequestCancelation.UserDeleted);
|
|
1786
|
-
handleRequestCancelation(RequestCancelation.TokenExpired);
|
|
1787
|
-
}
|
|
1788
|
-
}
|
|
1789
1791
|
}
|
|
1790
1792
|
return config;
|
|
1791
1793
|
});
|
|
@@ -23389,7 +23391,7 @@ const setClientToken = async (params) => {
|
|
|
23389
23391
|
const client = getActiveClient();
|
|
23390
23392
|
// begin establishing session
|
|
23391
23393
|
setSessionState("establishing" /* Amity.SessionStates.ESTABLISHING */);
|
|
23392
|
-
const { accessToken, users, expiresAt, issuedAt } = await getToken(params);
|
|
23394
|
+
const { accessToken, users, expiresAt, issuedAt, userType } = await getToken(params);
|
|
23393
23395
|
// manually setup the token for http transport
|
|
23394
23396
|
client.http.defaults.headers.common.Authorization = `Bearer ${accessToken}`;
|
|
23395
23397
|
client.http.defaults.metadata = {
|
|
@@ -23405,7 +23407,66 @@ const setClientToken = async (params) => {
|
|
|
23405
23407
|
};
|
|
23406
23408
|
client.token = { accessToken, issuedAt, expiresAt };
|
|
23407
23409
|
setSessionState("established" /* Amity.SessionStates.ESTABLISHED */);
|
|
23408
|
-
return { accessToken, users };
|
|
23410
|
+
return { accessToken, users, userType };
|
|
23411
|
+
};
|
|
23412
|
+
|
|
23413
|
+
/**
|
|
23414
|
+
* Retrieves a pair of {@link Amity.Tokens} necessary for connection
|
|
23415
|
+
*
|
|
23416
|
+
* @param params get visitor token param
|
|
23417
|
+
* @param params.deviceId The user's device Id (can be manually set for native users)
|
|
23418
|
+
* @param params.authSignature The authenitcation signature - necessary when network option is set to secure
|
|
23419
|
+
* @param params.authSignatureExpiresAt Expire time of the authenitcation signature
|
|
23420
|
+
* @param options get bot token options
|
|
23421
|
+
* @param options.setAccessTokenCookie The authentication token - necessary when network option is set to secure
|
|
23422
|
+
* @return The accessToken for the given userId
|
|
23423
|
+
*
|
|
23424
|
+
*
|
|
23425
|
+
* @category Client API
|
|
23426
|
+
* @hidden
|
|
23427
|
+
*/
|
|
23428
|
+
const getVisitorToken = async ({ params, options, }) => {
|
|
23429
|
+
const client = getActiveClient();
|
|
23430
|
+
client.log('client/api/getVisitorToken', params);
|
|
23431
|
+
const deviceInfo = getDeviceInfo();
|
|
23432
|
+
const { data } = await client.http.post('/api/v5/sessions/visitor', Object.assign(Object.assign({}, params), { deviceInfo }), {
|
|
23433
|
+
headers: {
|
|
23434
|
+
'X-API-Key': client.apiKey,
|
|
23435
|
+
'set-access-token-cookie': (options === null || options === void 0 ? void 0 : options.setAccessTokenCookie) || false,
|
|
23436
|
+
},
|
|
23437
|
+
});
|
|
23438
|
+
return data;
|
|
23439
|
+
};
|
|
23440
|
+
|
|
23441
|
+
/**
|
|
23442
|
+
* A util to set or refresh client token
|
|
23443
|
+
*
|
|
23444
|
+
* @param params.userId the user ID for the current session
|
|
23445
|
+
* @param params.displayName the user's displayName for the current session
|
|
23446
|
+
* @param params.deviceId Manual override of the user's device id (for device management)
|
|
23447
|
+
* @param params.authToken The authentication token - necessary when network option is set to secure
|
|
23448
|
+
* @param options get bot token options
|
|
23449
|
+
* @param options.setAccessTokenCookie The authentication token - necessary when network option is set to secure
|
|
23450
|
+
* @returns token & user info
|
|
23451
|
+
*
|
|
23452
|
+
* @category private
|
|
23453
|
+
* @async
|
|
23454
|
+
*/
|
|
23455
|
+
const setVisitorClientToken = async (params) => {
|
|
23456
|
+
const client = getActiveClient();
|
|
23457
|
+
// begin establishing session
|
|
23458
|
+
setSessionState("establishing" /* Amity.SessionStates.ESTABLISHING */);
|
|
23459
|
+
const { accessToken, users, expiresAt, issuedAt, userType } = await getVisitorToken(params);
|
|
23460
|
+
// manually setup the token for http transport
|
|
23461
|
+
client.http.defaults.headers.common.Authorization = `Bearer ${accessToken}`;
|
|
23462
|
+
client.http.defaults.metadata = {
|
|
23463
|
+
tokenExpiry: expiresAt,
|
|
23464
|
+
isGlobalBanned: false,
|
|
23465
|
+
isUserDeleted: false,
|
|
23466
|
+
};
|
|
23467
|
+
client.token = { accessToken, issuedAt, expiresAt };
|
|
23468
|
+
setSessionState("established" /* Amity.SessionStates.ESTABLISHED */);
|
|
23469
|
+
return { accessToken, users, userType };
|
|
23409
23470
|
};
|
|
23410
23471
|
|
|
23411
23472
|
function prepareUserPayload(response) {
|
|
@@ -24895,13 +24956,34 @@ const removeChannelMarkerCache = (channel) => {
|
|
|
24895
24956
|
dropFromCache(['channelMarker', 'get', id], true);
|
|
24896
24957
|
};
|
|
24897
24958
|
|
|
24959
|
+
let currentUserType = null;
|
|
24960
|
+
/* begin_public_function
|
|
24961
|
+
id: client.get_current_user_type
|
|
24962
|
+
*/
|
|
24963
|
+
const getCurrentUserType = () => {
|
|
24964
|
+
if (!currentUserType) {
|
|
24965
|
+
throw new ASCError('Connect client first', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "fatal" /* Amity.ErrorLevel.FATAL */);
|
|
24966
|
+
}
|
|
24967
|
+
return currentUserType;
|
|
24968
|
+
};
|
|
24969
|
+
/* end_public_function */
|
|
24970
|
+
const setCurrentUserType = (userType) => {
|
|
24971
|
+
currentUserType = userType;
|
|
24972
|
+
};
|
|
24973
|
+
|
|
24974
|
+
const setCurrentUser = ({ user, userType, }) => {
|
|
24975
|
+
setActiveUser(user);
|
|
24976
|
+
setCurrentUserType(userType);
|
|
24977
|
+
pushToCache(['user', 'get', user.userId], user);
|
|
24978
|
+
};
|
|
24979
|
+
|
|
24898
24980
|
/* eslint-disable no-param-reassign */
|
|
24899
24981
|
/*
|
|
24900
24982
|
* declared earlier to accomodate case when logging in with a different user
|
|
24901
24983
|
* than the one already connected, in which case the existing subscriptions need
|
|
24902
24984
|
* to be cleared
|
|
24903
24985
|
*/
|
|
24904
|
-
let subscriptions$
|
|
24986
|
+
let subscriptions$3 = [];
|
|
24905
24987
|
async function runMqtt$1() {
|
|
24906
24988
|
await modifyMqttConnection();
|
|
24907
24989
|
}
|
|
@@ -24936,13 +25018,13 @@ const login = async (params, sessionHandler, config) => {
|
|
|
24936
25018
|
if (client.userId && client.userId !== params.userId) {
|
|
24937
25019
|
await logout();
|
|
24938
25020
|
// Remove subscription to ban and delete
|
|
24939
|
-
subscriptions$
|
|
24940
|
-
subscriptions$
|
|
25021
|
+
subscriptions$3.forEach(fn => fn());
|
|
25022
|
+
subscriptions$3 = [];
|
|
24941
25023
|
}
|
|
24942
25024
|
// default values
|
|
24943
25025
|
const defaultDeviceId = await getDeviceId();
|
|
24944
25026
|
try {
|
|
24945
|
-
const { users } = await setClientToken({
|
|
25027
|
+
const { users, userType } = await setClientToken({
|
|
24946
25028
|
params: Object.assign(Object.assign({}, params), { displayName: params === null || params === void 0 ? void 0 : params.displayName, deviceId: (params === null || params === void 0 ? void 0 : params.deviceId) || defaultDeviceId }),
|
|
24947
25029
|
options: {
|
|
24948
25030
|
setAccessTokenCookie: true,
|
|
@@ -24956,7 +25038,7 @@ const login = async (params, sessionHandler, config) => {
|
|
|
24956
25038
|
terminateClient("userDeleted" /* Amity.TokenTerminationReason.USER_DELETED */);
|
|
24957
25039
|
return false;
|
|
24958
25040
|
}
|
|
24959
|
-
if (user.
|
|
25041
|
+
if (user.isGlobalBan) {
|
|
24960
25042
|
terminateClient("globalBan" /* Amity.TokenTerminationReason.GLOBAL_BAN */);
|
|
24961
25043
|
return false;
|
|
24962
25044
|
}
|
|
@@ -24967,7 +25049,7 @@ const login = async (params, sessionHandler, config) => {
|
|
|
24967
25049
|
* token expires
|
|
24968
25050
|
*/
|
|
24969
25051
|
unsubWatcher = client.accessTokenExpiryWatcher(sessionHandler);
|
|
24970
|
-
|
|
25052
|
+
setCurrentUser({ user, userType });
|
|
24971
25053
|
}
|
|
24972
25054
|
catch (error) {
|
|
24973
25055
|
/*
|
|
@@ -24982,42 +25064,141 @@ const login = async (params, sessionHandler, config) => {
|
|
|
24982
25064
|
runMqtt$1();
|
|
24983
25065
|
}
|
|
24984
25066
|
await initializeMessagePreviewSetting();
|
|
24985
|
-
if (subscriptions$
|
|
24986
|
-
subscriptions$
|
|
25067
|
+
if (subscriptions$3.length === 0) {
|
|
25068
|
+
subscriptions$3.push(
|
|
24987
25069
|
// GLOBAL_BAN
|
|
24988
25070
|
onClientBanned((_) => {
|
|
24989
25071
|
terminateClient("globalBan" /* Amity.TokenTerminationReason.GLOBAL_BAN */);
|
|
24990
|
-
subscriptions$
|
|
25072
|
+
subscriptions$3.forEach(fn => fn());
|
|
24991
25073
|
unsubWatcher();
|
|
24992
25074
|
}), onTokenTerminated(_ => {
|
|
24993
25075
|
terminateClient();
|
|
24994
|
-
subscriptions$
|
|
25076
|
+
subscriptions$3.forEach(fn => fn());
|
|
24995
25077
|
unsubWatcher();
|
|
24996
25078
|
}), onUserDeleted$2((user) => {
|
|
24997
25079
|
if (user.userId === client.userId) {
|
|
24998
25080
|
terminateClient("userDeleted" /* Amity.TokenTerminationReason.USER_DELETED */);
|
|
24999
|
-
subscriptions$
|
|
25081
|
+
subscriptions$3.forEach(fn => fn());
|
|
25000
25082
|
unsubWatcher();
|
|
25001
25083
|
}
|
|
25002
25084
|
}), onTokenExpired(state => {
|
|
25003
25085
|
SessionWatcher$1.getInstance().setSessionState(state);
|
|
25004
25086
|
logout();
|
|
25005
|
-
subscriptions$
|
|
25087
|
+
subscriptions$3.forEach(fn => fn());
|
|
25006
25088
|
}),
|
|
25007
25089
|
// NOTE: This is a temporary solution to handle the channel marker when the user is forced to leave
|
|
25008
25090
|
// the channel because currently backend can't handle this, so every time a user is banned from
|
|
25009
25091
|
// a channel or the channel is deleted the channel's unread count will not be reset to zero
|
|
25010
25092
|
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler(), reactionSyncEngineOnLoginHandler());
|
|
25011
25093
|
if (client.useLegacyUnreadCount) {
|
|
25012
|
-
subscriptions$
|
|
25094
|
+
subscriptions$3.push(readReceiptSyncEngineOnLoginHandler());
|
|
25013
25095
|
}
|
|
25014
25096
|
else
|
|
25015
|
-
subscriptions$
|
|
25097
|
+
subscriptions$3.push(legacyReadReceiptSyncEngineOnLoginHandler());
|
|
25098
|
+
}
|
|
25099
|
+
return true;
|
|
25100
|
+
};
|
|
25101
|
+
/* end_public_function */
|
|
25102
|
+
|
|
25103
|
+
/* eslint-disable require-atomic-updates */
|
|
25104
|
+
/*
|
|
25105
|
+
* declared earlier to accomodate case when logging in with a different user
|
|
25106
|
+
* than the one already connected, in which case the existing subscriptions need
|
|
25107
|
+
* to be cleared
|
|
25108
|
+
*/
|
|
25109
|
+
const subscriptions$2 = [];
|
|
25110
|
+
/* begin_public_function
|
|
25111
|
+
id: client.loginAsVisitor
|
|
25112
|
+
*/
|
|
25113
|
+
/**
|
|
25114
|
+
* ```js
|
|
25115
|
+
* import { loginAsVisitor } from '@amityco/ts-sdk/client/api'
|
|
25116
|
+
* const success = await loginAsVisitor({
|
|
25117
|
+
sessionHandler: {
|
|
25118
|
+
sessionWillRenewAccessToken(renewal: Amity.AccessTokenRenewal) {
|
|
25119
|
+
...
|
|
25120
|
+
}
|
|
25121
|
+
* })
|
|
25122
|
+
* ```
|
|
25123
|
+
*
|
|
25124
|
+
* Connects an {@link Amity.Client} instance to ASC servers
|
|
25125
|
+
*
|
|
25126
|
+
* @param params. the connect parameters
|
|
25127
|
+
* @param params.authSignature The authenitcation signature - necessary when network option is set to secure
|
|
25128
|
+
* @param params.authSignatureExpiresAt Expire time of the authenitcation signature
|
|
25129
|
+
* @param params.sessionHandler
|
|
25130
|
+
* @returns a success boolean if connected
|
|
25131
|
+
*
|
|
25132
|
+
* @category Client API
|
|
25133
|
+
* @async
|
|
25134
|
+
*/
|
|
25135
|
+
const loginAsVisitor = async (params) => {
|
|
25136
|
+
const client = getActiveClient();
|
|
25137
|
+
let unsubWatcher;
|
|
25138
|
+
client.log('client/api/connectClient', Object.assign({ apiKey: client.apiKey, sessionState: client.sessionState }, params));
|
|
25139
|
+
// generate deviceId
|
|
25140
|
+
const deviceId = await getDeviceId();
|
|
25141
|
+
let user;
|
|
25142
|
+
try {
|
|
25143
|
+
const { users, userType } = await setVisitorClientToken({
|
|
25144
|
+
params: Object.assign(Object.assign({}, params), { deviceId }),
|
|
25145
|
+
options: {
|
|
25146
|
+
setAccessTokenCookie: true,
|
|
25147
|
+
},
|
|
25148
|
+
});
|
|
25149
|
+
[user] = users;
|
|
25150
|
+
client.userId = user.userId;
|
|
25151
|
+
client.sessionHandler = params.sessionHandler;
|
|
25152
|
+
/*
|
|
25153
|
+
* Cannot push to subscriptions as watcher needs to continue working even if
|
|
25154
|
+
* token expires
|
|
25155
|
+
*/
|
|
25156
|
+
unsubWatcher = client.accessTokenExpiryWatcher(params.sessionHandler);
|
|
25157
|
+
setCurrentUser({ user, userType });
|
|
25158
|
+
}
|
|
25159
|
+
catch (error) {
|
|
25160
|
+
/*
|
|
25161
|
+
* if getting token failed session state reverts to initial state when app
|
|
25162
|
+
* is first launched
|
|
25163
|
+
*/
|
|
25164
|
+
SessionWatcher$1.getInstance().setSessionState("notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */);
|
|
25165
|
+
// pass error down tree so the calling function handle it
|
|
25166
|
+
throw error;
|
|
25167
|
+
}
|
|
25168
|
+
await initializeMessagePreviewSetting();
|
|
25169
|
+
if (subscriptions$2.length === 0) {
|
|
25170
|
+
// handling internal SDK events
|
|
25171
|
+
subscriptions$2.push(onTokenTerminated(_ => {
|
|
25172
|
+
terminateClient();
|
|
25173
|
+
subscriptions$2.forEach(fn => fn());
|
|
25174
|
+
unsubWatcher();
|
|
25175
|
+
}), onTokenExpired(state => {
|
|
25176
|
+
SessionWatcher$1.getInstance().setSessionState(state);
|
|
25177
|
+
logout();
|
|
25178
|
+
subscriptions$2.forEach(fn => fn());
|
|
25179
|
+
}));
|
|
25016
25180
|
}
|
|
25017
25181
|
return true;
|
|
25018
25182
|
};
|
|
25019
25183
|
/* end_public_function */
|
|
25020
25184
|
|
|
25185
|
+
/* begin_public_function
|
|
25186
|
+
id: client.get_current_user
|
|
25187
|
+
*/
|
|
25188
|
+
const getCurrentUser = () => {
|
|
25189
|
+
var _a;
|
|
25190
|
+
const client = getActiveClient();
|
|
25191
|
+
if (!client) {
|
|
25192
|
+
throw new ASCError('Connect client first', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "fatal" /* Amity.ErrorLevel.FATAL */);
|
|
25193
|
+
}
|
|
25194
|
+
const cache = (_a = pullFromCache(['user', 'get', client.userId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
25195
|
+
if (!cache) {
|
|
25196
|
+
throw new ASCError('Connect client first', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "fatal" /* Amity.ErrorLevel.FATAL */);
|
|
25197
|
+
}
|
|
25198
|
+
return userLinkedObject(cache);
|
|
25199
|
+
};
|
|
25200
|
+
/* end_public_function */
|
|
25201
|
+
|
|
25021
25202
|
/* begin_public_function
|
|
25022
25203
|
id: client.renew_access_token
|
|
25023
25204
|
*/
|
|
@@ -25040,7 +25221,7 @@ const renewal = () => {
|
|
|
25040
25221
|
* Per instance of Renewal, only one renewal is allowed
|
|
25041
25222
|
*/
|
|
25042
25223
|
const renewToken = async (authToken) => {
|
|
25043
|
-
const { userId, displayName } =
|
|
25224
|
+
const { userId, displayName } = getCurrentUser();
|
|
25044
25225
|
const deviceId = await getDeviceId();
|
|
25045
25226
|
const params = { userId, displayName, authToken, deviceId };
|
|
25046
25227
|
if (client.sessionState === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */ && client.sessionHandler) {
|
|
@@ -25059,6 +25240,24 @@ const renewal = () => {
|
|
|
25059
25240
|
if (renewTimeoutId)
|
|
25060
25241
|
clearTimeout(renewTimeoutId);
|
|
25061
25242
|
};
|
|
25243
|
+
const renewVisitorToken = async ({ authSignature, authSignatureExpiresAt, }) => {
|
|
25244
|
+
const deviceId = await getDeviceId();
|
|
25245
|
+
if (client.sessionState === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */ && client.sessionHandler) {
|
|
25246
|
+
await loginAsVisitor({ sessionHandler: client.sessionHandler });
|
|
25247
|
+
}
|
|
25248
|
+
else {
|
|
25249
|
+
// about to expire
|
|
25250
|
+
await setVisitorClientToken({
|
|
25251
|
+
params: { authSignature, authSignatureExpiresAt, deviceId },
|
|
25252
|
+
options: {
|
|
25253
|
+
setAccessTokenCookie: true,
|
|
25254
|
+
},
|
|
25255
|
+
});
|
|
25256
|
+
}
|
|
25257
|
+
tokenRenewed = true;
|
|
25258
|
+
if (renewTimeoutId)
|
|
25259
|
+
clearTimeout(renewTimeoutId);
|
|
25260
|
+
};
|
|
25062
25261
|
return {
|
|
25063
25262
|
renew: () => {
|
|
25064
25263
|
if (tokenRenewed) {
|
|
@@ -25080,6 +25279,19 @@ const renewal = () => {
|
|
|
25080
25279
|
(_a = client.sessionHandler) === null || _a === void 0 ? void 0 : _a.sessionWillRenewAccessToken(renewal());
|
|
25081
25280
|
}, ACCESS_TOKEN_WATCHER_INTERVAL);
|
|
25082
25281
|
},
|
|
25282
|
+
renewWithAuthSignature: (params) => {
|
|
25283
|
+
if (tokenRenewed) {
|
|
25284
|
+
console.log("'renew' method can be called only once per renewal instance");
|
|
25285
|
+
return;
|
|
25286
|
+
}
|
|
25287
|
+
renewVisitorToken(params);
|
|
25288
|
+
},
|
|
25289
|
+
unableToRetrieveAuthSignature: () => {
|
|
25290
|
+
renewTimeoutId = setTimeout(() => {
|
|
25291
|
+
var _a;
|
|
25292
|
+
(_a = client.sessionHandler) === null || _a === void 0 ? void 0 : _a.sessionWillRenewAccessToken(renewal());
|
|
25293
|
+
}, ACCESS_TOKEN_WATCHER_INTERVAL);
|
|
25294
|
+
},
|
|
25083
25295
|
};
|
|
25084
25296
|
};
|
|
25085
25297
|
/* end_public_function */
|
|
@@ -25646,6 +25858,7 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
|
|
|
25646
25858
|
validateTexts,
|
|
25647
25859
|
getFeedSettings,
|
|
25648
25860
|
getSocialSettings,
|
|
25861
|
+
getVisitorDeviceId: getDeviceId,
|
|
25649
25862
|
getMessagePreviewSetting,
|
|
25650
25863
|
onRTEConnectionStateChange,
|
|
25651
25864
|
use: () => setActiveClient(client),
|
|
@@ -25702,7 +25915,7 @@ const secureLogout = async () => {
|
|
|
25702
25915
|
* than the one already connected, in which case the existing subscriptions need
|
|
25703
25916
|
* to be cleared
|
|
25704
25917
|
*/
|
|
25705
|
-
let subscriptions = [];
|
|
25918
|
+
let subscriptions$1 = [];
|
|
25706
25919
|
async function runMqtt() {
|
|
25707
25920
|
await modifyMqttConnection();
|
|
25708
25921
|
}
|
|
@@ -25774,15 +25987,15 @@ const resumeSession = async (params, sessionHandler, config) => {
|
|
|
25774
25987
|
client.mqtt.disconnect();
|
|
25775
25988
|
}
|
|
25776
25989
|
// Clear existing subscriptions
|
|
25777
|
-
subscriptions.forEach(fn => fn());
|
|
25778
|
-
subscriptions = [];
|
|
25990
|
+
subscriptions$1.forEach(fn => fn());
|
|
25991
|
+
subscriptions$1 = [];
|
|
25779
25992
|
}
|
|
25780
25993
|
else {
|
|
25781
25994
|
// Different user - do full logout
|
|
25782
25995
|
await logout();
|
|
25783
25996
|
// Remove subscription to ban and delete
|
|
25784
|
-
subscriptions.forEach(fn => fn());
|
|
25785
|
-
subscriptions = [];
|
|
25997
|
+
subscriptions$1.forEach(fn => fn());
|
|
25998
|
+
subscriptions$1 = [];
|
|
25786
25999
|
}
|
|
25787
26000
|
}
|
|
25788
26001
|
try {
|
|
@@ -25820,37 +26033,37 @@ const resumeSession = async (params, sessionHandler, config) => {
|
|
|
25820
26033
|
runMqtt();
|
|
25821
26034
|
}
|
|
25822
26035
|
await initializeMessagePreviewSetting();
|
|
25823
|
-
if (subscriptions.length === 0) {
|
|
25824
|
-
subscriptions.push(
|
|
26036
|
+
if (subscriptions$1.length === 0) {
|
|
26037
|
+
subscriptions$1.push(
|
|
25825
26038
|
// GLOBAL_BAN
|
|
25826
26039
|
onClientBanned((_) => {
|
|
25827
26040
|
terminateClient("globalBan" /* Amity.TokenTerminationReason.GLOBAL_BAN */);
|
|
25828
|
-
subscriptions.forEach(fn => fn());
|
|
26041
|
+
subscriptions$1.forEach(fn => fn());
|
|
25829
26042
|
unsubWatcher();
|
|
25830
26043
|
}), onTokenTerminated(_ => {
|
|
25831
26044
|
terminateClient();
|
|
25832
|
-
subscriptions.forEach(fn => fn());
|
|
26045
|
+
subscriptions$1.forEach(fn => fn());
|
|
25833
26046
|
unsubWatcher();
|
|
25834
26047
|
}), onUserDeleted$2((user) => {
|
|
25835
26048
|
if (user.userId === client.userId) {
|
|
25836
26049
|
terminateClient("userDeleted" /* Amity.TokenTerminationReason.USER_DELETED */);
|
|
25837
|
-
subscriptions.forEach(fn => fn());
|
|
26050
|
+
subscriptions$1.forEach(fn => fn());
|
|
25838
26051
|
unsubWatcher();
|
|
25839
26052
|
}
|
|
25840
26053
|
}), onTokenExpired(state => {
|
|
25841
26054
|
SessionWatcher$1.getInstance().setSessionState(state);
|
|
25842
26055
|
logout();
|
|
25843
|
-
subscriptions.forEach(fn => fn());
|
|
26056
|
+
subscriptions$1.forEach(fn => fn());
|
|
25844
26057
|
}),
|
|
25845
26058
|
// NOTE: This is a temporary solution to handle the channel marker when the user is forced to leave
|
|
25846
26059
|
// the channel because currently backend can't handle this, so every time a user is banned from
|
|
25847
26060
|
// a channel or the channel is deleted the channel's unread count will not be reset to zero
|
|
25848
26061
|
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler());
|
|
25849
26062
|
if (client.useLegacyUnreadCount) {
|
|
25850
|
-
subscriptions.push(readReceiptSyncEngineOnLoginHandler());
|
|
26063
|
+
subscriptions$1.push(readReceiptSyncEngineOnLoginHandler());
|
|
25851
26064
|
}
|
|
25852
26065
|
else
|
|
25853
|
-
subscriptions.push(legacyReadReceiptSyncEngineOnLoginHandler());
|
|
26066
|
+
subscriptions$1.push(legacyReadReceiptSyncEngineOnLoginHandler());
|
|
25854
26067
|
}
|
|
25855
26068
|
return true;
|
|
25856
26069
|
};
|
|
@@ -25985,6 +26198,142 @@ const getShareableLinkConfiguration = async () => {
|
|
|
25985
26198
|
return data;
|
|
25986
26199
|
};
|
|
25987
26200
|
|
|
26201
|
+
/**
|
|
26202
|
+
* Retrieves a pair of {@link Amity.Tokens} necessary for connection
|
|
26203
|
+
*
|
|
26204
|
+
* @param param get bot token param
|
|
26205
|
+
* @param params.deviceId The user's device Id (can be manually set for native users)
|
|
26206
|
+
* @param options get bot token options
|
|
26207
|
+
* @param options.setAccessTokenCookie The authentication token - necessary when network option is set to secure
|
|
26208
|
+
* @return The accessToken for the given userId
|
|
26209
|
+
*
|
|
26210
|
+
* @category Client API
|
|
26211
|
+
* @hidden
|
|
26212
|
+
*/
|
|
26213
|
+
const getBotToken = async ({ params, options, }) => {
|
|
26214
|
+
const client = getActiveClient();
|
|
26215
|
+
client.log('client/api/getBotToken');
|
|
26216
|
+
const deviceInfo = getDeviceInfo();
|
|
26217
|
+
const { data } = await client.http.post('/api/v5/sessions/bot', Object.assign(Object.assign({}, params), { deviceInfo }), {
|
|
26218
|
+
headers: {
|
|
26219
|
+
'X-API-Key': client.apiKey,
|
|
26220
|
+
'set-access-token-cookie': (options === null || options === void 0 ? void 0 : options.setAccessTokenCookie) || false,
|
|
26221
|
+
},
|
|
26222
|
+
});
|
|
26223
|
+
return data;
|
|
26224
|
+
};
|
|
26225
|
+
|
|
26226
|
+
/**
|
|
26227
|
+
* A util to set or refresh client token
|
|
26228
|
+
* @param options get bot token options
|
|
26229
|
+
* @param options.setAccessTokenCookie The authentication token - necessary when network option is set to secure
|
|
26230
|
+
* @returns token & user info
|
|
26231
|
+
*
|
|
26232
|
+
* @category private
|
|
26233
|
+
* @async
|
|
26234
|
+
*/
|
|
26235
|
+
const setBotClientToken = async (params) => {
|
|
26236
|
+
const client = getActiveClient();
|
|
26237
|
+
// begin establishing session
|
|
26238
|
+
setSessionState("establishing" /* Amity.SessionStates.ESTABLISHING */);
|
|
26239
|
+
const { accessToken, users, expiresAt, issuedAt, userType } = await getBotToken(params);
|
|
26240
|
+
// manually setup the token for http transport
|
|
26241
|
+
client.http.defaults.headers.common.Authorization = `Bearer ${accessToken}`;
|
|
26242
|
+
client.http.defaults.metadata = {
|
|
26243
|
+
tokenExpiry: expiresAt,
|
|
26244
|
+
isGlobalBanned: false,
|
|
26245
|
+
isUserDeleted: false,
|
|
26246
|
+
};
|
|
26247
|
+
client.token = { accessToken, issuedAt, expiresAt };
|
|
26248
|
+
setSessionState("established" /* Amity.SessionStates.ESTABLISHED */);
|
|
26249
|
+
return { accessToken, users, userType };
|
|
26250
|
+
};
|
|
26251
|
+
|
|
26252
|
+
/* eslint-disable require-atomic-updates */
|
|
26253
|
+
/*
|
|
26254
|
+
* declared earlier to accomodate case when logging in with a different user
|
|
26255
|
+
* than the one already connected, in which case the existing subscriptions need
|
|
26256
|
+
* to be cleared
|
|
26257
|
+
*/
|
|
26258
|
+
const subscriptions = [];
|
|
26259
|
+
/* begin_public_function
|
|
26260
|
+
id: client.loginAsBot
|
|
26261
|
+
*/
|
|
26262
|
+
/**
|
|
26263
|
+
* ```js
|
|
26264
|
+
* import { loginAsBot } from '@amityco/ts-sdk/client/api'
|
|
26265
|
+
* const success = await loginAsBot({
|
|
26266
|
+
sessionHandler: {
|
|
26267
|
+
sessionWillRenewAccessToken(renewal: Amity.AccessTokenRenewal) {
|
|
26268
|
+
...
|
|
26269
|
+
}
|
|
26270
|
+
* })
|
|
26271
|
+
* ```
|
|
26272
|
+
*
|
|
26273
|
+
* Connects an {@link Amity.Client} instance to ASC servers
|
|
26274
|
+
*
|
|
26275
|
+
* @param params. the connect parameters
|
|
26276
|
+
* @param params.sessionHandler
|
|
26277
|
+
* @returns a success boolean if connected
|
|
26278
|
+
*
|
|
26279
|
+
* @category Client API
|
|
26280
|
+
* @async
|
|
26281
|
+
*/
|
|
26282
|
+
const loginAsBot = async (params) => {
|
|
26283
|
+
const client = getActiveClient();
|
|
26284
|
+
let unsubWatcher;
|
|
26285
|
+
client.log('client/api/connectClient', {
|
|
26286
|
+
apiKey: client.apiKey,
|
|
26287
|
+
sessionState: client.sessionState,
|
|
26288
|
+
});
|
|
26289
|
+
// generate deviceId
|
|
26290
|
+
const deviceId = await getDeviceId();
|
|
26291
|
+
let user;
|
|
26292
|
+
try {
|
|
26293
|
+
const { users, userType } = await setBotClientToken({
|
|
26294
|
+
params: {
|
|
26295
|
+
deviceId,
|
|
26296
|
+
},
|
|
26297
|
+
options: {
|
|
26298
|
+
setAccessTokenCookie: true,
|
|
26299
|
+
},
|
|
26300
|
+
});
|
|
26301
|
+
[user] = users;
|
|
26302
|
+
client.userId = user.userId;
|
|
26303
|
+
client.sessionHandler = params.sessionHandler;
|
|
26304
|
+
/*
|
|
26305
|
+
* Cannot push to subscriptions as watcher needs to continue working even if
|
|
26306
|
+
* token expires
|
|
26307
|
+
*/
|
|
26308
|
+
unsubWatcher = client.accessTokenExpiryWatcher(params.sessionHandler);
|
|
26309
|
+
setCurrentUser({ user, userType });
|
|
26310
|
+
}
|
|
26311
|
+
catch (error) {
|
|
26312
|
+
/*
|
|
26313
|
+
* if getting token failed session state reverts to initial state when app
|
|
26314
|
+
* is first launched
|
|
26315
|
+
*/
|
|
26316
|
+
SessionWatcher$1.getInstance().setSessionState("notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */);
|
|
26317
|
+
// pass error down tree so the calling function handle it
|
|
26318
|
+
throw error;
|
|
26319
|
+
}
|
|
26320
|
+
await initializeMessagePreviewSetting();
|
|
26321
|
+
if (subscriptions.length === 0) {
|
|
26322
|
+
// handling internal SDK events
|
|
26323
|
+
subscriptions.push(onTokenTerminated(_ => {
|
|
26324
|
+
terminateClient();
|
|
26325
|
+
subscriptions.forEach(fn => fn());
|
|
26326
|
+
unsubWatcher();
|
|
26327
|
+
}), onTokenExpired(state => {
|
|
26328
|
+
SessionWatcher$1.getInstance().setSessionState(state);
|
|
26329
|
+
logout();
|
|
26330
|
+
subscriptions.forEach(fn => fn());
|
|
26331
|
+
}));
|
|
26332
|
+
}
|
|
26333
|
+
return true;
|
|
26334
|
+
};
|
|
26335
|
+
/* end_public_function */
|
|
26336
|
+
|
|
25988
26337
|
/**
|
|
25989
26338
|
* ```js
|
|
25990
26339
|
* import { onChannelMarkerFetched } from '@amityco/ts-sdk-react-native'
|
|
@@ -26359,6 +26708,11 @@ var index$o = /*#__PURE__*/Object.freeze({
|
|
|
26359
26708
|
fetchLinkPreview: fetchLinkPreview,
|
|
26360
26709
|
getSocialSettings: getSocialSettings,
|
|
26361
26710
|
getShareableLinkConfiguration: getShareableLinkConfiguration,
|
|
26711
|
+
loginAsVisitor: loginAsVisitor,
|
|
26712
|
+
loginAsBot: loginAsBot,
|
|
26713
|
+
getCurrentUser: getCurrentUser,
|
|
26714
|
+
getCurrentUserType: getCurrentUserType,
|
|
26715
|
+
setCurrentUserType: setCurrentUserType,
|
|
26362
26716
|
onConnectionError: onConnectionError,
|
|
26363
26717
|
onClientDisconnected: onClientDisconnected,
|
|
26364
26718
|
onClientBanned: onClientBanned,
|
|
@@ -39253,7 +39607,7 @@ const getCategory = async (categoryId) => {
|
|
|
39253
39607
|
ingestInCache(data, { cachedAt });
|
|
39254
39608
|
const { categories } = data;
|
|
39255
39609
|
return {
|
|
39256
|
-
data: LinkedObject.category(categories.find(category => category.categoryId === categoryId)),
|
|
39610
|
+
data: LinkedObject.category((categories !== null && categories !== void 0 ? categories : []).find(category => category.categoryId === categoryId)),
|
|
39257
39611
|
cachedAt,
|
|
39258
39612
|
};
|
|
39259
39613
|
};
|
|
@@ -46009,4 +46363,4 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
46009
46363
|
getReactions: getReactions
|
|
46010
46364
|
});
|
|
46011
46365
|
|
|
46012
|
-
export { API_REGIONS, index$3 as AdRepository, index$b as CategoryRepository, index$f as ChannelRepository, index$o as Client, index$a as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$c as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, DefaultCommunityPostSetting, FeedDataTypeEnum, index$9 as FeedRepository, FeedSortByEnum, FeedSourceEnum, FileAccessTypeEnum, index$l as FileRepository, FileType, GET_WATCHER_URLS, index$1 as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTypeEnum, JoinRequestStatusEnum, JoinResultStatusEnum, index as LiveReactionRepository, index$5 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$j as MessageRepository, index$6 as PollRepository, PostContentType, index$8 as PostRepository, index$k as ReactionRepository, index$4 as StoryRepository, index$7 as StreamRepository, index$i as SubChannelRepository, SubscriptionLevels, index$m as UserRepository, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveReactionTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index$2 as notificationTray, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };
|
|
46366
|
+
export { API_REGIONS, index$3 as AdRepository, index$b as CategoryRepository, index$f as ChannelRepository, index$o as Client, index$a as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$c as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, DefaultCommunityPostSetting, FeedDataTypeEnum, index$9 as FeedRepository, FeedSortByEnum, FeedSourceEnum, FileAccessTypeEnum, index$l as FileRepository, FileType, GET_WATCHER_URLS, index$1 as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTypeEnum, JoinRequestStatusEnum, JoinResultStatusEnum, index as LiveReactionRepository, index$5 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$j as MessageRepository, index$6 as PollRepository, PostContentType, index$8 as PostRepository, index$k as ReactionRepository, index$4 as StoryRepository, index$7 as StreamRepository, index$i as SubChannelRepository, SubscriptionLevels, index$m as UserRepository, UserTypeEnum, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveReactionTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index$2 as notificationTray, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };
|