@amityco/ts-sdk-react-native 7.9.3-172f3f5.0 → 7.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env +26 -26
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/core/errors.d.ts +3 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/core/errors.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/core/errors.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/domains/client.d.ts +11 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/domains/client.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/domains/client.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/domains/user.d.ts +6 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/domains/user.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/domains/user.js +6 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/domains/user.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/index.d.ts +1 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/index.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/index.js +1 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/@types/index.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/categoryRepository/api/getCategory.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/categoryRepository/api/getCategory.js +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/categoryRepository/api/getCategory.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/activeUser.d.ts +1 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/activeUser.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/activeUser.js +1 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/activeUser.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/createClient.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/createClient.js +3 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/createClient.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/getBotToken.d.ts +21 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/getBotToken.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/getBotToken.js +27 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/getBotToken.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/getCurrentUser.d.ts +2 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/getCurrentUser.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/getCurrentUser.js +21 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/getCurrentUser.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/getCurrentUserType.d.ts +3 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/getCurrentUserType.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/getCurrentUserType.js +16 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/getCurrentUserType.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/getToken.d.ts +1 -3
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/getToken.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/getToken.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/getVisitorToken.d.ts +24 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/getVisitorToken.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/getVisitorToken.js +30 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/getVisitorToken.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/index.d.ts +4 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/index.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/index.js +4 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/index.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/login.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/login.js +4 -4
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/login.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/loginAsBot.d.ts +24 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/loginAsBot.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/loginAsBot.js +95 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/loginAsBot.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/loginAsVisitor.d.ts +26 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/loginAsVisitor.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/loginAsVisitor.js +92 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/loginAsVisitor.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/renewal.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/renewal.js +35 -2
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/api/renewal.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/utils/setBotClientToken.d.ts +16 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/utils/setBotClientToken.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/utils/setBotClientToken.js +29 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/utils/setBotClientToken.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/utils/setClientToken.d.ts +2 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/utils/setClientToken.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/utils/setClientToken.js +2 -2
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/utils/setClientToken.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/utils/setCurrentUser.d.ts +5 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/utils/setCurrentUser.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/utils/setCurrentUser.js +9 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/utils/setCurrentUser.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/utils/setVisitorClientToken.d.ts +21 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/utils/setVisitorClientToken.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/utils/setVisitorClientToken.js +34 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/client/utils/setVisitorClientToken.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/core/transports/http.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/core/transports/http.js +4 -4
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/dist/core/transports/http.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityReactNativeTypescriptSDK/AmityReactNativeTypescriptSDK/packages/sdk/tsconfig.tsbuildinfo +1 -1
- package/dist/@types/core/errors.d.ts +3 -1
- package/dist/@types/core/errors.d.ts.map +1 -1
- package/dist/@types/domains/client.d.ts +11 -0
- package/dist/@types/domains/client.d.ts.map +1 -1
- package/dist/@types/domains/user.d.ts +6 -0
- package/dist/@types/domains/user.d.ts.map +1 -1
- package/dist/@types/index.d.ts +1 -0
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/categoryRepository/api/getCategory.d.ts.map +1 -1
- package/dist/client/api/activeUser.d.ts +1 -0
- package/dist/client/api/activeUser.d.ts.map +1 -1
- package/dist/client/api/createClient.d.ts.map +1 -1
- package/dist/client/api/getBotToken.d.ts +21 -0
- package/dist/client/api/getBotToken.d.ts.map +1 -0
- package/dist/client/api/getCurrentUser.d.ts +2 -0
- package/dist/client/api/getCurrentUser.d.ts.map +1 -0
- package/dist/client/api/getCurrentUserType.d.ts +3 -0
- package/dist/client/api/getCurrentUserType.d.ts.map +1 -0
- package/dist/client/api/getToken.d.ts +1 -3
- package/dist/client/api/getToken.d.ts.map +1 -1
- package/dist/client/api/getVisitorToken.d.ts +24 -0
- package/dist/client/api/getVisitorToken.d.ts.map +1 -0
- package/dist/client/api/index.d.ts +4 -0
- package/dist/client/api/index.d.ts.map +1 -1
- package/dist/client/api/login.d.ts.map +1 -1
- package/dist/client/api/loginAsBot.d.ts +24 -0
- package/dist/client/api/loginAsBot.d.ts.map +1 -0
- package/dist/client/api/loginAsVisitor.d.ts +26 -0
- package/dist/client/api/loginAsVisitor.d.ts.map +1 -0
- package/dist/client/api/renewal.d.ts.map +1 -1
- package/dist/client/utils/setBotClientToken.d.ts +16 -0
- package/dist/client/utils/setBotClientToken.d.ts.map +1 -0
- package/dist/client/utils/setClientToken.d.ts +2 -1
- package/dist/client/utils/setClientToken.d.ts.map +1 -1
- package/dist/client/utils/setCurrentUser.d.ts +5 -0
- package/dist/client/utils/setCurrentUser.d.ts.map +1 -0
- package/dist/client/utils/setVisitorClientToken.d.ts +21 -0
- package/dist/client/utils/setVisitorClientToken.d.ts.map +1 -0
- package/dist/core/transports/http.d.ts.map +1 -1
- package/dist/index.cjs.js +394 -40
- package/dist/index.esm.js +395 -41
- package/dist/index.umd.js +3 -3
- package/package.json +1 -1
- package/src/@types/core/errors.ts +2 -0
- package/src/@types/domains/client.ts +17 -0
- package/src/@types/domains/user.ts +8 -0
- package/src/@types/index.ts +1 -0
- package/src/categoryRepository/api/getCategory.ts +3 -1
- package/src/client/api/activeUser.ts +1 -0
- package/src/client/api/createClient.ts +3 -5
- package/src/client/api/getBotToken.ts +44 -0
- package/src/client/api/getCurrentUser.ts +32 -0
- package/src/client/api/getCurrentUserType.ts +23 -0
- package/src/client/api/getToken.ts +1 -1
- package/src/client/api/getVisitorToken.ts +47 -0
- package/src/client/api/index.ts +6 -0
- package/src/client/api/login.ts +5 -4
- package/src/client/api/loginAsBot.ts +125 -0
- package/src/client/api/loginAsVisitor.ts +129 -0
- package/src/client/api/renewal.ts +42 -2
- package/src/client/utils/setBotClientToken.ts +35 -0
- package/src/client/utils/setClientToken.ts +2 -2
- package/src/client/utils/setCurrentUser.ts +15 -0
- package/src/client/utils/setVisitorClientToken.ts +40 -0
- package/src/core/transports/http.ts +5 -4
- package/tsconfig.tsbuildinfo +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -50,6 +50,13 @@ exports.MembershipAcceptanceTypeEnum = void 0;
|
|
|
50
50
|
MembershipAcceptanceTypeEnum["INVITATION"] = "invitation";
|
|
51
51
|
})(exports.MembershipAcceptanceTypeEnum || (exports.MembershipAcceptanceTypeEnum = {}));
|
|
52
52
|
|
|
53
|
+
exports.UserTypeEnum = void 0;
|
|
54
|
+
(function (UserTypeEnum) {
|
|
55
|
+
UserTypeEnum["SIGNED_IN"] = "signed-in";
|
|
56
|
+
UserTypeEnum["VISITOR"] = "visitor";
|
|
57
|
+
UserTypeEnum["BOT"] = "bot";
|
|
58
|
+
})(exports.UserTypeEnum || (exports.UserTypeEnum = {}));
|
|
59
|
+
|
|
53
60
|
const FileType = Object.freeze({
|
|
54
61
|
FILE: 'file',
|
|
55
62
|
IMAGE: 'image',
|
|
@@ -197,8 +204,8 @@ exports.FeedSourceEnum = void 0;
|
|
|
197
204
|
|
|
198
205
|
function getVersion() {
|
|
199
206
|
try {
|
|
200
|
-
// the string ''v7.
|
|
201
|
-
return 'v7.
|
|
207
|
+
// the string ''v7.10.0-cjs'' should be replaced by actual value by @rollup/plugin-replace
|
|
208
|
+
return 'v7.10.0-cjs';
|
|
202
209
|
}
|
|
203
210
|
catch (error) {
|
|
204
211
|
return '__dev__';
|
|
@@ -1381,6 +1388,7 @@ let activeUser = null;
|
|
|
1381
1388
|
*/
|
|
1382
1389
|
/**
|
|
1383
1390
|
* for internal use
|
|
1391
|
+
* @deprecated please use getCurrentUser api instead.
|
|
1384
1392
|
*/
|
|
1385
1393
|
const getActiveUser = () => {
|
|
1386
1394
|
if (!activeUser) {
|
|
@@ -1814,12 +1822,6 @@ const createHttpTransport = (endpoint) => {
|
|
|
1814
1822
|
controller.abort();
|
|
1815
1823
|
handleRequestCancelation(RequestCancelation.UserDeleted);
|
|
1816
1824
|
}
|
|
1817
|
-
if (tokenExpiry) {
|
|
1818
|
-
if (Date.now() >= Date.parse(tokenExpiry)) {
|
|
1819
|
-
controller.abort(RequestCancelation.UserDeleted);
|
|
1820
|
-
handleRequestCancelation(RequestCancelation.TokenExpired);
|
|
1821
|
-
}
|
|
1822
|
-
}
|
|
1823
1825
|
}
|
|
1824
1826
|
return config;
|
|
1825
1827
|
});
|
|
@@ -7316,7 +7318,7 @@ const setClientToken = async (params) => {
|
|
|
7316
7318
|
const client = getActiveClient();
|
|
7317
7319
|
// begin establishing session
|
|
7318
7320
|
setSessionState("establishing" /* Amity.SessionStates.ESTABLISHING */);
|
|
7319
|
-
const { accessToken, users, expiresAt, issuedAt } = await getToken(params);
|
|
7321
|
+
const { accessToken, users, expiresAt, issuedAt, userType } = await getToken(params);
|
|
7320
7322
|
// manually setup the token for http transport
|
|
7321
7323
|
client.http.defaults.headers.common.Authorization = `Bearer ${accessToken}`;
|
|
7322
7324
|
client.http.defaults.metadata = {
|
|
@@ -7332,7 +7334,66 @@ const setClientToken = async (params) => {
|
|
|
7332
7334
|
};
|
|
7333
7335
|
client.token = { accessToken, issuedAt, expiresAt };
|
|
7334
7336
|
setSessionState("established" /* Amity.SessionStates.ESTABLISHED */);
|
|
7335
|
-
return { accessToken, users };
|
|
7337
|
+
return { accessToken, users, userType };
|
|
7338
|
+
};
|
|
7339
|
+
|
|
7340
|
+
/**
|
|
7341
|
+
* Retrieves a pair of {@link Amity.Tokens} necessary for connection
|
|
7342
|
+
*
|
|
7343
|
+
* @param params get visitor token param
|
|
7344
|
+
* @param params.deviceId The user's device Id (can be manually set for native users)
|
|
7345
|
+
* @param params.authSignature The authenitcation signature - necessary when network option is set to secure
|
|
7346
|
+
* @param params.authSignatureExpiresAt Expire time of the authenitcation signature
|
|
7347
|
+
* @param options get bot token options
|
|
7348
|
+
* @param options.setAccessTokenCookie The authentication token - necessary when network option is set to secure
|
|
7349
|
+
* @return The accessToken for the given userId
|
|
7350
|
+
*
|
|
7351
|
+
*
|
|
7352
|
+
* @category Client API
|
|
7353
|
+
* @hidden
|
|
7354
|
+
*/
|
|
7355
|
+
const getVisitorToken = async ({ params, options, }) => {
|
|
7356
|
+
const client = getActiveClient();
|
|
7357
|
+
client.log('client/api/getVisitorToken', params);
|
|
7358
|
+
const deviceInfo = getDeviceInfo();
|
|
7359
|
+
const { data } = await client.http.post('/api/v5/sessions/visitor', Object.assign(Object.assign({}, params), { deviceInfo }), {
|
|
7360
|
+
headers: {
|
|
7361
|
+
'X-API-Key': client.apiKey,
|
|
7362
|
+
'set-access-token-cookie': (options === null || options === void 0 ? void 0 : options.setAccessTokenCookie) || false,
|
|
7363
|
+
},
|
|
7364
|
+
});
|
|
7365
|
+
return data;
|
|
7366
|
+
};
|
|
7367
|
+
|
|
7368
|
+
/**
|
|
7369
|
+
* A util to set or refresh client token
|
|
7370
|
+
*
|
|
7371
|
+
* @param params.userId the user ID for the current session
|
|
7372
|
+
* @param params.displayName the user's displayName for the current session
|
|
7373
|
+
* @param params.deviceId Manual override of the user's device id (for device management)
|
|
7374
|
+
* @param params.authToken The authentication token - necessary when network option is set to secure
|
|
7375
|
+
* @param options get bot token options
|
|
7376
|
+
* @param options.setAccessTokenCookie The authentication token - necessary when network option is set to secure
|
|
7377
|
+
* @returns token & user info
|
|
7378
|
+
*
|
|
7379
|
+
* @category private
|
|
7380
|
+
* @async
|
|
7381
|
+
*/
|
|
7382
|
+
const setVisitorClientToken = async (params) => {
|
|
7383
|
+
const client = getActiveClient();
|
|
7384
|
+
// begin establishing session
|
|
7385
|
+
setSessionState("establishing" /* Amity.SessionStates.ESTABLISHING */);
|
|
7386
|
+
const { accessToken, users, expiresAt, issuedAt, userType } = await getVisitorToken(params);
|
|
7387
|
+
// manually setup the token for http transport
|
|
7388
|
+
client.http.defaults.headers.common.Authorization = `Bearer ${accessToken}`;
|
|
7389
|
+
client.http.defaults.metadata = {
|
|
7390
|
+
tokenExpiry: expiresAt,
|
|
7391
|
+
isGlobalBanned: false,
|
|
7392
|
+
isUserDeleted: false,
|
|
7393
|
+
};
|
|
7394
|
+
client.token = { accessToken, issuedAt, expiresAt };
|
|
7395
|
+
setSessionState("established" /* Amity.SessionStates.ESTABLISHED */);
|
|
7396
|
+
return { accessToken, users, userType };
|
|
7336
7397
|
};
|
|
7337
7398
|
|
|
7338
7399
|
function prepareUserPayload(response) {
|
|
@@ -8822,13 +8883,34 @@ const removeChannelMarkerCache = (channel) => {
|
|
|
8822
8883
|
dropFromCache(['channelMarker', 'get', id], true);
|
|
8823
8884
|
};
|
|
8824
8885
|
|
|
8886
|
+
let currentUserType = null;
|
|
8887
|
+
/* begin_public_function
|
|
8888
|
+
id: client.get_current_user_type
|
|
8889
|
+
*/
|
|
8890
|
+
const getCurrentUserType = () => {
|
|
8891
|
+
if (!currentUserType) {
|
|
8892
|
+
throw new ASCError('Connect client first', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "fatal" /* Amity.ErrorLevel.FATAL */);
|
|
8893
|
+
}
|
|
8894
|
+
return currentUserType;
|
|
8895
|
+
};
|
|
8896
|
+
/* end_public_function */
|
|
8897
|
+
const setCurrentUserType = (userType) => {
|
|
8898
|
+
currentUserType = userType;
|
|
8899
|
+
};
|
|
8900
|
+
|
|
8901
|
+
const setCurrentUser = ({ user, userType, }) => {
|
|
8902
|
+
setActiveUser(user);
|
|
8903
|
+
setCurrentUserType(userType);
|
|
8904
|
+
pushToCache(['user', 'get', user.userId], user);
|
|
8905
|
+
};
|
|
8906
|
+
|
|
8825
8907
|
/* eslint-disable no-param-reassign */
|
|
8826
8908
|
/*
|
|
8827
8909
|
* declared earlier to accomodate case when logging in with a different user
|
|
8828
8910
|
* than the one already connected, in which case the existing subscriptions need
|
|
8829
8911
|
* to be cleared
|
|
8830
8912
|
*/
|
|
8831
|
-
let subscriptions$
|
|
8913
|
+
let subscriptions$3 = [];
|
|
8832
8914
|
async function runMqtt$1() {
|
|
8833
8915
|
await modifyMqttConnection();
|
|
8834
8916
|
}
|
|
@@ -8863,13 +8945,13 @@ const login = async (params, sessionHandler, config) => {
|
|
|
8863
8945
|
if (client.userId && client.userId !== params.userId) {
|
|
8864
8946
|
await logout();
|
|
8865
8947
|
// Remove subscription to ban and delete
|
|
8866
|
-
subscriptions$
|
|
8867
|
-
subscriptions$
|
|
8948
|
+
subscriptions$3.forEach(fn => fn());
|
|
8949
|
+
subscriptions$3 = [];
|
|
8868
8950
|
}
|
|
8869
8951
|
// default values
|
|
8870
8952
|
const defaultDeviceId = await getDeviceId();
|
|
8871
8953
|
try {
|
|
8872
|
-
const { users } = await setClientToken({
|
|
8954
|
+
const { users, userType } = await setClientToken({
|
|
8873
8955
|
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 }),
|
|
8874
8956
|
options: {
|
|
8875
8957
|
setAccessTokenCookie: true,
|
|
@@ -8883,7 +8965,7 @@ const login = async (params, sessionHandler, config) => {
|
|
|
8883
8965
|
terminateClient("userDeleted" /* Amity.TokenTerminationReason.USER_DELETED */);
|
|
8884
8966
|
return false;
|
|
8885
8967
|
}
|
|
8886
|
-
if (user.
|
|
8968
|
+
if (user.isGlobalBan) {
|
|
8887
8969
|
terminateClient("globalBan" /* Amity.TokenTerminationReason.GLOBAL_BAN */);
|
|
8888
8970
|
return false;
|
|
8889
8971
|
}
|
|
@@ -8894,7 +8976,7 @@ const login = async (params, sessionHandler, config) => {
|
|
|
8894
8976
|
* token expires
|
|
8895
8977
|
*/
|
|
8896
8978
|
unsubWatcher = client.accessTokenExpiryWatcher(sessionHandler);
|
|
8897
|
-
|
|
8979
|
+
setCurrentUser({ user, userType });
|
|
8898
8980
|
}
|
|
8899
8981
|
catch (error) {
|
|
8900
8982
|
/*
|
|
@@ -8909,42 +8991,141 @@ const login = async (params, sessionHandler, config) => {
|
|
|
8909
8991
|
runMqtt$1();
|
|
8910
8992
|
}
|
|
8911
8993
|
await initializeMessagePreviewSetting();
|
|
8912
|
-
if (subscriptions$
|
|
8913
|
-
subscriptions$
|
|
8994
|
+
if (subscriptions$3.length === 0) {
|
|
8995
|
+
subscriptions$3.push(
|
|
8914
8996
|
// GLOBAL_BAN
|
|
8915
8997
|
onClientBanned((_) => {
|
|
8916
8998
|
terminateClient("globalBan" /* Amity.TokenTerminationReason.GLOBAL_BAN */);
|
|
8917
|
-
subscriptions$
|
|
8999
|
+
subscriptions$3.forEach(fn => fn());
|
|
8918
9000
|
unsubWatcher();
|
|
8919
9001
|
}), onTokenTerminated(_ => {
|
|
8920
9002
|
terminateClient();
|
|
8921
|
-
subscriptions$
|
|
9003
|
+
subscriptions$3.forEach(fn => fn());
|
|
8922
9004
|
unsubWatcher();
|
|
8923
9005
|
}), onUserDeleted$2((user) => {
|
|
8924
9006
|
if (user.userId === client.userId) {
|
|
8925
9007
|
terminateClient("userDeleted" /* Amity.TokenTerminationReason.USER_DELETED */);
|
|
8926
|
-
subscriptions$
|
|
9008
|
+
subscriptions$3.forEach(fn => fn());
|
|
8927
9009
|
unsubWatcher();
|
|
8928
9010
|
}
|
|
8929
9011
|
}), onTokenExpired(state => {
|
|
8930
9012
|
SessionWatcher$1.getInstance().setSessionState(state);
|
|
8931
9013
|
logout();
|
|
8932
|
-
subscriptions$
|
|
9014
|
+
subscriptions$3.forEach(fn => fn());
|
|
8933
9015
|
}),
|
|
8934
9016
|
// NOTE: This is a temporary solution to handle the channel marker when the user is forced to leave
|
|
8935
9017
|
// the channel because currently backend can't handle this, so every time a user is banned from
|
|
8936
9018
|
// a channel or the channel is deleted the channel's unread count will not be reset to zero
|
|
8937
9019
|
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler(), reactionSyncEngineOnLoginHandler());
|
|
8938
9020
|
if (client.useLegacyUnreadCount) {
|
|
8939
|
-
subscriptions$
|
|
9021
|
+
subscriptions$3.push(readReceiptSyncEngineOnLoginHandler());
|
|
8940
9022
|
}
|
|
8941
9023
|
else
|
|
8942
|
-
subscriptions$
|
|
9024
|
+
subscriptions$3.push(legacyReadReceiptSyncEngineOnLoginHandler());
|
|
9025
|
+
}
|
|
9026
|
+
return true;
|
|
9027
|
+
};
|
|
9028
|
+
/* end_public_function */
|
|
9029
|
+
|
|
9030
|
+
/* eslint-disable require-atomic-updates */
|
|
9031
|
+
/*
|
|
9032
|
+
* declared earlier to accomodate case when logging in with a different user
|
|
9033
|
+
* than the one already connected, in which case the existing subscriptions need
|
|
9034
|
+
* to be cleared
|
|
9035
|
+
*/
|
|
9036
|
+
const subscriptions$2 = [];
|
|
9037
|
+
/* begin_public_function
|
|
9038
|
+
id: client.loginAsVisitor
|
|
9039
|
+
*/
|
|
9040
|
+
/**
|
|
9041
|
+
* ```js
|
|
9042
|
+
* import { loginAsVisitor } from '@amityco/ts-sdk/client/api'
|
|
9043
|
+
* const success = await loginAsVisitor({
|
|
9044
|
+
sessionHandler: {
|
|
9045
|
+
sessionWillRenewAccessToken(renewal: Amity.AccessTokenRenewal) {
|
|
9046
|
+
...
|
|
9047
|
+
}
|
|
9048
|
+
* })
|
|
9049
|
+
* ```
|
|
9050
|
+
*
|
|
9051
|
+
* Connects an {@link Amity.Client} instance to ASC servers
|
|
9052
|
+
*
|
|
9053
|
+
* @param params. the connect parameters
|
|
9054
|
+
* @param params.authSignature The authenitcation signature - necessary when network option is set to secure
|
|
9055
|
+
* @param params.authSignatureExpiresAt Expire time of the authenitcation signature
|
|
9056
|
+
* @param params.sessionHandler
|
|
9057
|
+
* @returns a success boolean if connected
|
|
9058
|
+
*
|
|
9059
|
+
* @category Client API
|
|
9060
|
+
* @async
|
|
9061
|
+
*/
|
|
9062
|
+
const loginAsVisitor = async (params) => {
|
|
9063
|
+
const client = getActiveClient();
|
|
9064
|
+
let unsubWatcher;
|
|
9065
|
+
client.log('client/api/connectClient', Object.assign({ apiKey: client.apiKey, sessionState: client.sessionState }, params));
|
|
9066
|
+
// generate deviceId
|
|
9067
|
+
const deviceId = await getDeviceId();
|
|
9068
|
+
let user;
|
|
9069
|
+
try {
|
|
9070
|
+
const { users, userType } = await setVisitorClientToken({
|
|
9071
|
+
params: Object.assign(Object.assign({}, params), { deviceId }),
|
|
9072
|
+
options: {
|
|
9073
|
+
setAccessTokenCookie: true,
|
|
9074
|
+
},
|
|
9075
|
+
});
|
|
9076
|
+
[user] = users;
|
|
9077
|
+
client.userId = user.userId;
|
|
9078
|
+
client.sessionHandler = params.sessionHandler;
|
|
9079
|
+
/*
|
|
9080
|
+
* Cannot push to subscriptions as watcher needs to continue working even if
|
|
9081
|
+
* token expires
|
|
9082
|
+
*/
|
|
9083
|
+
unsubWatcher = client.accessTokenExpiryWatcher(params.sessionHandler);
|
|
9084
|
+
setCurrentUser({ user, userType });
|
|
9085
|
+
}
|
|
9086
|
+
catch (error) {
|
|
9087
|
+
/*
|
|
9088
|
+
* if getting token failed session state reverts to initial state when app
|
|
9089
|
+
* is first launched
|
|
9090
|
+
*/
|
|
9091
|
+
SessionWatcher$1.getInstance().setSessionState("notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */);
|
|
9092
|
+
// pass error down tree so the calling function handle it
|
|
9093
|
+
throw error;
|
|
9094
|
+
}
|
|
9095
|
+
await initializeMessagePreviewSetting();
|
|
9096
|
+
if (subscriptions$2.length === 0) {
|
|
9097
|
+
// handling internal SDK events
|
|
9098
|
+
subscriptions$2.push(onTokenTerminated(_ => {
|
|
9099
|
+
terminateClient();
|
|
9100
|
+
subscriptions$2.forEach(fn => fn());
|
|
9101
|
+
unsubWatcher();
|
|
9102
|
+
}), onTokenExpired(state => {
|
|
9103
|
+
SessionWatcher$1.getInstance().setSessionState(state);
|
|
9104
|
+
logout();
|
|
9105
|
+
subscriptions$2.forEach(fn => fn());
|
|
9106
|
+
}));
|
|
8943
9107
|
}
|
|
8944
9108
|
return true;
|
|
8945
9109
|
};
|
|
8946
9110
|
/* end_public_function */
|
|
8947
9111
|
|
|
9112
|
+
/* begin_public_function
|
|
9113
|
+
id: client.get_current_user
|
|
9114
|
+
*/
|
|
9115
|
+
const getCurrentUser = () => {
|
|
9116
|
+
var _a;
|
|
9117
|
+
const client = getActiveClient();
|
|
9118
|
+
if (!client) {
|
|
9119
|
+
throw new ASCError('Connect client first', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "fatal" /* Amity.ErrorLevel.FATAL */);
|
|
9120
|
+
}
|
|
9121
|
+
const cache = (_a = pullFromCache(['user', 'get', client.userId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
9122
|
+
if (!cache) {
|
|
9123
|
+
throw new ASCError('Connect client first', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "fatal" /* Amity.ErrorLevel.FATAL */);
|
|
9124
|
+
}
|
|
9125
|
+
return userLinkedObject(cache);
|
|
9126
|
+
};
|
|
9127
|
+
/* end_public_function */
|
|
9128
|
+
|
|
8948
9129
|
/* begin_public_function
|
|
8949
9130
|
id: client.renew_access_token
|
|
8950
9131
|
*/
|
|
@@ -8967,7 +9148,7 @@ const renewal = () => {
|
|
|
8967
9148
|
* Per instance of Renewal, only one renewal is allowed
|
|
8968
9149
|
*/
|
|
8969
9150
|
const renewToken = async (authToken) => {
|
|
8970
|
-
const { userId, displayName } =
|
|
9151
|
+
const { userId, displayName } = getCurrentUser();
|
|
8971
9152
|
const deviceId = await getDeviceId();
|
|
8972
9153
|
const params = { userId, displayName, authToken, deviceId };
|
|
8973
9154
|
if (client.sessionState === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */ && client.sessionHandler) {
|
|
@@ -8986,6 +9167,24 @@ const renewal = () => {
|
|
|
8986
9167
|
if (renewTimeoutId)
|
|
8987
9168
|
clearTimeout(renewTimeoutId);
|
|
8988
9169
|
};
|
|
9170
|
+
const renewVisitorToken = async ({ authSignature, authSignatureExpiresAt, }) => {
|
|
9171
|
+
const deviceId = await getDeviceId();
|
|
9172
|
+
if (client.sessionState === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */ && client.sessionHandler) {
|
|
9173
|
+
await loginAsVisitor({ sessionHandler: client.sessionHandler });
|
|
9174
|
+
}
|
|
9175
|
+
else {
|
|
9176
|
+
// about to expire
|
|
9177
|
+
await setVisitorClientToken({
|
|
9178
|
+
params: { authSignature, authSignatureExpiresAt, deviceId },
|
|
9179
|
+
options: {
|
|
9180
|
+
setAccessTokenCookie: true,
|
|
9181
|
+
},
|
|
9182
|
+
});
|
|
9183
|
+
}
|
|
9184
|
+
tokenRenewed = true;
|
|
9185
|
+
if (renewTimeoutId)
|
|
9186
|
+
clearTimeout(renewTimeoutId);
|
|
9187
|
+
};
|
|
8989
9188
|
return {
|
|
8990
9189
|
renew: () => {
|
|
8991
9190
|
if (tokenRenewed) {
|
|
@@ -9007,6 +9206,19 @@ const renewal = () => {
|
|
|
9007
9206
|
(_a = client.sessionHandler) === null || _a === void 0 ? void 0 : _a.sessionWillRenewAccessToken(renewal());
|
|
9008
9207
|
}, ACCESS_TOKEN_WATCHER_INTERVAL);
|
|
9009
9208
|
},
|
|
9209
|
+
renewWithAuthSignature: (params) => {
|
|
9210
|
+
if (tokenRenewed) {
|
|
9211
|
+
console.log("'renew' method can be called only once per renewal instance");
|
|
9212
|
+
return;
|
|
9213
|
+
}
|
|
9214
|
+
renewVisitorToken(params);
|
|
9215
|
+
},
|
|
9216
|
+
unableToRetrieveAuthSignature: () => {
|
|
9217
|
+
renewTimeoutId = setTimeout(() => {
|
|
9218
|
+
var _a;
|
|
9219
|
+
(_a = client.sessionHandler) === null || _a === void 0 ? void 0 : _a.sessionWillRenewAccessToken(renewal());
|
|
9220
|
+
}, ACCESS_TOKEN_WATCHER_INTERVAL);
|
|
9221
|
+
},
|
|
9010
9222
|
};
|
|
9011
9223
|
};
|
|
9012
9224
|
/* end_public_function */
|
|
@@ -9573,6 +9785,7 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
|
|
|
9573
9785
|
validateTexts,
|
|
9574
9786
|
getFeedSettings,
|
|
9575
9787
|
getSocialSettings,
|
|
9788
|
+
getVisitorDeviceId: getDeviceId,
|
|
9576
9789
|
getMessagePreviewSetting,
|
|
9577
9790
|
onRTEConnectionStateChange,
|
|
9578
9791
|
use: () => setActiveClient(client),
|
|
@@ -9629,7 +9842,7 @@ const secureLogout = async () => {
|
|
|
9629
9842
|
* than the one already connected, in which case the existing subscriptions need
|
|
9630
9843
|
* to be cleared
|
|
9631
9844
|
*/
|
|
9632
|
-
let subscriptions = [];
|
|
9845
|
+
let subscriptions$1 = [];
|
|
9633
9846
|
async function runMqtt() {
|
|
9634
9847
|
await modifyMqttConnection();
|
|
9635
9848
|
}
|
|
@@ -9701,15 +9914,15 @@ const resumeSession = async (params, sessionHandler, config) => {
|
|
|
9701
9914
|
client.mqtt.disconnect();
|
|
9702
9915
|
}
|
|
9703
9916
|
// Clear existing subscriptions
|
|
9704
|
-
subscriptions.forEach(fn => fn());
|
|
9705
|
-
subscriptions = [];
|
|
9917
|
+
subscriptions$1.forEach(fn => fn());
|
|
9918
|
+
subscriptions$1 = [];
|
|
9706
9919
|
}
|
|
9707
9920
|
else {
|
|
9708
9921
|
// Different user - do full logout
|
|
9709
9922
|
await logout();
|
|
9710
9923
|
// Remove subscription to ban and delete
|
|
9711
|
-
subscriptions.forEach(fn => fn());
|
|
9712
|
-
subscriptions = [];
|
|
9924
|
+
subscriptions$1.forEach(fn => fn());
|
|
9925
|
+
subscriptions$1 = [];
|
|
9713
9926
|
}
|
|
9714
9927
|
}
|
|
9715
9928
|
try {
|
|
@@ -9747,37 +9960,37 @@ const resumeSession = async (params, sessionHandler, config) => {
|
|
|
9747
9960
|
runMqtt();
|
|
9748
9961
|
}
|
|
9749
9962
|
await initializeMessagePreviewSetting();
|
|
9750
|
-
if (subscriptions.length === 0) {
|
|
9751
|
-
subscriptions.push(
|
|
9963
|
+
if (subscriptions$1.length === 0) {
|
|
9964
|
+
subscriptions$1.push(
|
|
9752
9965
|
// GLOBAL_BAN
|
|
9753
9966
|
onClientBanned((_) => {
|
|
9754
9967
|
terminateClient("globalBan" /* Amity.TokenTerminationReason.GLOBAL_BAN */);
|
|
9755
|
-
subscriptions.forEach(fn => fn());
|
|
9968
|
+
subscriptions$1.forEach(fn => fn());
|
|
9756
9969
|
unsubWatcher();
|
|
9757
9970
|
}), onTokenTerminated(_ => {
|
|
9758
9971
|
terminateClient();
|
|
9759
|
-
subscriptions.forEach(fn => fn());
|
|
9972
|
+
subscriptions$1.forEach(fn => fn());
|
|
9760
9973
|
unsubWatcher();
|
|
9761
9974
|
}), onUserDeleted$2((user) => {
|
|
9762
9975
|
if (user.userId === client.userId) {
|
|
9763
9976
|
terminateClient("userDeleted" /* Amity.TokenTerminationReason.USER_DELETED */);
|
|
9764
|
-
subscriptions.forEach(fn => fn());
|
|
9977
|
+
subscriptions$1.forEach(fn => fn());
|
|
9765
9978
|
unsubWatcher();
|
|
9766
9979
|
}
|
|
9767
9980
|
}), onTokenExpired(state => {
|
|
9768
9981
|
SessionWatcher$1.getInstance().setSessionState(state);
|
|
9769
9982
|
logout();
|
|
9770
|
-
subscriptions.forEach(fn => fn());
|
|
9983
|
+
subscriptions$1.forEach(fn => fn());
|
|
9771
9984
|
}),
|
|
9772
9985
|
// NOTE: This is a temporary solution to handle the channel marker when the user is forced to leave
|
|
9773
9986
|
// the channel because currently backend can't handle this, so every time a user is banned from
|
|
9774
9987
|
// a channel or the channel is deleted the channel's unread count will not be reset to zero
|
|
9775
9988
|
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler());
|
|
9776
9989
|
if (client.useLegacyUnreadCount) {
|
|
9777
|
-
subscriptions.push(readReceiptSyncEngineOnLoginHandler());
|
|
9990
|
+
subscriptions$1.push(readReceiptSyncEngineOnLoginHandler());
|
|
9778
9991
|
}
|
|
9779
9992
|
else
|
|
9780
|
-
subscriptions.push(legacyReadReceiptSyncEngineOnLoginHandler());
|
|
9993
|
+
subscriptions$1.push(legacyReadReceiptSyncEngineOnLoginHandler());
|
|
9781
9994
|
}
|
|
9782
9995
|
return true;
|
|
9783
9996
|
};
|
|
@@ -9912,6 +10125,142 @@ const getShareableLinkConfiguration = async () => {
|
|
|
9912
10125
|
return data;
|
|
9913
10126
|
};
|
|
9914
10127
|
|
|
10128
|
+
/**
|
|
10129
|
+
* Retrieves a pair of {@link Amity.Tokens} necessary for connection
|
|
10130
|
+
*
|
|
10131
|
+
* @param param get bot token param
|
|
10132
|
+
* @param params.deviceId The user's device Id (can be manually set for native users)
|
|
10133
|
+
* @param options get bot token options
|
|
10134
|
+
* @param options.setAccessTokenCookie The authentication token - necessary when network option is set to secure
|
|
10135
|
+
* @return The accessToken for the given userId
|
|
10136
|
+
*
|
|
10137
|
+
* @category Client API
|
|
10138
|
+
* @hidden
|
|
10139
|
+
*/
|
|
10140
|
+
const getBotToken = async ({ params, options, }) => {
|
|
10141
|
+
const client = getActiveClient();
|
|
10142
|
+
client.log('client/api/getBotToken');
|
|
10143
|
+
const deviceInfo = getDeviceInfo();
|
|
10144
|
+
const { data } = await client.http.post('/api/v5/sessions/bot', Object.assign(Object.assign({}, params), { deviceInfo }), {
|
|
10145
|
+
headers: {
|
|
10146
|
+
'X-API-Key': client.apiKey,
|
|
10147
|
+
'set-access-token-cookie': (options === null || options === void 0 ? void 0 : options.setAccessTokenCookie) || false,
|
|
10148
|
+
},
|
|
10149
|
+
});
|
|
10150
|
+
return data;
|
|
10151
|
+
};
|
|
10152
|
+
|
|
10153
|
+
/**
|
|
10154
|
+
* A util to set or refresh client token
|
|
10155
|
+
* @param options get bot token options
|
|
10156
|
+
* @param options.setAccessTokenCookie The authentication token - necessary when network option is set to secure
|
|
10157
|
+
* @returns token & user info
|
|
10158
|
+
*
|
|
10159
|
+
* @category private
|
|
10160
|
+
* @async
|
|
10161
|
+
*/
|
|
10162
|
+
const setBotClientToken = async (params) => {
|
|
10163
|
+
const client = getActiveClient();
|
|
10164
|
+
// begin establishing session
|
|
10165
|
+
setSessionState("establishing" /* Amity.SessionStates.ESTABLISHING */);
|
|
10166
|
+
const { accessToken, users, expiresAt, issuedAt, userType } = await getBotToken(params);
|
|
10167
|
+
// manually setup the token for http transport
|
|
10168
|
+
client.http.defaults.headers.common.Authorization = `Bearer ${accessToken}`;
|
|
10169
|
+
client.http.defaults.metadata = {
|
|
10170
|
+
tokenExpiry: expiresAt,
|
|
10171
|
+
isGlobalBanned: false,
|
|
10172
|
+
isUserDeleted: false,
|
|
10173
|
+
};
|
|
10174
|
+
client.token = { accessToken, issuedAt, expiresAt };
|
|
10175
|
+
setSessionState("established" /* Amity.SessionStates.ESTABLISHED */);
|
|
10176
|
+
return { accessToken, users, userType };
|
|
10177
|
+
};
|
|
10178
|
+
|
|
10179
|
+
/* eslint-disable require-atomic-updates */
|
|
10180
|
+
/*
|
|
10181
|
+
* declared earlier to accomodate case when logging in with a different user
|
|
10182
|
+
* than the one already connected, in which case the existing subscriptions need
|
|
10183
|
+
* to be cleared
|
|
10184
|
+
*/
|
|
10185
|
+
const subscriptions = [];
|
|
10186
|
+
/* begin_public_function
|
|
10187
|
+
id: client.loginAsBot
|
|
10188
|
+
*/
|
|
10189
|
+
/**
|
|
10190
|
+
* ```js
|
|
10191
|
+
* import { loginAsBot } from '@amityco/ts-sdk/client/api'
|
|
10192
|
+
* const success = await loginAsBot({
|
|
10193
|
+
sessionHandler: {
|
|
10194
|
+
sessionWillRenewAccessToken(renewal: Amity.AccessTokenRenewal) {
|
|
10195
|
+
...
|
|
10196
|
+
}
|
|
10197
|
+
* })
|
|
10198
|
+
* ```
|
|
10199
|
+
*
|
|
10200
|
+
* Connects an {@link Amity.Client} instance to ASC servers
|
|
10201
|
+
*
|
|
10202
|
+
* @param params. the connect parameters
|
|
10203
|
+
* @param params.sessionHandler
|
|
10204
|
+
* @returns a success boolean if connected
|
|
10205
|
+
*
|
|
10206
|
+
* @category Client API
|
|
10207
|
+
* @async
|
|
10208
|
+
*/
|
|
10209
|
+
const loginAsBot = async (params) => {
|
|
10210
|
+
const client = getActiveClient();
|
|
10211
|
+
let unsubWatcher;
|
|
10212
|
+
client.log('client/api/connectClient', {
|
|
10213
|
+
apiKey: client.apiKey,
|
|
10214
|
+
sessionState: client.sessionState,
|
|
10215
|
+
});
|
|
10216
|
+
// generate deviceId
|
|
10217
|
+
const deviceId = await getDeviceId();
|
|
10218
|
+
let user;
|
|
10219
|
+
try {
|
|
10220
|
+
const { users, userType } = await setBotClientToken({
|
|
10221
|
+
params: {
|
|
10222
|
+
deviceId,
|
|
10223
|
+
},
|
|
10224
|
+
options: {
|
|
10225
|
+
setAccessTokenCookie: true,
|
|
10226
|
+
},
|
|
10227
|
+
});
|
|
10228
|
+
[user] = users;
|
|
10229
|
+
client.userId = user.userId;
|
|
10230
|
+
client.sessionHandler = params.sessionHandler;
|
|
10231
|
+
/*
|
|
10232
|
+
* Cannot push to subscriptions as watcher needs to continue working even if
|
|
10233
|
+
* token expires
|
|
10234
|
+
*/
|
|
10235
|
+
unsubWatcher = client.accessTokenExpiryWatcher(params.sessionHandler);
|
|
10236
|
+
setCurrentUser({ user, userType });
|
|
10237
|
+
}
|
|
10238
|
+
catch (error) {
|
|
10239
|
+
/*
|
|
10240
|
+
* if getting token failed session state reverts to initial state when app
|
|
10241
|
+
* is first launched
|
|
10242
|
+
*/
|
|
10243
|
+
SessionWatcher$1.getInstance().setSessionState("notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */);
|
|
10244
|
+
// pass error down tree so the calling function handle it
|
|
10245
|
+
throw error;
|
|
10246
|
+
}
|
|
10247
|
+
await initializeMessagePreviewSetting();
|
|
10248
|
+
if (subscriptions.length === 0) {
|
|
10249
|
+
// handling internal SDK events
|
|
10250
|
+
subscriptions.push(onTokenTerminated(_ => {
|
|
10251
|
+
terminateClient();
|
|
10252
|
+
subscriptions.forEach(fn => fn());
|
|
10253
|
+
unsubWatcher();
|
|
10254
|
+
}), onTokenExpired(state => {
|
|
10255
|
+
SessionWatcher$1.getInstance().setSessionState(state);
|
|
10256
|
+
logout();
|
|
10257
|
+
subscriptions.forEach(fn => fn());
|
|
10258
|
+
}));
|
|
10259
|
+
}
|
|
10260
|
+
return true;
|
|
10261
|
+
};
|
|
10262
|
+
/* end_public_function */
|
|
10263
|
+
|
|
9915
10264
|
/**
|
|
9916
10265
|
* ```js
|
|
9917
10266
|
* import { onChannelMarkerFetched } from '@amityco/ts-sdk-react-native'
|
|
@@ -10286,6 +10635,11 @@ var index$o = /*#__PURE__*/Object.freeze({
|
|
|
10286
10635
|
fetchLinkPreview: fetchLinkPreview,
|
|
10287
10636
|
getSocialSettings: getSocialSettings,
|
|
10288
10637
|
getShareableLinkConfiguration: getShareableLinkConfiguration,
|
|
10638
|
+
loginAsVisitor: loginAsVisitor,
|
|
10639
|
+
loginAsBot: loginAsBot,
|
|
10640
|
+
getCurrentUser: getCurrentUser,
|
|
10641
|
+
getCurrentUserType: getCurrentUserType,
|
|
10642
|
+
setCurrentUserType: setCurrentUserType,
|
|
10289
10643
|
onConnectionError: onConnectionError,
|
|
10290
10644
|
onClientDisconnected: onClientDisconnected,
|
|
10291
10645
|
onClientBanned: onClientBanned,
|
|
@@ -23180,7 +23534,7 @@ const getCategory = async (categoryId) => {
|
|
|
23180
23534
|
ingestInCache(data, { cachedAt });
|
|
23181
23535
|
const { categories } = data;
|
|
23182
23536
|
return {
|
|
23183
|
-
data: LinkedObject.category(categories.find(category => category.categoryId === categoryId)),
|
|
23537
|
+
data: LinkedObject.category((categories !== null && categories !== void 0 ? categories : []).find(category => category.categoryId === categoryId)),
|
|
23184
23538
|
cachedAt,
|
|
23185
23539
|
};
|
|
23186
23540
|
};
|
|
@@ -27622,7 +27976,7 @@ var index$6 = /*#__PURE__*/Object.freeze({
|
|
|
27622
27976
|
getPoll: getPoll
|
|
27623
27977
|
});
|
|
27624
27978
|
|
|
27625
|
-
const privateKey = "-----BEGIN PRIVATE KEY-----\
|
|
27979
|
+
const privateKey = "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDHo80SecH7FuF2\nhFYnb+l26/VN8UMLXAQFLnxciNTEwkGVFMpdezlH8rU2HtUJL4RETogbAOLVY0XM\njs6sPn8G1nALmh9qeDpUtVqFOVtBHxEZ910TLOtQiunjqJKO5nWdqZ71EC3OFluR\niGQkO84BiIFbv37ub7xl3S8XarbtKoLcyVpkDHi+1wx1pgCAn6gtBUgckPL5NR8j\nLseabl3HAXQfhTCKo4tmOFM2Dxwl1IUMmIJrJg/aIU/U0tj/1Eoo7mG0JcNWX19l\nW3EecCbi0ncCJOrkUdwlBrcjaMayaX/ubEwyUeTGiLdyc4L3GRLHjyK8xgVNXRMH\nbZWJ2a5NAgMBAAECggEASxuE+35zTFO/XydKgmvIGcWL9FbgMlXb7Vcf0nBoG945\nbiz0NVc2paraIhJXc608xbYF3qLmtAE1MVBI0ORyRdBHNxY024l/6H6SH60Ed+uI\nM4ysp5ourY6Vj+DLwpdRiI9YDjqYAQDIUmhNxJP7XPhOMoZI6st+xZQBM34ic/bv\nAMSJm9OZphSp3+qXVkFZztr2mxD2EZSJJLYxi8BCdgM2qhazalbcJ6zDKHCZWVWm\n8RRxDGldyMb/237JxETzP40tAlzOZDmBAbUgEnurDJ93RVDIE3rbZUshwgeQd18a\nem096mWgvB1AIKYgsTAR3pw+V19YWAjq/glP6fz8wQKBgQD/oQq+ukKF0PRgBeM5\ngeTjSwsdGppQLmf5ndujvoiz/TpdjDEPu6R8kigQr1rG2t4K/yfdZoI8RdmJD1al\n3Q7N9hofooSy4rj6E3txzWZCHJjHad2cnCp/O26HiReGAl7wTcfTmNdiFHhZQzm5\nJBkvWAiwuvQMNfEbnXxw6/vIDwKBgQDH7fX8gsc77JLvAWgp1MaQN/sbqVb6JeT1\nFQfR8E/WFCSmzQBtNzd5KgYuCeelwr/8DyYytvN2BzCYZXp73gI1jF3YlW5jVn74\nOY6TwQ095digwo6Z0yuxopdIOApKgAkL9PRKgNrqAf3NAyMua6lOGifzjDojC3KU\nfylQmxMn4wKBgHp2B9O/H0dEBw5JQ8W0+JX6yWQz7mEjGiR2/1W+XXb8hQ1zr709\nw1r6Gb+EghRpnZ3fBpYGGbYOMFx8wKHM+N6qW3F0ReX8v2juFGE8aRSa5oYBrWzt\nU16Idjbv8hj84cZ1PJmdyvDtpYn9rpWHOZl4rxEbPvbqkIsOMyNVqdT5AoGAOSge\nmwIIU2le2FVeohbibXiToWTYKMuMmURZ5/r72AgKMmWJKbAPe+Q3wBG01/7FRBpQ\noU8Ma0HC8s6QJbliiEyIx9JwrJWd1vkdecBHONrtA4ibm/5zD2WcOllLF+FitLhi\n3qnX6+6F0IaFGFBPJrTzlv0P4dTz/OAdv52V7GECgYEA2TttOKBAqWllgOaZOkql\nLVMJVmgR7s6tLi1+cEP8ZcapV9aRbRzTAKXm4f8AEhtlG9F9kCOvHYCYGi6JaiWJ\nZkHjeex3T+eE6Di6y5Bm/Ift5jtVhJ4jCVwHOKTMej79NPUFTJfv8hCo29haBDv6\nRXFrv+T21KCcw8k3sJeJWWQ=\n-----END PRIVATE KEY-----";
|
|
27626
27980
|
/*
|
|
27627
27981
|
* The crypto algorithm used for importing key and signing string
|
|
27628
27982
|
*/
|