@amityco/ts-sdk 7.9.2 → 7.9.3-26ea573.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/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/core/errors.d.ts +3 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/core/errors.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/core/errors.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/client.d.ts +10 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/client.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/client.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/user.d.ts +6 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/user.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/user.js +6 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/user.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/index.d.ts +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/index.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/index.js +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/index.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/activeUser.d.ts +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/activeUser.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/activeUser.js +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/activeUser.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/getBotToken.d.ts +21 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/getBotToken.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/getBotToken.js +27 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/getBotToken.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/getCurrentUser.d.ts +2 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/getCurrentUser.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/getCurrentUser.js +21 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/getCurrentUser.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/getCurrentUserType.d.ts +3 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/getCurrentUserType.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/getCurrentUserType.js +16 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/getCurrentUserType.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/getToken.d.ts +1 -3
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/getToken.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/getToken.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/getVisitorToken.d.ts +24 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/getVisitorToken.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/getVisitorToken.js +30 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/getVisitorToken.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/index.d.ts +4 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/index.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/index.js +4 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/index.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/login.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/login.js +4 -4
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/login.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/loginAsBot.d.ts +24 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/loginAsBot.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/loginAsBot.js +95 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/loginAsBot.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/loginAsVisitor.d.ts +26 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/loginAsVisitor.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/loginAsVisitor.js +92 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/loginAsVisitor.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/renewal.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/renewal.js +35 -2
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/renewal.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/utils/setBotClientToken.d.ts +16 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/utils/setBotClientToken.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/utils/setBotClientToken.js +29 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/utils/setBotClientToken.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/utils/setClientToken.d.ts +2 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/utils/setClientToken.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/utils/setClientToken.js +2 -2
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/utils/setClientToken.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/utils/setCurrentUser.d.ts +5 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/utils/setCurrentUser.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/utils/setCurrentUser.js +9 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/utils/setCurrentUser.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/utils/setVisitorClientToken.d.ts +21 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/utils/setVisitorClientToken.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/utils/setVisitorClientToken.js +34 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/utils/setVisitorClientToken.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/core/transports/http.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/core/transports/http.js +4 -4
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/core/transports/http.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/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 +10 -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/client/api/activeUser.d.ts +1 -0
- package/dist/client/api/activeUser.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 +390 -37
- package/dist/index.esm.js +391 -38
- 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 +15 -0
- package/src/@types/domains/user.ts +8 -0
- package/src/@types/index.ts +1 -0
- package/src/client/api/activeUser.ts +1 -0
- 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 +126 -0
- package/src/client/api/loginAsVisitor.ts +131 -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 +41 -0
- package/src/core/transports/http.ts +5 -4
- package/tsconfig.tsbuildinfo +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -14,6 +14,13 @@ var MembershipAcceptanceTypeEnum;
|
|
|
14
14
|
MembershipAcceptanceTypeEnum["INVITATION"] = "invitation";
|
|
15
15
|
})(MembershipAcceptanceTypeEnum || (MembershipAcceptanceTypeEnum = {}));
|
|
16
16
|
|
|
17
|
+
var UserTypeEnum;
|
|
18
|
+
(function (UserTypeEnum) {
|
|
19
|
+
UserTypeEnum["SIGNED_IN"] = "signed-in";
|
|
20
|
+
UserTypeEnum["VISITOR"] = "visitor";
|
|
21
|
+
UserTypeEnum["BOT"] = "bot";
|
|
22
|
+
})(UserTypeEnum || (UserTypeEnum = {}));
|
|
23
|
+
|
|
17
24
|
const FileType = Object.freeze({
|
|
18
25
|
FILE: 'file',
|
|
19
26
|
IMAGE: 'image',
|
|
@@ -1333,6 +1340,7 @@ let activeUser = null;
|
|
|
1333
1340
|
*/
|
|
1334
1341
|
/**
|
|
1335
1342
|
* for internal use
|
|
1343
|
+
* @deprecated please use getCurrentUser api instead.
|
|
1336
1344
|
*/
|
|
1337
1345
|
const getActiveUser = () => {
|
|
1338
1346
|
if (!activeUser) {
|
|
@@ -1766,12 +1774,6 @@ const createHttpTransport = (endpoint) => {
|
|
|
1766
1774
|
controller.abort();
|
|
1767
1775
|
handleRequestCancelation(RequestCancelation.UserDeleted);
|
|
1768
1776
|
}
|
|
1769
|
-
if (tokenExpiry) {
|
|
1770
|
-
if (Date.now() >= Date.parse(tokenExpiry)) {
|
|
1771
|
-
controller.abort(RequestCancelation.UserDeleted);
|
|
1772
|
-
handleRequestCancelation(RequestCancelation.TokenExpired);
|
|
1773
|
-
}
|
|
1774
|
-
}
|
|
1775
1777
|
}
|
|
1776
1778
|
return config;
|
|
1777
1779
|
});
|
|
@@ -23332,7 +23334,7 @@ const setClientToken = async (params) => {
|
|
|
23332
23334
|
const client = getActiveClient();
|
|
23333
23335
|
// begin establishing session
|
|
23334
23336
|
setSessionState("establishing" /* Amity.SessionStates.ESTABLISHING */);
|
|
23335
|
-
const { accessToken, users, expiresAt, issuedAt } = await getToken(params);
|
|
23337
|
+
const { accessToken, users, expiresAt, issuedAt, userType } = await getToken(params);
|
|
23336
23338
|
// manually setup the token for http transport
|
|
23337
23339
|
client.http.defaults.headers.common.Authorization = `Bearer ${accessToken}`;
|
|
23338
23340
|
client.http.defaults.metadata = {
|
|
@@ -23348,7 +23350,66 @@ const setClientToken = async (params) => {
|
|
|
23348
23350
|
};
|
|
23349
23351
|
client.token = { accessToken, issuedAt, expiresAt };
|
|
23350
23352
|
setSessionState("established" /* Amity.SessionStates.ESTABLISHED */);
|
|
23351
|
-
return { accessToken, users };
|
|
23353
|
+
return { accessToken, users, userType };
|
|
23354
|
+
};
|
|
23355
|
+
|
|
23356
|
+
/**
|
|
23357
|
+
* Retrieves a pair of {@link Amity.Tokens} necessary for connection
|
|
23358
|
+
*
|
|
23359
|
+
* @param params get visitor token param
|
|
23360
|
+
* @param params.deviceId The user's device Id (can be manually set for native users)
|
|
23361
|
+
* @param params.authSignature The authenitcation signature - necessary when network option is set to secure
|
|
23362
|
+
* @param params.authSignatureExpiresAt Expire time of the authenitcation signature
|
|
23363
|
+
* @param options get bot token options
|
|
23364
|
+
* @param options.setAccessTokenCookie The authentication token - necessary when network option is set to secure
|
|
23365
|
+
* @return The accessToken for the given userId
|
|
23366
|
+
*
|
|
23367
|
+
*
|
|
23368
|
+
* @category Client API
|
|
23369
|
+
* @hidden
|
|
23370
|
+
*/
|
|
23371
|
+
const getVisitorToken = async ({ params, options, }) => {
|
|
23372
|
+
const client = getActiveClient();
|
|
23373
|
+
client.log('client/api/getVisitorToken', params);
|
|
23374
|
+
const deviceInfo = getDeviceInfo();
|
|
23375
|
+
const { data } = await client.http.post('/api/v5/sessions/visitor', Object.assign(Object.assign({}, params), { deviceInfo }), {
|
|
23376
|
+
headers: {
|
|
23377
|
+
'X-API-Key': client.apiKey,
|
|
23378
|
+
'set-access-token-cookie': (options === null || options === void 0 ? void 0 : options.setAccessTokenCookie) || false,
|
|
23379
|
+
},
|
|
23380
|
+
});
|
|
23381
|
+
return data;
|
|
23382
|
+
};
|
|
23383
|
+
|
|
23384
|
+
/**
|
|
23385
|
+
* A util to set or refresh client token
|
|
23386
|
+
*
|
|
23387
|
+
* @param params.userId the user ID for the current session
|
|
23388
|
+
* @param params.displayName the user's displayName for the current session
|
|
23389
|
+
* @param params.deviceId Manual override of the user's device id (for device management)
|
|
23390
|
+
* @param params.authToken The authentication token - necessary when network option is set to secure
|
|
23391
|
+
* @param options get bot token options
|
|
23392
|
+
* @param options.setAccessTokenCookie The authentication token - necessary when network option is set to secure
|
|
23393
|
+
* @returns token & user info
|
|
23394
|
+
*
|
|
23395
|
+
* @category private
|
|
23396
|
+
* @async
|
|
23397
|
+
*/
|
|
23398
|
+
const setVisitorClientToken = async (params) => {
|
|
23399
|
+
const client = getActiveClient();
|
|
23400
|
+
// begin establishing session
|
|
23401
|
+
setSessionState("establishing" /* Amity.SessionStates.ESTABLISHING */);
|
|
23402
|
+
const { accessToken, users, expiresAt, issuedAt, userType } = await getVisitorToken(params);
|
|
23403
|
+
// manually setup the token for http transport
|
|
23404
|
+
client.http.defaults.headers.common.Authorization = `Bearer ${accessToken}`;
|
|
23405
|
+
client.http.defaults.metadata = {
|
|
23406
|
+
tokenExpiry: expiresAt,
|
|
23407
|
+
isGlobalBanned: false,
|
|
23408
|
+
isUserDeleted: false,
|
|
23409
|
+
};
|
|
23410
|
+
client.token = { accessToken, issuedAt, expiresAt };
|
|
23411
|
+
setSessionState("established" /* Amity.SessionStates.ESTABLISHED */);
|
|
23412
|
+
return { accessToken, users, userType };
|
|
23352
23413
|
};
|
|
23353
23414
|
|
|
23354
23415
|
function prepareUserPayload(response) {
|
|
@@ -24808,13 +24869,34 @@ const removeChannelMarkerCache = (channel) => {
|
|
|
24808
24869
|
dropFromCache(['channelMarker', 'get', id], true);
|
|
24809
24870
|
};
|
|
24810
24871
|
|
|
24872
|
+
let currentUserType = null;
|
|
24873
|
+
/* begin_public_function
|
|
24874
|
+
id: client.get_current_user_type
|
|
24875
|
+
*/
|
|
24876
|
+
const getCurrentUserType = () => {
|
|
24877
|
+
if (!currentUserType) {
|
|
24878
|
+
throw new ASCError('Connect client first', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "fatal" /* Amity.ErrorLevel.FATAL */);
|
|
24879
|
+
}
|
|
24880
|
+
return currentUserType;
|
|
24881
|
+
};
|
|
24882
|
+
/* end_public_function */
|
|
24883
|
+
const setCurrentUserType = (userType) => {
|
|
24884
|
+
currentUserType = userType;
|
|
24885
|
+
};
|
|
24886
|
+
|
|
24887
|
+
const setCurrentUser = ({ user, userType, }) => {
|
|
24888
|
+
setActiveUser(user);
|
|
24889
|
+
setCurrentUserType(userType);
|
|
24890
|
+
pushToCache(['user', 'get', user.userId], user);
|
|
24891
|
+
};
|
|
24892
|
+
|
|
24811
24893
|
/* eslint-disable no-param-reassign */
|
|
24812
24894
|
/*
|
|
24813
24895
|
* declared earlier to accomodate case when logging in with a different user
|
|
24814
24896
|
* than the one already connected, in which case the existing subscriptions need
|
|
24815
24897
|
* to be cleared
|
|
24816
24898
|
*/
|
|
24817
|
-
let subscriptions$
|
|
24899
|
+
let subscriptions$3 = [];
|
|
24818
24900
|
async function runMqtt$1() {
|
|
24819
24901
|
await modifyMqttConnection();
|
|
24820
24902
|
}
|
|
@@ -24849,13 +24931,13 @@ const login = async (params, sessionHandler, config) => {
|
|
|
24849
24931
|
if (client.userId && client.userId !== params.userId) {
|
|
24850
24932
|
await logout();
|
|
24851
24933
|
// Remove subscription to ban and delete
|
|
24852
|
-
subscriptions$
|
|
24853
|
-
subscriptions$
|
|
24934
|
+
subscriptions$3.forEach(fn => fn());
|
|
24935
|
+
subscriptions$3 = [];
|
|
24854
24936
|
}
|
|
24855
24937
|
// default values
|
|
24856
24938
|
const defaultDeviceId = await getDeviceId();
|
|
24857
24939
|
try {
|
|
24858
|
-
const { users } = await setClientToken({
|
|
24940
|
+
const { users, userType } = await setClientToken({
|
|
24859
24941
|
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 }),
|
|
24860
24942
|
options: {
|
|
24861
24943
|
setAccessTokenCookie: true,
|
|
@@ -24869,7 +24951,7 @@ const login = async (params, sessionHandler, config) => {
|
|
|
24869
24951
|
terminateClient("userDeleted" /* Amity.TokenTerminationReason.USER_DELETED */);
|
|
24870
24952
|
return false;
|
|
24871
24953
|
}
|
|
24872
|
-
if (user.
|
|
24954
|
+
if (user.isGlobalBan) {
|
|
24873
24955
|
terminateClient("globalBan" /* Amity.TokenTerminationReason.GLOBAL_BAN */);
|
|
24874
24956
|
return false;
|
|
24875
24957
|
}
|
|
@@ -24880,7 +24962,7 @@ const login = async (params, sessionHandler, config) => {
|
|
|
24880
24962
|
* token expires
|
|
24881
24963
|
*/
|
|
24882
24964
|
unsubWatcher = client.accessTokenExpiryWatcher(sessionHandler);
|
|
24883
|
-
|
|
24965
|
+
setCurrentUser({ user, userType });
|
|
24884
24966
|
}
|
|
24885
24967
|
catch (error) {
|
|
24886
24968
|
/*
|
|
@@ -24895,42 +24977,141 @@ const login = async (params, sessionHandler, config) => {
|
|
|
24895
24977
|
runMqtt$1();
|
|
24896
24978
|
}
|
|
24897
24979
|
await initializeMessagePreviewSetting();
|
|
24898
|
-
if (subscriptions$
|
|
24899
|
-
subscriptions$
|
|
24980
|
+
if (subscriptions$3.length === 0) {
|
|
24981
|
+
subscriptions$3.push(
|
|
24900
24982
|
// GLOBAL_BAN
|
|
24901
24983
|
onClientBanned((_) => {
|
|
24902
24984
|
terminateClient("globalBan" /* Amity.TokenTerminationReason.GLOBAL_BAN */);
|
|
24903
|
-
subscriptions$
|
|
24985
|
+
subscriptions$3.forEach(fn => fn());
|
|
24904
24986
|
unsubWatcher();
|
|
24905
24987
|
}), onTokenTerminated(_ => {
|
|
24906
24988
|
terminateClient();
|
|
24907
|
-
subscriptions$
|
|
24989
|
+
subscriptions$3.forEach(fn => fn());
|
|
24908
24990
|
unsubWatcher();
|
|
24909
24991
|
}), onUserDeleted$2((user) => {
|
|
24910
24992
|
if (user.userId === client.userId) {
|
|
24911
24993
|
terminateClient("userDeleted" /* Amity.TokenTerminationReason.USER_DELETED */);
|
|
24912
|
-
subscriptions$
|
|
24994
|
+
subscriptions$3.forEach(fn => fn());
|
|
24913
24995
|
unsubWatcher();
|
|
24914
24996
|
}
|
|
24915
24997
|
}), onTokenExpired(state => {
|
|
24916
24998
|
SessionWatcher$1.getInstance().setSessionState(state);
|
|
24917
24999
|
logout();
|
|
24918
|
-
subscriptions$
|
|
25000
|
+
subscriptions$3.forEach(fn => fn());
|
|
24919
25001
|
}),
|
|
24920
25002
|
// NOTE: This is a temporary solution to handle the channel marker when the user is forced to leave
|
|
24921
25003
|
// the channel because currently backend can't handle this, so every time a user is banned from
|
|
24922
25004
|
// a channel or the channel is deleted the channel's unread count will not be reset to zero
|
|
24923
25005
|
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler(), reactionSyncEngineOnLoginHandler());
|
|
24924
25006
|
if (client.useLegacyUnreadCount) {
|
|
24925
|
-
subscriptions$
|
|
25007
|
+
subscriptions$3.push(readReceiptSyncEngineOnLoginHandler());
|
|
24926
25008
|
}
|
|
24927
25009
|
else
|
|
24928
|
-
subscriptions$
|
|
25010
|
+
subscriptions$3.push(legacyReadReceiptSyncEngineOnLoginHandler());
|
|
25011
|
+
}
|
|
25012
|
+
return true;
|
|
25013
|
+
};
|
|
25014
|
+
/* end_public_function */
|
|
25015
|
+
|
|
25016
|
+
/* eslint-disable require-atomic-updates */
|
|
25017
|
+
/*
|
|
25018
|
+
* declared earlier to accomodate case when logging in with a different user
|
|
25019
|
+
* than the one already connected, in which case the existing subscriptions need
|
|
25020
|
+
* to be cleared
|
|
25021
|
+
*/
|
|
25022
|
+
const subscriptions$2 = [];
|
|
25023
|
+
/* begin_public_function
|
|
25024
|
+
id: client.loginAsVisitor
|
|
25025
|
+
*/
|
|
25026
|
+
/**
|
|
25027
|
+
* ```js
|
|
25028
|
+
* import { loginAsVisitor } from '@amityco/ts-sdk/client/api'
|
|
25029
|
+
* const success = await loginAsVisitor({
|
|
25030
|
+
sessionHandler: {
|
|
25031
|
+
sessionWillRenewAccessToken(renewal: Amity.AccessTokenRenewal) {
|
|
25032
|
+
...
|
|
25033
|
+
}
|
|
25034
|
+
* })
|
|
25035
|
+
* ```
|
|
25036
|
+
*
|
|
25037
|
+
* Connects an {@link Amity.Client} instance to ASC servers
|
|
25038
|
+
*
|
|
25039
|
+
* @param params. the connect parameters
|
|
25040
|
+
* @param params.authSignature The authenitcation signature - necessary when network option is set to secure
|
|
25041
|
+
* @param params.authSignatureExpiresAt Expire time of the authenitcation signature
|
|
25042
|
+
* @param params.sessionHandler
|
|
25043
|
+
* @returns a success boolean if connected
|
|
25044
|
+
*
|
|
25045
|
+
* @category Client API
|
|
25046
|
+
* @async
|
|
25047
|
+
*/
|
|
25048
|
+
const loginAsVisitor = async (params) => {
|
|
25049
|
+
const client = getActiveClient();
|
|
25050
|
+
let unsubWatcher;
|
|
25051
|
+
client.log('client/api/connectClient', Object.assign({ apiKey: client.apiKey, sessionState: client.sessionState }, params));
|
|
25052
|
+
// generate deviceId
|
|
25053
|
+
const deviceId = await getDeviceId();
|
|
25054
|
+
let user;
|
|
25055
|
+
try {
|
|
25056
|
+
const { users, userType } = await setVisitorClientToken({
|
|
25057
|
+
params: Object.assign(Object.assign({}, params), { deviceId }),
|
|
25058
|
+
options: {
|
|
25059
|
+
setAccessTokenCookie: true,
|
|
25060
|
+
},
|
|
25061
|
+
});
|
|
25062
|
+
[user] = users;
|
|
25063
|
+
client.userId = user.userId;
|
|
25064
|
+
client.sessionHandler = params.sessionHandler;
|
|
25065
|
+
/*
|
|
25066
|
+
* Cannot push to subscriptions as watcher needs to continue working even if
|
|
25067
|
+
* token expires
|
|
25068
|
+
*/
|
|
25069
|
+
unsubWatcher = client.accessTokenExpiryWatcher(params.sessionHandler);
|
|
25070
|
+
setCurrentUser({ user, userType });
|
|
25071
|
+
}
|
|
25072
|
+
catch (error) {
|
|
25073
|
+
/*
|
|
25074
|
+
* if getting token failed session state reverts to initial state when app
|
|
25075
|
+
* is first launched
|
|
25076
|
+
*/
|
|
25077
|
+
SessionWatcher$1.getInstance().setSessionState("notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */);
|
|
25078
|
+
// pass error down tree so the calling function handle it
|
|
25079
|
+
throw error;
|
|
25080
|
+
}
|
|
25081
|
+
await initializeMessagePreviewSetting();
|
|
25082
|
+
if (subscriptions$2.length === 0) {
|
|
25083
|
+
// handling internal SDK events
|
|
25084
|
+
subscriptions$2.push(onTokenTerminated(_ => {
|
|
25085
|
+
terminateClient();
|
|
25086
|
+
subscriptions$2.forEach(fn => fn());
|
|
25087
|
+
unsubWatcher();
|
|
25088
|
+
}), onTokenExpired(state => {
|
|
25089
|
+
SessionWatcher$1.getInstance().setSessionState(state);
|
|
25090
|
+
logout();
|
|
25091
|
+
subscriptions$2.forEach(fn => fn());
|
|
25092
|
+
}));
|
|
24929
25093
|
}
|
|
24930
25094
|
return true;
|
|
24931
25095
|
};
|
|
24932
25096
|
/* end_public_function */
|
|
24933
25097
|
|
|
25098
|
+
/* begin_public_function
|
|
25099
|
+
id: client.get_current_user
|
|
25100
|
+
*/
|
|
25101
|
+
const getCurrentUser = () => {
|
|
25102
|
+
var _a;
|
|
25103
|
+
const client = getActiveClient();
|
|
25104
|
+
if (!client) {
|
|
25105
|
+
throw new ASCError('Connect client first', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "fatal" /* Amity.ErrorLevel.FATAL */);
|
|
25106
|
+
}
|
|
25107
|
+
const cache = (_a = pullFromCache(['user', 'get', client.userId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
25108
|
+
if (!cache) {
|
|
25109
|
+
throw new ASCError('Connect client first', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "fatal" /* Amity.ErrorLevel.FATAL */);
|
|
25110
|
+
}
|
|
25111
|
+
return userLinkedObject(cache);
|
|
25112
|
+
};
|
|
25113
|
+
/* end_public_function */
|
|
25114
|
+
|
|
24934
25115
|
/* begin_public_function
|
|
24935
25116
|
id: client.renew_access_token
|
|
24936
25117
|
*/
|
|
@@ -24953,7 +25134,7 @@ const renewal = () => {
|
|
|
24953
25134
|
* Per instance of Renewal, only one renewal is allowed
|
|
24954
25135
|
*/
|
|
24955
25136
|
const renewToken = async (authToken) => {
|
|
24956
|
-
const { userId, displayName } =
|
|
25137
|
+
const { userId, displayName } = getCurrentUser();
|
|
24957
25138
|
const deviceId = await getDeviceId();
|
|
24958
25139
|
const params = { userId, displayName, authToken, deviceId };
|
|
24959
25140
|
if (client.sessionState === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */ && client.sessionHandler) {
|
|
@@ -24972,6 +25153,24 @@ const renewal = () => {
|
|
|
24972
25153
|
if (renewTimeoutId)
|
|
24973
25154
|
clearTimeout(renewTimeoutId);
|
|
24974
25155
|
};
|
|
25156
|
+
const renewVisitorToken = async ({ authSignature, authSignatureExpiresAt, }) => {
|
|
25157
|
+
const deviceId = await getDeviceId();
|
|
25158
|
+
if (client.sessionState === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */ && client.sessionHandler) {
|
|
25159
|
+
await loginAsVisitor({ sessionHandler: client.sessionHandler });
|
|
25160
|
+
}
|
|
25161
|
+
else {
|
|
25162
|
+
// about to expire
|
|
25163
|
+
await setVisitorClientToken({
|
|
25164
|
+
params: { authSignature, authSignatureExpiresAt, deviceId },
|
|
25165
|
+
options: {
|
|
25166
|
+
setAccessTokenCookie: true,
|
|
25167
|
+
},
|
|
25168
|
+
});
|
|
25169
|
+
}
|
|
25170
|
+
tokenRenewed = true;
|
|
25171
|
+
if (renewTimeoutId)
|
|
25172
|
+
clearTimeout(renewTimeoutId);
|
|
25173
|
+
};
|
|
24975
25174
|
return {
|
|
24976
25175
|
renew: () => {
|
|
24977
25176
|
if (tokenRenewed) {
|
|
@@ -24993,6 +25192,19 @@ const renewal = () => {
|
|
|
24993
25192
|
(_a = client.sessionHandler) === null || _a === void 0 ? void 0 : _a.sessionWillRenewAccessToken(renewal());
|
|
24994
25193
|
}, ACCESS_TOKEN_WATCHER_INTERVAL);
|
|
24995
25194
|
},
|
|
25195
|
+
renewWithAuthSignature: (params) => {
|
|
25196
|
+
if (tokenRenewed) {
|
|
25197
|
+
console.log("'renew' method can be called only once per renewal instance");
|
|
25198
|
+
return;
|
|
25199
|
+
}
|
|
25200
|
+
renewVisitorToken(params);
|
|
25201
|
+
},
|
|
25202
|
+
unableToRetrieveAuthSignature: () => {
|
|
25203
|
+
renewTimeoutId = setTimeout(() => {
|
|
25204
|
+
var _a;
|
|
25205
|
+
(_a = client.sessionHandler) === null || _a === void 0 ? void 0 : _a.sessionWillRenewAccessToken(renewal());
|
|
25206
|
+
}, ACCESS_TOKEN_WATCHER_INTERVAL);
|
|
25207
|
+
},
|
|
24996
25208
|
};
|
|
24997
25209
|
};
|
|
24998
25210
|
/* end_public_function */
|
|
@@ -25594,7 +25806,7 @@ const secureLogout = async () => {
|
|
|
25594
25806
|
* than the one already connected, in which case the existing subscriptions need
|
|
25595
25807
|
* to be cleared
|
|
25596
25808
|
*/
|
|
25597
|
-
let subscriptions = [];
|
|
25809
|
+
let subscriptions$1 = [];
|
|
25598
25810
|
async function runMqtt() {
|
|
25599
25811
|
await modifyMqttConnection();
|
|
25600
25812
|
}
|
|
@@ -25666,15 +25878,15 @@ const resumeSession = async (params, sessionHandler, config) => {
|
|
|
25666
25878
|
client.mqtt.disconnect();
|
|
25667
25879
|
}
|
|
25668
25880
|
// Clear existing subscriptions
|
|
25669
|
-
subscriptions.forEach(fn => fn());
|
|
25670
|
-
subscriptions = [];
|
|
25881
|
+
subscriptions$1.forEach(fn => fn());
|
|
25882
|
+
subscriptions$1 = [];
|
|
25671
25883
|
}
|
|
25672
25884
|
else {
|
|
25673
25885
|
// Different user - do full logout
|
|
25674
25886
|
await logout();
|
|
25675
25887
|
// Remove subscription to ban and delete
|
|
25676
|
-
subscriptions.forEach(fn => fn());
|
|
25677
|
-
subscriptions = [];
|
|
25888
|
+
subscriptions$1.forEach(fn => fn());
|
|
25889
|
+
subscriptions$1 = [];
|
|
25678
25890
|
}
|
|
25679
25891
|
}
|
|
25680
25892
|
try {
|
|
@@ -25712,37 +25924,37 @@ const resumeSession = async (params, sessionHandler, config) => {
|
|
|
25712
25924
|
runMqtt();
|
|
25713
25925
|
}
|
|
25714
25926
|
await initializeMessagePreviewSetting();
|
|
25715
|
-
if (subscriptions.length === 0) {
|
|
25716
|
-
subscriptions.push(
|
|
25927
|
+
if (subscriptions$1.length === 0) {
|
|
25928
|
+
subscriptions$1.push(
|
|
25717
25929
|
// GLOBAL_BAN
|
|
25718
25930
|
onClientBanned((_) => {
|
|
25719
25931
|
terminateClient("globalBan" /* Amity.TokenTerminationReason.GLOBAL_BAN */);
|
|
25720
|
-
subscriptions.forEach(fn => fn());
|
|
25932
|
+
subscriptions$1.forEach(fn => fn());
|
|
25721
25933
|
unsubWatcher();
|
|
25722
25934
|
}), onTokenTerminated(_ => {
|
|
25723
25935
|
terminateClient();
|
|
25724
|
-
subscriptions.forEach(fn => fn());
|
|
25936
|
+
subscriptions$1.forEach(fn => fn());
|
|
25725
25937
|
unsubWatcher();
|
|
25726
25938
|
}), onUserDeleted$2((user) => {
|
|
25727
25939
|
if (user.userId === client.userId) {
|
|
25728
25940
|
terminateClient("userDeleted" /* Amity.TokenTerminationReason.USER_DELETED */);
|
|
25729
|
-
subscriptions.forEach(fn => fn());
|
|
25941
|
+
subscriptions$1.forEach(fn => fn());
|
|
25730
25942
|
unsubWatcher();
|
|
25731
25943
|
}
|
|
25732
25944
|
}), onTokenExpired(state => {
|
|
25733
25945
|
SessionWatcher$1.getInstance().setSessionState(state);
|
|
25734
25946
|
logout();
|
|
25735
|
-
subscriptions.forEach(fn => fn());
|
|
25947
|
+
subscriptions$1.forEach(fn => fn());
|
|
25736
25948
|
}),
|
|
25737
25949
|
// NOTE: This is a temporary solution to handle the channel marker when the user is forced to leave
|
|
25738
25950
|
// the channel because currently backend can't handle this, so every time a user is banned from
|
|
25739
25951
|
// a channel or the channel is deleted the channel's unread count will not be reset to zero
|
|
25740
25952
|
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler());
|
|
25741
25953
|
if (client.useLegacyUnreadCount) {
|
|
25742
|
-
subscriptions.push(readReceiptSyncEngineOnLoginHandler());
|
|
25954
|
+
subscriptions$1.push(readReceiptSyncEngineOnLoginHandler());
|
|
25743
25955
|
}
|
|
25744
25956
|
else
|
|
25745
|
-
subscriptions.push(legacyReadReceiptSyncEngineOnLoginHandler());
|
|
25957
|
+
subscriptions$1.push(legacyReadReceiptSyncEngineOnLoginHandler());
|
|
25746
25958
|
}
|
|
25747
25959
|
return true;
|
|
25748
25960
|
};
|
|
@@ -25840,6 +26052,142 @@ const getShareableLinkConfiguration = async () => {
|
|
|
25840
26052
|
return data;
|
|
25841
26053
|
};
|
|
25842
26054
|
|
|
26055
|
+
/**
|
|
26056
|
+
* Retrieves a pair of {@link Amity.Tokens} necessary for connection
|
|
26057
|
+
*
|
|
26058
|
+
* @param param get bot token param
|
|
26059
|
+
* @param params.deviceId The user's device Id (can be manually set for native users)
|
|
26060
|
+
* @param options get bot token options
|
|
26061
|
+
* @param options.setAccessTokenCookie The authentication token - necessary when network option is set to secure
|
|
26062
|
+
* @return The accessToken for the given userId
|
|
26063
|
+
*
|
|
26064
|
+
* @category Client API
|
|
26065
|
+
* @hidden
|
|
26066
|
+
*/
|
|
26067
|
+
const getBotToken = async ({ params, options, }) => {
|
|
26068
|
+
const client = getActiveClient();
|
|
26069
|
+
client.log('client/api/getBotToken');
|
|
26070
|
+
const deviceInfo = getDeviceInfo();
|
|
26071
|
+
const { data } = await client.http.post('/api/v5/sessions/bot', Object.assign(Object.assign({}, params), { deviceInfo }), {
|
|
26072
|
+
headers: {
|
|
26073
|
+
'X-API-Key': client.apiKey,
|
|
26074
|
+
'set-access-token-cookie': (options === null || options === void 0 ? void 0 : options.setAccessTokenCookie) || false,
|
|
26075
|
+
},
|
|
26076
|
+
});
|
|
26077
|
+
return data;
|
|
26078
|
+
};
|
|
26079
|
+
|
|
26080
|
+
/**
|
|
26081
|
+
* A util to set or refresh client token
|
|
26082
|
+
* @param options get bot token options
|
|
26083
|
+
* @param options.setAccessTokenCookie The authentication token - necessary when network option is set to secure
|
|
26084
|
+
* @returns token & user info
|
|
26085
|
+
*
|
|
26086
|
+
* @category private
|
|
26087
|
+
* @async
|
|
26088
|
+
*/
|
|
26089
|
+
const setBotClientToken = async (params) => {
|
|
26090
|
+
const client = getActiveClient();
|
|
26091
|
+
// begin establishing session
|
|
26092
|
+
setSessionState("establishing" /* Amity.SessionStates.ESTABLISHING */);
|
|
26093
|
+
const { accessToken, users, expiresAt, issuedAt, userType } = await getBotToken(params);
|
|
26094
|
+
// manually setup the token for http transport
|
|
26095
|
+
client.http.defaults.headers.common.Authorization = `Bearer ${accessToken}`;
|
|
26096
|
+
client.http.defaults.metadata = {
|
|
26097
|
+
tokenExpiry: expiresAt,
|
|
26098
|
+
isGlobalBanned: false,
|
|
26099
|
+
isUserDeleted: false,
|
|
26100
|
+
};
|
|
26101
|
+
client.token = { accessToken, issuedAt, expiresAt };
|
|
26102
|
+
setSessionState("established" /* Amity.SessionStates.ESTABLISHED */);
|
|
26103
|
+
return { accessToken, users, userType };
|
|
26104
|
+
};
|
|
26105
|
+
|
|
26106
|
+
/* eslint-disable require-atomic-updates */
|
|
26107
|
+
/*
|
|
26108
|
+
* declared earlier to accomodate case when logging in with a different user
|
|
26109
|
+
* than the one already connected, in which case the existing subscriptions need
|
|
26110
|
+
* to be cleared
|
|
26111
|
+
*/
|
|
26112
|
+
const subscriptions = [];
|
|
26113
|
+
/* begin_public_function
|
|
26114
|
+
id: client.loginAsBot
|
|
26115
|
+
*/
|
|
26116
|
+
/**
|
|
26117
|
+
* ```js
|
|
26118
|
+
* import { loginAsBot } from '@amityco/ts-sdk/client/api'
|
|
26119
|
+
* const success = await loginAsBot({
|
|
26120
|
+
sessionHandler: {
|
|
26121
|
+
sessionWillRenewAccessToken(renewal: Amity.AccessTokenRenewal) {
|
|
26122
|
+
...
|
|
26123
|
+
}
|
|
26124
|
+
* })
|
|
26125
|
+
* ```
|
|
26126
|
+
*
|
|
26127
|
+
* Connects an {@link Amity.Client} instance to ASC servers
|
|
26128
|
+
*
|
|
26129
|
+
* @param params. the connect parameters
|
|
26130
|
+
* @param params.sessionHandler
|
|
26131
|
+
* @returns a success boolean if connected
|
|
26132
|
+
*
|
|
26133
|
+
* @category Client API
|
|
26134
|
+
* @async
|
|
26135
|
+
*/
|
|
26136
|
+
const loginAsBot = async (params) => {
|
|
26137
|
+
const client = getActiveClient();
|
|
26138
|
+
let unsubWatcher;
|
|
26139
|
+
client.log('client/api/connectClient', {
|
|
26140
|
+
apiKey: client.apiKey,
|
|
26141
|
+
sessionState: client.sessionState,
|
|
26142
|
+
});
|
|
26143
|
+
// generate deviceId
|
|
26144
|
+
const deviceId = await getDeviceId();
|
|
26145
|
+
let user;
|
|
26146
|
+
try {
|
|
26147
|
+
const { users, userType } = await setBotClientToken({
|
|
26148
|
+
params: {
|
|
26149
|
+
deviceId,
|
|
26150
|
+
},
|
|
26151
|
+
options: {
|
|
26152
|
+
setAccessTokenCookie: true,
|
|
26153
|
+
},
|
|
26154
|
+
});
|
|
26155
|
+
[user] = users;
|
|
26156
|
+
client.userId = user.userId;
|
|
26157
|
+
client.sessionHandler = params.sessionHandler;
|
|
26158
|
+
/*
|
|
26159
|
+
* Cannot push to subscriptions as watcher needs to continue working even if
|
|
26160
|
+
* token expires
|
|
26161
|
+
*/
|
|
26162
|
+
unsubWatcher = client.accessTokenExpiryWatcher(params.sessionHandler);
|
|
26163
|
+
setCurrentUser({ user, userType });
|
|
26164
|
+
}
|
|
26165
|
+
catch (error) {
|
|
26166
|
+
/*
|
|
26167
|
+
* if getting token failed session state reverts to initial state when app
|
|
26168
|
+
* is first launched
|
|
26169
|
+
*/
|
|
26170
|
+
SessionWatcher$1.getInstance().setSessionState("notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */);
|
|
26171
|
+
// pass error down tree so the calling function handle it
|
|
26172
|
+
throw error;
|
|
26173
|
+
}
|
|
26174
|
+
await initializeMessagePreviewSetting();
|
|
26175
|
+
if (subscriptions.length === 0) {
|
|
26176
|
+
// handling internal SDK events
|
|
26177
|
+
subscriptions.push(onTokenTerminated(_ => {
|
|
26178
|
+
terminateClient();
|
|
26179
|
+
subscriptions.forEach(fn => fn());
|
|
26180
|
+
unsubWatcher();
|
|
26181
|
+
}), onTokenExpired(state => {
|
|
26182
|
+
SessionWatcher$1.getInstance().setSessionState(state);
|
|
26183
|
+
logout();
|
|
26184
|
+
subscriptions.forEach(fn => fn());
|
|
26185
|
+
}));
|
|
26186
|
+
}
|
|
26187
|
+
return true;
|
|
26188
|
+
};
|
|
26189
|
+
/* end_public_function */
|
|
26190
|
+
|
|
25843
26191
|
/**
|
|
25844
26192
|
* ```js
|
|
25845
26193
|
* import { onChannelMarkerFetched } from '@amityco/ts-sdk'
|
|
@@ -26211,6 +26559,11 @@ var index$o = /*#__PURE__*/Object.freeze({
|
|
|
26211
26559
|
fetchLinkPreview: fetchLinkPreview,
|
|
26212
26560
|
getSocialSettings: getSocialSettings,
|
|
26213
26561
|
getShareableLinkConfiguration: getShareableLinkConfiguration,
|
|
26562
|
+
loginAsVisitor: loginAsVisitor,
|
|
26563
|
+
loginAsBot: loginAsBot,
|
|
26564
|
+
getCurrentUser: getCurrentUser,
|
|
26565
|
+
getCurrentUserType: getCurrentUserType,
|
|
26566
|
+
setCurrentUserType: setCurrentUserType,
|
|
26214
26567
|
onConnectionError: onConnectionError,
|
|
26215
26568
|
onClientDisconnected: onClientDisconnected,
|
|
26216
26569
|
onClientBanned: onClientBanned,
|
|
@@ -43554,7 +43907,7 @@ var index$6 = /*#__PURE__*/Object.freeze({
|
|
|
43554
43907
|
getPoll: getPoll
|
|
43555
43908
|
});
|
|
43556
43909
|
|
|
43557
|
-
const privateKey = "-----BEGIN PRIVATE KEY-----\
|
|
43910
|
+
const privateKey = "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDAARz+hmBgi8pJ\nQb8LeY41gtHhk+ACMwRfhsn7GqpqRQNG2qU0755mzZuVDUqjQMGSo8THJB7O+OJs\nflbZRkFXlFoFOVNw1UpNOgwEQZ6wB9oRwzepTJAfF1sVhm/o/ixvXh1zDFNDy6yZ\npXyiiJHUVxqyjllZhxnwdvjoVtDs6hW6awG09bB9nh/TTejlUKXoAgzqVwu/1QMu\nUVViET495elEe19aUarEy+oL2iKeXCEvqda/pWNBdbieFyJvvZ08HN8dPuT88wq2\njZLEAth1vrwQ2IAa4ktaLcBQdLJgIkrbDvAiVZ8lQAjS/bq5vXQikTGvoPlC5bbn\nvuOM/3eLAgMBAAECggEAVZ+peHAghq2QVj71nX5lxsNCKaCyYwixSJBpfouTt7Rz\nE6PpzMOXFi1W1o+I22jDakuSM2SOQKqI/u0QefB0r0O/KVk5NrZHXk0mkrdYtxOp\nUgaGyf8UvmjB+8VqHrNKyZdk9qtmbnNj01kTTcAtmE4H39zPR7eR/8Rul94vaZbs\nwCnKJS3mLT3JxyGug6lxanveKkjG+CKC1nJQYWaxCJxaFSzbwXQPvDhB+TvrIbee\npd5v4EAyEJohpr+T9oDGGJkb/KARBZCtwLyB976PKJwwBA8MRVL1i5QwawuMiMq5\nUtnOnbGKtCeFzaLbNU0Qi8bqyims84EQxC6DOu1fkQKBgQDdvsoBsEhsOXV7hlIJ\naEd0eSJZVkdqimxH8uGoMM2FeNaOrcB6yBXqTSP0R3OIyf8eaY6yjRvP30ZNXcll\n/gD3O1Mu6YmWQdt1W2WA6pKOsUuPXasf0pdOF7IiFZKlSabz5YHXFqwVuqm8loaj\nsXel3YWqPVdHiankE7tz+3ssnQKBgQDdqi4TNdD1MdEpihx19jr0QjUiXW3939FK\nqp30HESPEGDGQzXdmJgif9HhZb+cJSuWaHEbjgBrYahvgCF+y6LbEpOD+D/dmT+s\nDEAQaR84sah6dokwPjV8fjBSrcVFjCS+doxv0d3p/9OUEeyUhFrY03nxtIEYkLIE\n/Zvn37b4RwKBgQCLENVFe9XfsaVhQ5r9dV2iyTlmh7qgMZG5CbTFs12hQGhm8McO\n+Z7s41YSJCFr/yq1WwP4LJDtrBw99vyQr1zRsG35tNLp3gGRNzGQSQyC2uQFVHw2\np+7mNewsfhUK/gbrXNsyFnDz6635rPlhfbII3sWuP2wWXFqkxE9CbMwR7QKBgQC6\nawDMzxmo2/iYArrkyevSuEuPVxvFwpF1RgAI6C0QVCnPE38dmdN4UB7mfHekje4W\nVEercMURidPp0cxZolCYBQtilUjAyL0vqC3In1/Ogjq6oy3FEMxSop1pKxMY5j+Q\nnoqFD+6deLUrddeNH7J3X4LSr4dSbX4JjG+tlgt+yQKBgQCuwTL4hA6KqeInQ0Ta\n9VQX5Qr8hFlqJz1gpymi/k63tW/Ob8yedbg3WWNWyShwRMFYyY9S81ITFWM95uL6\nvF3x9rmRjwElJw9PMwVu6dmf/CO0Z1wzXSp2VVD12gbrUD/0/d7MUoJ9LgC8X8f/\nn0txLHYGHbx+nf95+JUg6lV3hg==\n-----END PRIVATE KEY-----";
|
|
43558
43911
|
/*
|
|
43559
43912
|
* The crypto algorithm used for importing key and signing string
|
|
43560
43913
|
*/
|
|
@@ -45869,4 +46222,4 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
45869
46222
|
getReactions: getReactions
|
|
45870
46223
|
});
|
|
45871
46224
|
|
|
45872
|
-
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 };
|
|
46225
|
+
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 };
|