@amityco/ts-sdk 7.0.1-fbbf78f.0 → 7.0.2-3f56a68.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/core/linkPreview.d.ts +12 -0
- package/dist/@types/core/linkPreview.d.ts.map +1 -0
- package/dist/@types/domains/client.d.ts +0 -1
- package/dist/@types/domains/client.d.ts.map +1 -1
- package/dist/analytic/service/analytic/AnalyticsEventCapturer.d.ts.map +1 -1
- package/dist/client/api/createClient.d.ts.map +1 -1
- package/dist/client/api/fetchLinkPreview.d.ts +14 -0
- package/dist/client/api/fetchLinkPreview.d.ts.map +1 -0
- package/dist/client/api/index.d.ts +1 -0
- package/dist/client/api/index.d.ts.map +1 -1
- package/dist/core/model/index.d.ts +0 -1
- package/dist/core/model/index.d.ts.map +1 -1
- package/dist/index.cjs.js +56 -128
- package/dist/index.esm.js +56 -128
- package/dist/index.umd.js +4 -4
- package/dist/messageRepository/api/createMessage.d.ts.map +1 -1
- package/dist/messageRepository/utils/getMessageFromMainDB.d.ts.map +1 -1
- package/dist/messageRepository/utils/index.d.ts +0 -1
- package/dist/messageRepository/utils/index.d.ts.map +1 -1
- package/dist/messageRepository/utils/prepareMessagePayload.d.ts.map +1 -1
- package/dist/utils/event.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/@types/core/linkPreview.ts +12 -0
- package/src/@types/domains/client.ts +0 -2
- package/src/analytic/service/analytic/AnalyticsEventCapturer.ts +9 -6
- package/src/client/api/createClient.ts +0 -26
- package/src/client/api/fetchLinkPreview.ts +30 -0
- package/src/client/api/index.ts +2 -0
- package/src/core/model/index.ts +0 -1
- package/src/messageRepository/api/createMessage.ts +0 -7
- package/src/messageRepository/observers/getMessages/MessageQueryStreamController.ts +4 -4
- package/src/messageRepository/utils/getMessageFromMainDB.ts +5 -9
- package/src/messageRepository/utils/index.ts +0 -1
- package/src/messageRepository/utils/prepareMessagePayload.ts +17 -22
- package/src/utils/event.ts +2 -19
- package/dist/core/model/localReferenceId.d.ts +0 -2
- package/dist/core/model/localReferenceId.d.ts.map +0 -1
- package/dist/messageRepository/utils/getMessageIdentifierIds.d.ts +0 -2
- package/dist/messageRepository/utils/getMessageIdentifierIds.d.ts.map +0 -1
- package/src/core/model/localReferenceId.ts +0 -12
- package/src/messageRepository/utils/getMessageIdentifierIds.ts +0 -37
package/dist/index.esm.js
CHANGED
|
@@ -87,8 +87,8 @@ const PostContentType = Object.freeze({
|
|
|
87
87
|
|
|
88
88
|
function getVersion() {
|
|
89
89
|
try {
|
|
90
|
-
// the string ''v7.0.
|
|
91
|
-
return 'v7.0.
|
|
90
|
+
// the string ''v7.0.1-esm'' should be replaced by actual value by @rollup/plugin-replace
|
|
91
|
+
return 'v7.0.1-esm';
|
|
92
92
|
}
|
|
93
93
|
catch (error) {
|
|
94
94
|
return '__dev__';
|
|
@@ -536,18 +536,6 @@ const idResolvers = {
|
|
|
536
536
|
*/
|
|
537
537
|
const getResolver = (name) => idResolvers[name];
|
|
538
538
|
|
|
539
|
-
/*
|
|
540
|
-
* To check if an id is a local referenceId, the id must start with 'LOCAL_'.
|
|
541
|
-
*
|
|
542
|
-
* Example: LOCAL_155f5158-281a-4a9d-a445-9243138d2041
|
|
543
|
-
*
|
|
544
|
-
* @param id as string
|
|
545
|
-
* @returns true if the id is a local referenceId, false otherwise
|
|
546
|
-
*/
|
|
547
|
-
const isLocalId = (id) => {
|
|
548
|
-
return id.startsWith('LOCAL_');
|
|
549
|
-
};
|
|
550
|
-
|
|
551
539
|
/**
|
|
552
540
|
* A map of v3 response keys to a store name.
|
|
553
541
|
* @hidden
|
|
@@ -21054,12 +21042,14 @@ class AnalyticsEventCapturer {
|
|
|
21054
21042
|
}
|
|
21055
21043
|
isAbleToEnqueue({ uniqueId, expireTime, isHighPriority = false, }) {
|
|
21056
21044
|
const now = new Date();
|
|
21057
|
-
|
|
21058
|
-
|
|
21059
|
-
|
|
21060
|
-
|
|
21061
|
-
|
|
21062
|
-
|
|
21045
|
+
// Get the recent view date (if any)
|
|
21046
|
+
const recentViewedDate = isHighPriority
|
|
21047
|
+
? this._recentHighPriorityViewed[uniqueId]
|
|
21048
|
+
: this._recentViewed[uniqueId];
|
|
21049
|
+
// If this is the first view, always allow it
|
|
21050
|
+
if (!recentViewedDate) {
|
|
21051
|
+
return true;
|
|
21052
|
+
}
|
|
21063
21053
|
const timeDiff = now.getTime() - recentViewedDate.getTime();
|
|
21064
21054
|
if (timeDiff < expireTime) {
|
|
21065
21055
|
// just recently view this post, ignore the event.
|
|
@@ -22509,26 +22499,20 @@ function convertFromRaw$2(_a) {
|
|
|
22509
22499
|
} }, rest), { channelId: channelPublicId, creatorId: creatorPublicId, displayName: name, lastActivity: lastMessageTimestamp, latestMessageId: lastMessageId, messageCount: childCount, subChannelId: messageFeedId, isUnreadCountSupport: isUnreadCountSupport$2({ channelType }) });
|
|
22510
22500
|
}
|
|
22511
22501
|
|
|
22512
|
-
const
|
|
22513
|
-
|
|
22514
|
-
const {
|
|
22515
|
-
|
|
22516
|
-
|
|
22517
|
-
|
|
22518
|
-
|
|
22519
|
-
|
|
22520
|
-
|
|
22521
|
-
*
|
|
22522
|
-
* The referenceId is undefined means this message is not a local created message (optimistic creation message).
|
|
22523
|
-
*/
|
|
22524
|
-
referenceId: isLocalId(payload.messageId)
|
|
22525
|
-
? payload.messageId
|
|
22526
|
-
: objectSyncMap.get(payload.messageId) });
|
|
22502
|
+
const mergePayloadWithLocal = (payload) => {
|
|
22503
|
+
var _a, _b, _c;
|
|
22504
|
+
const localMessage = (_b = (_a = queryCache(['message', 'get'])) === null || _a === void 0 ? void 0 : _a.find(({ data }) => data.messageId === payload.messageId)) === null || _b === void 0 ? void 0 : _b.data;
|
|
22505
|
+
if (localMessage) {
|
|
22506
|
+
return Object.assign(Object.assign(Object.assign({}, localMessage), payload), {
|
|
22507
|
+
// NOTE: referenceId is missing in the some payload event. If we have local message data with referenceId, use it instead.
|
|
22508
|
+
referenceId: (_c = localMessage.referenceId) !== null && _c !== void 0 ? _c : payload.referenceId });
|
|
22509
|
+
}
|
|
22510
|
+
return payload;
|
|
22527
22511
|
};
|
|
22528
22512
|
function convertFromRaw$1(message, reactors, event) {
|
|
22529
22513
|
var _a;
|
|
22530
|
-
const
|
|
22531
|
-
const { channelPublicId, childCount, creatorPublicId, mentionedUsers, messageFeedId, myReactions, reactionCount, reactions, referenceId, segment, messageId, creatorId } =
|
|
22514
|
+
const mergeMessage = mergePayloadWithLocal(message);
|
|
22515
|
+
const { channelPublicId, childCount, creatorPublicId, mentionedUsers, messageFeedId, myReactions, reactionCount, reactions, referenceId, segment, messageId, creatorId } = mergeMessage, rest = __rest(mergeMessage, ["channelPublicId", "childCount", "creatorPublicId", "mentionedUsers", "messageFeedId", "myReactions", "reactionCount", "reactions", "referenceId", "segment", "messageId", "creatorId"]);
|
|
22532
22516
|
let cache;
|
|
22533
22517
|
if (referenceId) {
|
|
22534
22518
|
cache = pullFromCache(['message', 'get', referenceId]);
|
|
@@ -24686,42 +24670,6 @@ const updateSubChannelUnreadFromMessage = (message) => {
|
|
|
24686
24670
|
pushToCache(cacheKeyUnreadCount, updatedCachedUnreadCount);
|
|
24687
24671
|
};
|
|
24688
24672
|
|
|
24689
|
-
/*
|
|
24690
|
-
* To get message identifier ids used as a cache key for the each message.
|
|
24691
|
-
* These ids are used to store in the query stream and use to get messages from cache.
|
|
24692
|
-
*
|
|
24693
|
-
* The query stream data keeps the message identifier ids as follows:
|
|
24694
|
-
* ['server_message_id_1', 'server_message_id_2', 'LOCAL_message_id_1', 'LOCAL_message_id_2']
|
|
24695
|
-
*
|
|
24696
|
-
* Example use case: Message created locally and then created on the server.
|
|
24697
|
-
*
|
|
24698
|
-
* 1. Message created locally has `LOCAL_message_id_2` as referenceId.
|
|
24699
|
-
* 2. The `message.created` event will be fired from server with message payload that has no the referenceId.
|
|
24700
|
-
* 3. SDK use this function to find indentifer id for each message in the payload. If the message is created locally, the identifier id will be the local reference id.
|
|
24701
|
-
* 4. The SDK use this identifier ids to check if the message is already in the query stream before appending it.
|
|
24702
|
-
*
|
|
24703
|
-
* @param The raw message payload from server response
|
|
24704
|
-
* @returns The identifier ids of the messages
|
|
24705
|
-
*/
|
|
24706
|
-
function getMessageIdentifierIds(messages) {
|
|
24707
|
-
const client = getActiveClient();
|
|
24708
|
-
const { objectSyncMap } = client;
|
|
24709
|
-
return messages
|
|
24710
|
-
.map(message => {
|
|
24711
|
-
var _a;
|
|
24712
|
-
/* NOTE: This logic is used to get identifier id for each message.
|
|
24713
|
-
*
|
|
24714
|
-
* if messageId is a local id, use it as identifier id else get identifier id from objectSyncMap.
|
|
24715
|
-
* if find referenceId in objectSyncMap, this means this message is a local created message. The identifier id will be local message id.
|
|
24716
|
-
* if cannot find identifier id in objectSyncMap, this means this message is not a local created message. The identifier id will be server message id.
|
|
24717
|
-
*/
|
|
24718
|
-
if (isLocalId(message.messageId))
|
|
24719
|
-
return message.messageId;
|
|
24720
|
-
return (_a = objectSyncMap.get(message.messageId)) !== null && _a !== void 0 ? _a : message.messageId;
|
|
24721
|
-
})
|
|
24722
|
-
.filter(Boolean);
|
|
24723
|
-
}
|
|
24724
|
-
|
|
24725
24673
|
/**
|
|
24726
24674
|
* ```js
|
|
24727
24675
|
* import { onMessageCreated } from '@amityco/ts-sdk'
|
|
@@ -25421,7 +25369,6 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
|
|
|
25421
25369
|
const sessionState = "notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */;
|
|
25422
25370
|
const sessionHandler = undefined;
|
|
25423
25371
|
const isUnreadCountEnabled = false;
|
|
25424
|
-
const objectSyncMap = new Map();
|
|
25425
25372
|
const client = {
|
|
25426
25373
|
version: `${VERSION}`,
|
|
25427
25374
|
apiKey,
|
|
@@ -25457,29 +25404,6 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
|
|
|
25457
25404
|
* This is allow user to have multiple SDK client and Mqtt client within the same app.
|
|
25458
25405
|
*/
|
|
25459
25406
|
prefixDeviceIdKey,
|
|
25460
|
-
/*
|
|
25461
|
-
* The objectSyncMap is used to keep the map between local referenceId and server id in two ways mapping.
|
|
25462
|
-
*
|
|
25463
|
-
* For objects created locally (optimistic creation), the SDK stores them with their local ID as the cache key, which is used throughout the entire SDK session (in-memory) for syncing updates.
|
|
25464
|
-
* If the payload or response only contains the remote ID of the same object, the SDK will look up the corresponding local ID to retrieve the object through ObjectSyncMap.
|
|
25465
|
-
*
|
|
25466
|
-
* This is useful for syncing updates to the object, as the SDK can find the local ID from the server ID and update the object in the cache correctly.
|
|
25467
|
-
*
|
|
25468
|
-
* Example:
|
|
25469
|
-
* In the case of message optimistically creation. The referenceId is created locally.
|
|
25470
|
-
*
|
|
25471
|
-
* 1. When creating a message optimistically, a local referenceId is created. The objectSyncMap will have the following structure.
|
|
25472
|
-
* {
|
|
25473
|
-
* "LOCAL_uuid": undefined,
|
|
25474
|
-
* }
|
|
25475
|
-
*
|
|
25476
|
-
* 2. After the message was created on the server and SDK received the response from server, the objectSyncMap will be updated to
|
|
25477
|
-
* {
|
|
25478
|
-
* "LOCAL_uuid": "server_message_id",
|
|
25479
|
-
* "server_message_id": "LOCAL_uuid"
|
|
25480
|
-
* }
|
|
25481
|
-
*/
|
|
25482
|
-
objectSyncMap,
|
|
25483
25407
|
};
|
|
25484
25408
|
try {
|
|
25485
25409
|
const activeClient = getActiveClient();
|
|
@@ -25570,6 +25494,28 @@ function setUploadedFileAccessType(accessType) {
|
|
|
25570
25494
|
GlobalFileAccessType$1.getInstance().setFileAccessType(accessType);
|
|
25571
25495
|
}
|
|
25572
25496
|
|
|
25497
|
+
/**
|
|
25498
|
+
* ```js
|
|
25499
|
+
* import { fetchLinkPreview } from '@amityco/ts-sdk'
|
|
25500
|
+
* const { title, description, imageUrl } = fetchLinkPreview('https://www.example.com/')
|
|
25501
|
+
* ```
|
|
25502
|
+
*
|
|
25503
|
+
*
|
|
25504
|
+
* @param url the url to fetch link preview
|
|
25505
|
+
* @returns A {@link Amity.LinkPreview} instance
|
|
25506
|
+
*
|
|
25507
|
+
* @category Client API
|
|
25508
|
+
* */
|
|
25509
|
+
const fetchLinkPreview = async (url) => {
|
|
25510
|
+
const client = getActiveClient();
|
|
25511
|
+
let fetchUrl = url;
|
|
25512
|
+
if (!/^https?:\/\//i.test(url)) {
|
|
25513
|
+
fetchUrl = `https://${url}`;
|
|
25514
|
+
}
|
|
25515
|
+
const { data } = await client.http.get(`/api/v1/link-preview?url=${encodeURIComponent(fetchUrl)}`);
|
|
25516
|
+
return data;
|
|
25517
|
+
};
|
|
25518
|
+
|
|
25573
25519
|
/**
|
|
25574
25520
|
* ```js
|
|
25575
25521
|
* import { onChannelMarkerFetched } from '@amityco/ts-sdk'
|
|
@@ -25937,6 +25883,7 @@ var index$l = /*#__PURE__*/Object.freeze({
|
|
|
25937
25883
|
markerSync: markerSync,
|
|
25938
25884
|
enableUnreadCount: enableUnreadCount,
|
|
25939
25885
|
setUploadedFileAccessType: setUploadedFileAccessType,
|
|
25886
|
+
fetchLinkPreview: fetchLinkPreview,
|
|
25940
25887
|
onConnectionError: onConnectionError,
|
|
25941
25888
|
onClientDisconnected: onClientDisconnected,
|
|
25942
25889
|
onClientBanned: onClientBanned,
|
|
@@ -27766,24 +27713,12 @@ function prepareBlockedUserPayload(response) {
|
|
|
27766
27713
|
}
|
|
27767
27714
|
|
|
27768
27715
|
const convertEventPayload = (eventHandler, sourceModelProp, destinationDomain) => (callback) => eventHandler(sourceModel => {
|
|
27769
|
-
var _a
|
|
27716
|
+
var _a;
|
|
27770
27717
|
if (!sourceModel) {
|
|
27771
27718
|
return sourceModel;
|
|
27772
27719
|
}
|
|
27773
|
-
const
|
|
27774
|
-
const
|
|
27775
|
-
/*
|
|
27776
|
-
* NOTE: For objects created locally (optimistic creation), the SDK stores them with their local ID as the cache key, which is used throughout the entire SDK session (in-memory) for syncing updates.
|
|
27777
|
-
* If the payload or response only contains the remote ID of the same object, the SDK will look up the corresponding local ID to retrieve the object.
|
|
27778
|
-
*/
|
|
27779
|
-
const resolvedId = isLocalId(sourceModel[sourceModelProp])
|
|
27780
|
-
? sourceModel[sourceModelProp]
|
|
27781
|
-
: (_a = objectSyncMap.get(sourceModel[sourceModelProp])) !== null && _a !== void 0 ? _a : sourceModel[sourceModelProp];
|
|
27782
|
-
const model = (_b = pullFromCache([
|
|
27783
|
-
destinationDomain,
|
|
27784
|
-
'get',
|
|
27785
|
-
`${resolvedId}`,
|
|
27786
|
-
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
27720
|
+
const cacheKey = [destinationDomain, 'get', `${sourceModel[sourceModelProp]}`];
|
|
27721
|
+
const model = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27787
27722
|
if (!model)
|
|
27788
27723
|
return;
|
|
27789
27724
|
return callback(model);
|
|
@@ -31011,7 +30946,6 @@ let uniqueId;
|
|
|
31011
30946
|
const createMessageOptimistic = (bundle) => {
|
|
31012
30947
|
var _a, _b;
|
|
31013
30948
|
const client = getActiveClient();
|
|
31014
|
-
const { objectSyncMap } = client;
|
|
31015
30949
|
if (!client.cache)
|
|
31016
30950
|
return;
|
|
31017
30951
|
/*
|
|
@@ -31044,7 +30978,6 @@ const createMessageOptimistic = (bundle) => {
|
|
|
31044
30978
|
const message = Object.assign({ creatorId: client.userId, creatorPrivateId: getActiveUser()._id, channelSegment: ((_b = subChannel === null || subChannel === void 0 ? void 0 : subChannel.data.messageCount) !== null && _b !== void 0 ? _b : 0) + 1, childrenNumber: 0, createdAt: createdTime, updatedAt: createdTime, syncState: "syncing" /* Amity.SyncState.Syncing */, isDeleted: false }, bundleWithMessageId);
|
|
31045
30979
|
const cachedAt = UNSYNCED_OBJECT_CACHED_AT_VALUE;
|
|
31046
30980
|
pushToCache(['message', 'get', message.messageId], message, { cachedAt });
|
|
31047
|
-
objectSyncMap.set(message.messageId, undefined);
|
|
31048
30981
|
fireEvent('local.message.created', { messages: [message] });
|
|
31049
30982
|
return message;
|
|
31050
30983
|
};
|
|
@@ -31072,15 +31005,12 @@ const createMessageOptimistic = (bundle) => {
|
|
|
31072
31005
|
*/
|
|
31073
31006
|
const createMessage = async (bundle) => {
|
|
31074
31007
|
const client = getActiveClient();
|
|
31075
|
-
const { objectSyncMap } = client;
|
|
31076
31008
|
client.log('message/createMessage', bundle);
|
|
31077
31009
|
const optimisticData = createMessageOptimistic(bundle);
|
|
31078
31010
|
const referenceId = bundle.referenceId || uniqueId || getLocalId();
|
|
31079
31011
|
uniqueId = undefined;
|
|
31080
31012
|
try {
|
|
31081
31013
|
const { data: payload } = await client.http.post('/api/v5/messages', Object.assign(Object.assign({}, convertParams(bundle)), { referenceId }));
|
|
31082
|
-
objectSyncMap.set(referenceId, payload.messages[0].messageId);
|
|
31083
|
-
objectSyncMap.set(payload.messages[0].messageId, referenceId);
|
|
31084
31014
|
const data = await prepareMessagePayload(payload);
|
|
31085
31015
|
const { messages } = data;
|
|
31086
31016
|
const cachedAt = client.cache && Date.now();
|
|
@@ -31835,7 +31765,7 @@ class MessageQueryStreamController extends QueryStreamController {
|
|
|
31835
31765
|
var _a, _b;
|
|
31836
31766
|
if (refresh) {
|
|
31837
31767
|
pushToCache(this.cacheKey, {
|
|
31838
|
-
data:
|
|
31768
|
+
data: response.messages.map(getResolver('message')),
|
|
31839
31769
|
query: this.query,
|
|
31840
31770
|
});
|
|
31841
31771
|
}
|
|
@@ -31843,8 +31773,8 @@ class MessageQueryStreamController extends QueryStreamController {
|
|
|
31843
31773
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
31844
31774
|
const messages = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
31845
31775
|
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: direction === 'next'
|
|
31846
|
-
? [...new Set([...messages, ...
|
|
31847
|
-
: [...new Set([...
|
|
31776
|
+
? [...new Set([...messages, ...response.messages.map(getResolver('message'))])]
|
|
31777
|
+
: [...new Set([...response.messages.map(getResolver('message')), ...messages])] }));
|
|
31848
31778
|
}
|
|
31849
31779
|
}
|
|
31850
31780
|
reactor(action) {
|
|
@@ -31911,12 +31841,11 @@ class MessagePaginationController extends PaginationController {
|
|
|
31911
31841
|
|
|
31912
31842
|
const getMessageFromMainDB = (messageId) => {
|
|
31913
31843
|
var _a, _b;
|
|
31914
|
-
const
|
|
31915
|
-
|
|
31916
|
-
|
|
31917
|
-
|
|
31918
|
-
|
|
31919
|
-
return (_b = pullFromCache(['message', 'get', resolvedMessageId])) === null || _b === void 0 ? void 0 : _b.data;
|
|
31844
|
+
const message = (_a = pullFromCache(['message', 'get', messageId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
31845
|
+
if (message)
|
|
31846
|
+
return message;
|
|
31847
|
+
const messages = queryCache(['message', 'get']);
|
|
31848
|
+
return (_b = messages === null || messages === void 0 ? void 0 : messages.find(({ data }) => data.messageId === messageId)) === null || _b === void 0 ? void 0 : _b.data;
|
|
31920
31849
|
};
|
|
31921
31850
|
|
|
31922
31851
|
class MessageLiveCollectionController extends LiveCollectionController {
|
|
@@ -32077,8 +32006,7 @@ var index$g = /*#__PURE__*/Object.freeze({
|
|
|
32077
32006
|
convertFromRaw: convertFromRaw$1,
|
|
32078
32007
|
prepareMessagePayload: prepareMessagePayload,
|
|
32079
32008
|
convertParams: convertParams,
|
|
32080
|
-
convertQueryParams: convertQueryParams$1
|
|
32081
|
-
getMessageIdentifierIds: getMessageIdentifierIds
|
|
32009
|
+
convertQueryParams: convertQueryParams$1
|
|
32082
32010
|
});
|
|
32083
32011
|
|
|
32084
32012
|
/**
|