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