@amityco/ts-sdk 7.5.4-6dc7299.0 → 7.5.4-734bd35a.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/dist/@types/domains/channel.d.ts +0 -1
- package/dist/@types/domains/channel.d.ts.map +1 -1
- package/dist/@types/domains/group.d.ts +0 -2
- package/dist/@types/domains/group.d.ts.map +1 -1
- package/dist/channelRepository/channelMembership/observers/getMembers/ChannelMemberLiveCollectionController.d.ts.map +1 -1
- package/dist/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberLiveCollectionController.d.ts.map +1 -1
- package/dist/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberQueryStreamController.d.ts +2 -2
- package/dist/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberQueryStreamController.d.ts.map +1 -1
- package/dist/client/api/index.d.ts +0 -1
- package/dist/client/api/index.d.ts.map +1 -1
- package/dist/index.cjs.js +14 -215
- package/dist/index.esm.js +14 -214
- package/dist/index.umd.js +4 -4
- package/dist/utils/linkedObject/channelLinkedObject.d.ts.map +1 -1
- package/dist/utils/linkedObject/index.d.ts +0 -1
- package/dist/utils/linkedObject/index.d.ts.map +1 -1
- package/dist/utils/tests/dummy/community.d.ts +0 -2
- package/dist/utils/tests/dummy/community.d.ts.map +1 -1
- package/package.json +1 -2
- package/src/@types/domains/channel.ts +0 -1
- package/src/@types/domains/group.ts +0 -2
- package/src/channelRepository/channelMembership/observers/getMembers/ChannelMemberLiveCollectionController.ts +1 -3
- package/src/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberLiveCollectionController.ts +1 -2
- package/src/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberQueryStreamController.ts +2 -2
- package/src/client/api/index.ts +0 -1
- package/src/utils/linkedObject/channelLinkedObject.ts +0 -19
- package/src/utils/linkedObject/index.ts +0 -2
- package/dist/client/api/resumeSession.d.ts +0 -32
- package/dist/client/api/resumeSession.d.ts.map +0 -1
- package/dist/client/api/tests/resumeSession.test.d.ts +0 -2
- package/dist/client/api/tests/resumeSession.test.d.ts.map +0 -1
- package/dist/utils/linkedObject/channelMemberLinkedObject.d.ts +0 -2
- package/dist/utils/linkedObject/channelMemberLinkedObject.d.ts.map +0 -1
- package/src/client/api/resumeSession.ts +0 -282
- package/src/client/api/tests/resumeSession.test.ts +0 -173
- package/src/utils/linkedObject/channelMemberLinkedObject.ts +0 -20
package/dist/index.esm.js
CHANGED
|
@@ -6,7 +6,6 @@ import HttpAgent, { HttpsAgent } from 'agentkeepalive';
|
|
|
6
6
|
import io from 'socket.io-client';
|
|
7
7
|
import uuid$1 from 'react-native-uuid';
|
|
8
8
|
import hash from 'object-hash';
|
|
9
|
-
import jwtDecode from 'jwt-decode';
|
|
10
9
|
import Hls from 'hls.js';
|
|
11
10
|
|
|
12
11
|
var MembershipAcceptanceTypeEnum;
|
|
@@ -23387,35 +23386,9 @@ const markAsRead = async (channelId) => {
|
|
|
23387
23386
|
return true;
|
|
23388
23387
|
};
|
|
23389
23388
|
|
|
23390
|
-
const channelMemberLinkedObject = (channelMember) => {
|
|
23391
|
-
const getUser = () => {
|
|
23392
|
-
var _a;
|
|
23393
|
-
const cacheKey = ['user', 'get', channelMember.userId];
|
|
23394
|
-
const internalUser = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23395
|
-
return internalUser ? userLinkedObject(internalUser) : undefined;
|
|
23396
|
-
};
|
|
23397
|
-
return Object.assign(Object.assign({}, channelMember), { get user() {
|
|
23398
|
-
return getUser();
|
|
23399
|
-
} });
|
|
23400
|
-
};
|
|
23401
|
-
|
|
23402
23389
|
const channelLinkedObject = (channel) => {
|
|
23403
|
-
var _a;
|
|
23404
|
-
let previewMembers = [];
|
|
23405
|
-
if (channel.type === 'conversation') {
|
|
23406
|
-
const channelUsers = queryCache(['channelUsers', 'get']);
|
|
23407
|
-
if (channelUsers && (channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.length) > 0) {
|
|
23408
|
-
previewMembers = ((_a = channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.filter(({ data }) => data.channelId === channel.channelId)) !== null && _a !== void 0 ? _a : [])
|
|
23409
|
-
// sort in ascending order by userInternalId
|
|
23410
|
-
.sort((a, b) => a.data.userInternalId.localeCompare(b.data.userInternalId))
|
|
23411
|
-
// Select only first 4 members
|
|
23412
|
-
.slice(0, 4)
|
|
23413
|
-
.map(({ data }) => channelMemberLinkedObject(data));
|
|
23414
|
-
}
|
|
23415
|
-
}
|
|
23416
23390
|
return shallowClone(channel, {
|
|
23417
23391
|
markAsRead: () => markAsRead(channel.channelInternalId),
|
|
23418
|
-
previewMembers,
|
|
23419
23392
|
});
|
|
23420
23393
|
};
|
|
23421
23394
|
|
|
@@ -24738,7 +24711,6 @@ const LinkedObject = {
|
|
|
24738
24711
|
community: communityLinkedObject,
|
|
24739
24712
|
invitation: invitationLinkedObject,
|
|
24740
24713
|
joinRequest: joinRequestLinkedObject,
|
|
24741
|
-
channelMember: channelMemberLinkedObject,
|
|
24742
24714
|
};
|
|
24743
24715
|
|
|
24744
24716
|
const constructChannelObject = (channel) => {
|
|
@@ -26021,8 +25993,8 @@ const removeChannelMarkerCache = (channel) => {
|
|
|
26021
25993
|
* than the one already connected, in which case the existing subscriptions need
|
|
26022
25994
|
* to be cleared
|
|
26023
25995
|
*/
|
|
26024
|
-
let subscriptions
|
|
26025
|
-
async function runMqtt
|
|
25996
|
+
let subscriptions = [];
|
|
25997
|
+
async function runMqtt() {
|
|
26026
25998
|
await modifyMqttConnection();
|
|
26027
25999
|
}
|
|
26028
26000
|
/* begin_public_function
|
|
@@ -26057,8 +26029,8 @@ const login = async (params, sessionHandler, config) => {
|
|
|
26057
26029
|
if (client.userId && client.userId !== params.userId) {
|
|
26058
26030
|
await logout();
|
|
26059
26031
|
// Remove subscription to ban and delete
|
|
26060
|
-
subscriptions
|
|
26061
|
-
subscriptions
|
|
26032
|
+
subscriptions.forEach(fn => fn());
|
|
26033
|
+
subscriptions = [];
|
|
26062
26034
|
}
|
|
26063
26035
|
// default values
|
|
26064
26036
|
const defaultDeviceId = await getDeviceId();
|
|
@@ -26104,40 +26076,40 @@ const login = async (params, sessionHandler, config) => {
|
|
|
26104
26076
|
throw error;
|
|
26105
26077
|
}
|
|
26106
26078
|
if ((config === null || config === void 0 ? void 0 : config.disableRTE) !== true) {
|
|
26107
|
-
runMqtt
|
|
26079
|
+
runMqtt();
|
|
26108
26080
|
}
|
|
26109
26081
|
await initializeMessagePreviewSetting();
|
|
26110
|
-
if (subscriptions
|
|
26111
|
-
subscriptions
|
|
26082
|
+
if (subscriptions.length === 0) {
|
|
26083
|
+
subscriptions.push(
|
|
26112
26084
|
// GLOBAL_BAN
|
|
26113
26085
|
onClientBanned((_) => {
|
|
26114
26086
|
terminateClient("globalBan" /* Amity.TokenTerminationReason.GLOBAL_BAN */);
|
|
26115
|
-
subscriptions
|
|
26087
|
+
subscriptions.forEach(fn => fn());
|
|
26116
26088
|
unsubWatcher();
|
|
26117
26089
|
}), onTokenTerminated(_ => {
|
|
26118
26090
|
terminateClient();
|
|
26119
|
-
subscriptions
|
|
26091
|
+
subscriptions.forEach(fn => fn());
|
|
26120
26092
|
unsubWatcher();
|
|
26121
26093
|
}), onUserDeleted$2((user) => {
|
|
26122
26094
|
if (user.userId === client.userId) {
|
|
26123
26095
|
terminateClient("userDeleted" /* Amity.TokenTerminationReason.USER_DELETED */);
|
|
26124
|
-
subscriptions
|
|
26096
|
+
subscriptions.forEach(fn => fn());
|
|
26125
26097
|
unsubWatcher();
|
|
26126
26098
|
}
|
|
26127
26099
|
}), onTokenExpired(state => {
|
|
26128
26100
|
SessionWatcher$1.getInstance().setSessionState(state);
|
|
26129
26101
|
logout();
|
|
26130
|
-
subscriptions
|
|
26102
|
+
subscriptions.forEach(fn => fn());
|
|
26131
26103
|
}),
|
|
26132
26104
|
// NOTE: This is a temporary solution to handle the channel marker when the user is forced to leave
|
|
26133
26105
|
// the channel because currently backend can't handle this, so every time a user is banned from
|
|
26134
26106
|
// a channel or the channel is deleted the channel's unread count will not be reset to zero
|
|
26135
26107
|
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler());
|
|
26136
26108
|
if (client.useLegacyUnreadCount) {
|
|
26137
|
-
subscriptions
|
|
26109
|
+
subscriptions.push(readReceiptSyncEngineOnLoginHandler());
|
|
26138
26110
|
}
|
|
26139
26111
|
else
|
|
26140
|
-
subscriptions
|
|
26112
|
+
subscriptions.push(legacyReadReceiptSyncEngineOnLoginHandler());
|
|
26141
26113
|
}
|
|
26142
26114
|
return true;
|
|
26143
26115
|
};
|
|
@@ -27062,176 +27034,6 @@ const secureLogout = async () => {
|
|
|
27062
27034
|
};
|
|
27063
27035
|
/* end_public_function */
|
|
27064
27036
|
|
|
27065
|
-
/*
|
|
27066
|
-
* declared earlier to accomodate case when logging in with a different user
|
|
27067
|
-
* than the one already connected, in which case the existing subscriptions need
|
|
27068
|
-
* to be cleared
|
|
27069
|
-
*/
|
|
27070
|
-
let subscriptions = [];
|
|
27071
|
-
async function runMqtt() {
|
|
27072
|
-
await modifyMqttConnection();
|
|
27073
|
-
}
|
|
27074
|
-
const isSameUserId = (token) => {
|
|
27075
|
-
var _a;
|
|
27076
|
-
const client = getActiveClient();
|
|
27077
|
-
const decoded = jwtDecode(token);
|
|
27078
|
-
return ((_a = decoded === null || decoded === void 0 ? void 0 : decoded.user) === null || _a === void 0 ? void 0 : _a.publicUserId) === client.userId;
|
|
27079
|
-
};
|
|
27080
|
-
const validateAccessToken = async ({ token, userId }) => {
|
|
27081
|
-
const client = getActiveClient();
|
|
27082
|
-
// begin establishing session
|
|
27083
|
-
setSessionState("establishing" /* Amity.SessionStates.ESTABLISHING */);
|
|
27084
|
-
const { data: { users }, } = await client.http.get(`/api/v3/users/${userId}`, {
|
|
27085
|
-
headers: {
|
|
27086
|
-
Authorization: `Bearer ${token.accessToken}`,
|
|
27087
|
-
},
|
|
27088
|
-
});
|
|
27089
|
-
const user = users.find((u) => u.userId === userId);
|
|
27090
|
-
client.http.defaults.headers.common.Authorization = `Bearer ${token.accessToken}`;
|
|
27091
|
-
client.http.defaults.metadata = {
|
|
27092
|
-
tokenExpiry: token.expiresAt,
|
|
27093
|
-
isGlobalBanned: false,
|
|
27094
|
-
isUserDeleted: false,
|
|
27095
|
-
};
|
|
27096
|
-
client.upload.defaults.headers.common.Authorization = `Bearer ${token.accessToken}`;
|
|
27097
|
-
client.upload.defaults.metadata = {
|
|
27098
|
-
tokenExpiry: token.expiresAt,
|
|
27099
|
-
isGlobalBanned: false,
|
|
27100
|
-
isUserDeleted: false,
|
|
27101
|
-
};
|
|
27102
|
-
// manually setup the token for ws transport
|
|
27103
|
-
if (client.ws)
|
|
27104
|
-
client.ws.io.opts.query = { token: token.accessToken };
|
|
27105
|
-
client.token = token;
|
|
27106
|
-
setSessionState("established" /* Amity.SessionStates.ESTABLISHED */);
|
|
27107
|
-
return user;
|
|
27108
|
-
};
|
|
27109
|
-
/* begin_public_function
|
|
27110
|
-
id: client.resumeSession
|
|
27111
|
-
*/
|
|
27112
|
-
/**
|
|
27113
|
-
* ```js
|
|
27114
|
-
* import { resumeSession } from '@amityco/ts-sdk/client/api'
|
|
27115
|
-
* const success = await resumeSession({
|
|
27116
|
-
* userId: 'XYZ123456789',
|
|
27117
|
-
* token: { accessToken: 'abc123', issuedAt: '2023-01-01T00:00:00Z', expiresAt: '2023-01-02T00:00:00Z' }
|
|
27118
|
-
* })
|
|
27119
|
-
* ```
|
|
27120
|
-
*
|
|
27121
|
-
* Connects an {@link Amity.Client} instance to ASC servers using an existing access token
|
|
27122
|
-
*
|
|
27123
|
-
* @param params the connect parameters
|
|
27124
|
-
* @param params.userId the user ID for the current session
|
|
27125
|
-
* @param params.token the existing access token with its metadata
|
|
27126
|
-
* @param sessionHandler the session handler for token renewal
|
|
27127
|
-
* @param config optional configuration
|
|
27128
|
-
* @returns a success boolean if connected
|
|
27129
|
-
*
|
|
27130
|
-
* @category Client API
|
|
27131
|
-
* @async
|
|
27132
|
-
*/
|
|
27133
|
-
const resumeSession = async (params, sessionHandler, config) => {
|
|
27134
|
-
var _a;
|
|
27135
|
-
const client = getActiveClient();
|
|
27136
|
-
let unsubWatcher;
|
|
27137
|
-
client.log('client/api/resumeSession', Object.assign({ apiKey: client.apiKey, sessionState: client.sessionState }, params));
|
|
27138
|
-
// Handle existing connected user
|
|
27139
|
-
if (client.userId) {
|
|
27140
|
-
if (client.userId === params.userId && isSameUserId(params.token.accessToken)) {
|
|
27141
|
-
// Clear connections and listeners but preserve cache
|
|
27142
|
-
if (client.mqtt && client.mqtt.connected) {
|
|
27143
|
-
client.mqtt.disconnect();
|
|
27144
|
-
}
|
|
27145
|
-
if (client.ws && client.ws.connected) {
|
|
27146
|
-
client.ws.disconnect();
|
|
27147
|
-
}
|
|
27148
|
-
// Clear existing subscriptions
|
|
27149
|
-
subscriptions.forEach(fn => fn());
|
|
27150
|
-
subscriptions = [];
|
|
27151
|
-
}
|
|
27152
|
-
else {
|
|
27153
|
-
// Different user - do full logout
|
|
27154
|
-
await logout();
|
|
27155
|
-
// Remove subscription to ban and delete
|
|
27156
|
-
subscriptions.forEach(fn => fn());
|
|
27157
|
-
subscriptions = [];
|
|
27158
|
-
}
|
|
27159
|
-
}
|
|
27160
|
-
try {
|
|
27161
|
-
const user = await validateAccessToken(params);
|
|
27162
|
-
if (user == null) {
|
|
27163
|
-
throw new ASCError(`${params.userId} has not been found`, 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
27164
|
-
}
|
|
27165
|
-
if (user.isDeleted) {
|
|
27166
|
-
terminateClient("userDeleted" /* Amity.TokenTerminationReason.USER_DELETED */);
|
|
27167
|
-
return false;
|
|
27168
|
-
}
|
|
27169
|
-
if (user.isGlobalBanned) {
|
|
27170
|
-
terminateClient("globalBan" /* Amity.TokenTerminationReason.GLOBAL_BAN */);
|
|
27171
|
-
return false;
|
|
27172
|
-
}
|
|
27173
|
-
// FIXME: events are duplicated if connectClient is called few times without disconnectClient
|
|
27174
|
-
// wire websocket events to our event emitter
|
|
27175
|
-
proxyWebsocketEvents(client.ws, client.emitter);
|
|
27176
|
-
(_a = client.ws) === null || _a === void 0 ? void 0 : _a.open();
|
|
27177
|
-
client.userId = user.userId;
|
|
27178
|
-
client.sessionHandler = sessionHandler;
|
|
27179
|
-
/*
|
|
27180
|
-
* Cannot push to subscriptions as watcher needs to continue working even if
|
|
27181
|
-
* token expires
|
|
27182
|
-
*/
|
|
27183
|
-
unsubWatcher = client.accessTokenExpiryWatcher(sessionHandler);
|
|
27184
|
-
setActiveUser(user);
|
|
27185
|
-
}
|
|
27186
|
-
catch (error) {
|
|
27187
|
-
/*
|
|
27188
|
-
* if getting token failed session state reverts to initial state when app
|
|
27189
|
-
* is first launched
|
|
27190
|
-
*/
|
|
27191
|
-
SessionWatcher$1.getInstance().setSessionState("notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */);
|
|
27192
|
-
// pass error down tree so the calling function handle it
|
|
27193
|
-
throw error;
|
|
27194
|
-
}
|
|
27195
|
-
if ((config === null || config === void 0 ? void 0 : config.disableRTE) !== true) {
|
|
27196
|
-
runMqtt();
|
|
27197
|
-
}
|
|
27198
|
-
await initializeMessagePreviewSetting();
|
|
27199
|
-
if (subscriptions.length === 0) {
|
|
27200
|
-
subscriptions.push(
|
|
27201
|
-
// GLOBAL_BAN
|
|
27202
|
-
onClientBanned((_) => {
|
|
27203
|
-
terminateClient("globalBan" /* Amity.TokenTerminationReason.GLOBAL_BAN */);
|
|
27204
|
-
subscriptions.forEach(fn => fn());
|
|
27205
|
-
unsubWatcher();
|
|
27206
|
-
}), onTokenTerminated(_ => {
|
|
27207
|
-
terminateClient();
|
|
27208
|
-
subscriptions.forEach(fn => fn());
|
|
27209
|
-
unsubWatcher();
|
|
27210
|
-
}), onUserDeleted$2((user) => {
|
|
27211
|
-
if (user.userId === client.userId) {
|
|
27212
|
-
terminateClient("userDeleted" /* Amity.TokenTerminationReason.USER_DELETED */);
|
|
27213
|
-
subscriptions.forEach(fn => fn());
|
|
27214
|
-
unsubWatcher();
|
|
27215
|
-
}
|
|
27216
|
-
}), onTokenExpired(state => {
|
|
27217
|
-
SessionWatcher$1.getInstance().setSessionState(state);
|
|
27218
|
-
logout();
|
|
27219
|
-
subscriptions.forEach(fn => fn());
|
|
27220
|
-
}),
|
|
27221
|
-
// NOTE: This is a temporary solution to handle the channel marker when the user is forced to leave
|
|
27222
|
-
// the channel because currently backend can't handle this, so every time a user is banned from
|
|
27223
|
-
// a channel or the channel is deleted the channel's unread count will not be reset to zero
|
|
27224
|
-
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler());
|
|
27225
|
-
if (client.useLegacyUnreadCount) {
|
|
27226
|
-
subscriptions.push(readReceiptSyncEngineOnLoginHandler());
|
|
27227
|
-
}
|
|
27228
|
-
else
|
|
27229
|
-
subscriptions.push(legacyReadReceiptSyncEngineOnLoginHandler());
|
|
27230
|
-
}
|
|
27231
|
-
return true;
|
|
27232
|
-
};
|
|
27233
|
-
/* end_public_function */
|
|
27234
|
-
|
|
27235
27037
|
/**
|
|
27236
27038
|
* ```js
|
|
27237
27039
|
* import { isConnected } from '@amityco/ts-sdk'
|
|
@@ -27637,7 +27439,6 @@ var index$n = /*#__PURE__*/Object.freeze({
|
|
|
27637
27439
|
login: login,
|
|
27638
27440
|
logout: logout,
|
|
27639
27441
|
secureLogout: secureLogout,
|
|
27640
|
-
resumeSession: resumeSession,
|
|
27641
27442
|
isConnected: isConnected,
|
|
27642
27443
|
getFeedSettings: getFeedSettings,
|
|
27643
27444
|
renewal: renewal,
|
|
@@ -35332,8 +35133,7 @@ class ChannelMemberLiveCollectionController extends LiveCollectionController {
|
|
|
35332
35133
|
const data = this.applyFilter((_b = collection.data
|
|
35333
35134
|
.map(id => pullFromCache(['channelUsers', 'get', id]))
|
|
35334
35135
|
.filter(Boolean)
|
|
35335
|
-
.map(({ data }) => data)
|
|
35336
|
-
.map(LinkedObject.channelMember)) !== null && _b !== void 0 ? _b : []);
|
|
35136
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
|
|
35337
35137
|
if (!this.shouldNotify(data) && origin === 'event')
|
|
35338
35138
|
return;
|
|
35339
35139
|
this.callback({
|