@amityco/ts-sdk 6.30.5-b3b15ee.0 → 6.31.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/dist/@types/domains/client.d.ts +1 -0
- package/dist/@types/domains/client.d.ts.map +1 -1
- package/dist/client/api/createClient.d.ts.map +1 -1
- package/dist/core/model/index.d.ts +1 -0
- package/dist/core/model/index.d.ts.map +1 -1
- package/dist/core/model/localReferenceId.d.ts +2 -0
- package/dist/core/model/localReferenceId.d.ts.map +1 -0
- package/dist/index.cjs.js +123 -28
- package/dist/index.esm.js +123 -28
- package/dist/index.umd.js +4 -4
- package/dist/messageRepository/api/createMessage.d.ts.map +1 -1
- package/dist/messageRepository/observers/getMessages/MessageLiveCollectionController.d.ts.map +1 -1
- package/dist/messageRepository/observers/getMessages/MessageQueryStreamController.d.ts.map +1 -1
- package/dist/messageRepository/utils/getMessageFromMainDB.d.ts.map +1 -1
- package/dist/messageRepository/utils/getMessageIdentifierIds.d.ts +2 -0
- package/dist/messageRepository/utils/getMessageIdentifierIds.d.ts.map +1 -0
- package/dist/messageRepository/utils/index.d.ts +1 -0
- 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/domains/client.ts +2 -0
- package/src/client/api/createClient.ts +26 -0
- package/src/core/model/index.ts +1 -0
- package/src/core/model/localReferenceId.ts +12 -0
- package/src/messageRepository/api/createMessage.ts +9 -0
- package/src/messageRepository/observers/getMessages/MessageLiveCollectionController.ts +1 -0
- package/src/messageRepository/observers/getMessages/MessageQueryStreamController.ts +4 -4
- package/src/messageRepository/utils/getMessageFromMainDB.ts +9 -6
- package/src/messageRepository/utils/getMessageIdentifierIds.ts +37 -0
- package/src/messageRepository/utils/index.ts +1 -0
- package/src/messageRepository/utils/prepareMessagePayload.ts +22 -18
- package/src/utils/event.ts +20 -3
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 ''v6.
|
|
91
|
-
return 'v6.
|
|
90
|
+
// the string ''v6.31.0-esm'' should be replaced by actual value by @rollup/plugin-replace
|
|
91
|
+
return 'v6.31.0-esm';
|
|
92
92
|
}
|
|
93
93
|
catch (error) {
|
|
94
94
|
return '__dev__';
|
|
@@ -536,6 +536,18 @@ 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
|
+
|
|
539
551
|
/**
|
|
540
552
|
* A map of v3 response keys to a store name.
|
|
541
553
|
* @hidden
|
|
@@ -22880,21 +22892,26 @@ function convertFromRaw$1(_a) {
|
|
|
22880
22892
|
} }, rest), { channelId: channelPublicId, creatorId: creatorPublicId, displayName: name, lastActivity: lastMessageTimestamp, latestMessageId: lastMessageId, messageCount: childCount, subChannelId: messageFeedId, isUnreadCountSupport: isUnreadCountSupport$1({ channelType }) });
|
|
22881
22893
|
}
|
|
22882
22894
|
|
|
22883
|
-
const
|
|
22884
|
-
|
|
22885
|
-
const
|
|
22886
|
-
|
|
22887
|
-
|
|
22888
|
-
|
|
22889
|
-
|
|
22890
|
-
|
|
22891
|
-
|
|
22892
|
-
|
|
22895
|
+
const addLocalReferenceId = (payload) => {
|
|
22896
|
+
const client = getActiveClient();
|
|
22897
|
+
const { objectSyncMap } = client;
|
|
22898
|
+
return Object.assign(Object.assign({}, payload), {
|
|
22899
|
+
/* NOTE: This logic is used to get local referenceId for each message.
|
|
22900
|
+
*
|
|
22901
|
+
* if messageId is a local reference id, use it as referenceId else get referenceId from objectSyncMap.
|
|
22902
|
+
* if find referenceId in objectSyncMap, this means this message is a local created message. The referenceId will be local reference id.
|
|
22903
|
+
* if cannot find referenceId in objectSyncMap, referenceId will be undefined.
|
|
22904
|
+
*
|
|
22905
|
+
* The referenceId is undefined means this message is not a local created message (optimistic creation message).
|
|
22906
|
+
*/
|
|
22907
|
+
referenceId: isLocalId(payload.messageId)
|
|
22908
|
+
? payload.messageId
|
|
22909
|
+
: objectSyncMap.get(payload.messageId) });
|
|
22893
22910
|
};
|
|
22894
22911
|
function convertFromRaw(message, reactors, event) {
|
|
22895
22912
|
var _a;
|
|
22896
|
-
const
|
|
22897
|
-
const { channelPublicId, childCount, creatorPublicId, mentionedUsers, messageFeedId, myReactions, reactionCount, reactions, referenceId, segment, messageId, creatorId } =
|
|
22913
|
+
const messageWithReferenceId = addLocalReferenceId(message);
|
|
22914
|
+
const { channelPublicId, childCount, creatorPublicId, mentionedUsers, messageFeedId, myReactions, reactionCount, reactions, referenceId, segment, messageId, creatorId } = messageWithReferenceId, rest = __rest(messageWithReferenceId, ["channelPublicId", "childCount", "creatorPublicId", "mentionedUsers", "messageFeedId", "myReactions", "reactionCount", "reactions", "referenceId", "segment", "messageId", "creatorId"]);
|
|
22898
22915
|
let cache;
|
|
22899
22916
|
if (referenceId) {
|
|
22900
22917
|
cache = pullFromCache(['message', 'get', referenceId]);
|
|
@@ -24681,6 +24698,42 @@ const updateSubChannelUnreadFromMessage = (message) => {
|
|
|
24681
24698
|
pushToCache(cacheKeyUnreadCount, updatedCachedUnreadCount);
|
|
24682
24699
|
};
|
|
24683
24700
|
|
|
24701
|
+
/*
|
|
24702
|
+
* To get message identifier ids used as a cache key for the each message.
|
|
24703
|
+
* These ids are used to store in the query stream and use to get messages from cache.
|
|
24704
|
+
*
|
|
24705
|
+
* The query stream data keeps the message identifier ids as follows:
|
|
24706
|
+
* ['server_message_id_1', 'server_message_id_2', 'LOCAL_message_id_1', 'LOCAL_message_id_2']
|
|
24707
|
+
*
|
|
24708
|
+
* Example use case: Message created locally and then created on the server.
|
|
24709
|
+
*
|
|
24710
|
+
* 1. Message created locally has `LOCAL_message_id_2` as referenceId.
|
|
24711
|
+
* 2. The `message.created` event will be fired from server with message payload that has no the referenceId.
|
|
24712
|
+
* 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.
|
|
24713
|
+
* 4. The SDK use this identifier ids to check if the message is already in the query stream before appending it.
|
|
24714
|
+
*
|
|
24715
|
+
* @param The raw message payload from server response
|
|
24716
|
+
* @returns The identifier ids of the messages
|
|
24717
|
+
*/
|
|
24718
|
+
function getMessageIdentifierIds(messages) {
|
|
24719
|
+
const client = getActiveClient();
|
|
24720
|
+
const { objectSyncMap } = client;
|
|
24721
|
+
return messages
|
|
24722
|
+
.map(message => {
|
|
24723
|
+
var _a;
|
|
24724
|
+
/* NOTE: This logic is used to get identifier id for each message.
|
|
24725
|
+
*
|
|
24726
|
+
* if messageId is a local id, use it as identifier id else get identifier id from objectSyncMap.
|
|
24727
|
+
* if find referenceId in objectSyncMap, this means this message is a local created message. The identifier id will be local message id.
|
|
24728
|
+
* 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.
|
|
24729
|
+
*/
|
|
24730
|
+
if (isLocalId(message.messageId))
|
|
24731
|
+
return message.messageId;
|
|
24732
|
+
return (_a = objectSyncMap.get(message.messageId)) !== null && _a !== void 0 ? _a : message.messageId;
|
|
24733
|
+
})
|
|
24734
|
+
.filter(Boolean);
|
|
24735
|
+
}
|
|
24736
|
+
|
|
24684
24737
|
/**
|
|
24685
24738
|
* ```js
|
|
24686
24739
|
* import { onMessageCreated } from '@amityco/ts-sdk'
|
|
@@ -25381,6 +25434,7 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
|
|
|
25381
25434
|
const sessionState = "notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */;
|
|
25382
25435
|
const sessionHandler = undefined;
|
|
25383
25436
|
const isUnreadCountEnabled = false;
|
|
25437
|
+
const objectSyncMap = new Map();
|
|
25384
25438
|
const client = {
|
|
25385
25439
|
version: `${VERSION}`,
|
|
25386
25440
|
apiKey,
|
|
@@ -25411,6 +25465,29 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
|
|
|
25411
25465
|
use: () => setActiveClient(client),
|
|
25412
25466
|
isUnreadCountEnabled,
|
|
25413
25467
|
getMarkerSyncConsistentMode,
|
|
25468
|
+
/*
|
|
25469
|
+
* The objectSyncMap is used to keep the map between local referenceId and server id in two ways mapping.
|
|
25470
|
+
*
|
|
25471
|
+
* 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.
|
|
25472
|
+
* 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.
|
|
25473
|
+
*
|
|
25474
|
+
* 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.
|
|
25475
|
+
*
|
|
25476
|
+
* Example:
|
|
25477
|
+
* In the case of message optimistically creation. The referenceId is created locally.
|
|
25478
|
+
*
|
|
25479
|
+
* 1. When creating a message optimistically, a local referenceId is created. The objectSyncMap will have the following structure.
|
|
25480
|
+
* {
|
|
25481
|
+
* "LOCAL_uuid": undefined,
|
|
25482
|
+
* }
|
|
25483
|
+
*
|
|
25484
|
+
* 2. After the message was created on the server and SDK received the response from server, the objectSyncMap will be updated to
|
|
25485
|
+
* {
|
|
25486
|
+
* "LOCAL_uuid": "server_message_id",
|
|
25487
|
+
* "server_message_id": "LOCAL_uuid"
|
|
25488
|
+
* }
|
|
25489
|
+
*/
|
|
25490
|
+
objectSyncMap,
|
|
25414
25491
|
};
|
|
25415
25492
|
try {
|
|
25416
25493
|
const activeClient = getActiveClient();
|
|
@@ -30990,12 +31067,24 @@ const unmuteChannel = async (channelId) => {
|
|
|
30990
31067
|
/* end_public_function */
|
|
30991
31068
|
|
|
30992
31069
|
const convertEventPayload = (eventHandler, sourceModelProp, destinationDomain) => (callback) => eventHandler(sourceModel => {
|
|
30993
|
-
var _a;
|
|
31070
|
+
var _a, _b;
|
|
30994
31071
|
if (!sourceModel) {
|
|
30995
31072
|
return sourceModel;
|
|
30996
31073
|
}
|
|
30997
|
-
const
|
|
30998
|
-
const
|
|
31074
|
+
const client = getActiveClient();
|
|
31075
|
+
const { objectSyncMap } = client;
|
|
31076
|
+
/*
|
|
31077
|
+
* 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.
|
|
31078
|
+
* 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.
|
|
31079
|
+
*/
|
|
31080
|
+
const resolvedId = isLocalId(sourceModel[sourceModelProp])
|
|
31081
|
+
? sourceModel[sourceModelProp]
|
|
31082
|
+
: (_a = objectSyncMap.get(sourceModel[sourceModelProp])) !== null && _a !== void 0 ? _a : sourceModel[sourceModelProp];
|
|
31083
|
+
const model = (_b = pullFromCache([
|
|
31084
|
+
destinationDomain,
|
|
31085
|
+
'get',
|
|
31086
|
+
`${resolvedId}`,
|
|
31087
|
+
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
30999
31088
|
if (!model)
|
|
31000
31089
|
return;
|
|
31001
31090
|
return callback(model);
|
|
@@ -31423,6 +31512,7 @@ let uniqueId;
|
|
|
31423
31512
|
const createMessageOptimistic = (bundle) => {
|
|
31424
31513
|
var _a, _b;
|
|
31425
31514
|
const client = getActiveClient();
|
|
31515
|
+
const { objectSyncMap } = client;
|
|
31426
31516
|
if (!client.cache)
|
|
31427
31517
|
return;
|
|
31428
31518
|
/*
|
|
@@ -31451,6 +31541,7 @@ const createMessageOptimistic = (bundle) => {
|
|
|
31451
31541
|
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);
|
|
31452
31542
|
const cachedAt = UNSYNCED_OBJECT_CACHED_AT_VALUE;
|
|
31453
31543
|
pushToCache(['message', 'get', message.messageId], message, { cachedAt });
|
|
31544
|
+
objectSyncMap.set(message.messageId, undefined);
|
|
31454
31545
|
fireEvent('local.message.created', { messages: [message] });
|
|
31455
31546
|
return message;
|
|
31456
31547
|
};
|
|
@@ -31478,12 +31569,15 @@ const createMessageOptimistic = (bundle) => {
|
|
|
31478
31569
|
*/
|
|
31479
31570
|
const createMessage = async (bundle) => {
|
|
31480
31571
|
const client = getActiveClient();
|
|
31572
|
+
const { objectSyncMap } = client;
|
|
31481
31573
|
client.log('message/createMessage', bundle);
|
|
31482
31574
|
const optimisticData = createMessageOptimistic(bundle);
|
|
31483
31575
|
const referenceId = bundle.referenceId || uniqueId || getLocalId();
|
|
31484
31576
|
uniqueId = undefined;
|
|
31485
31577
|
try {
|
|
31486
31578
|
const { data: payload } = await client.http.post('/api/v5/messages', Object.assign(Object.assign({}, convertParams(bundle)), { referenceId }));
|
|
31579
|
+
objectSyncMap.set(referenceId, payload.messages[0].messageId);
|
|
31580
|
+
objectSyncMap.set(payload.messages[0].messageId, referenceId);
|
|
31487
31581
|
const data = await prepareMessagePayload(payload);
|
|
31488
31582
|
const { messages } = data;
|
|
31489
31583
|
const cachedAt = client.cache && Date.now();
|
|
@@ -32238,7 +32332,7 @@ class MessageQueryStreamController extends QueryStreamController {
|
|
|
32238
32332
|
var _a, _b;
|
|
32239
32333
|
if (refresh) {
|
|
32240
32334
|
pushToCache(this.cacheKey, {
|
|
32241
|
-
data: response.messages
|
|
32335
|
+
data: getMessageIdentifierIds(response.messages),
|
|
32242
32336
|
query: this.query,
|
|
32243
32337
|
});
|
|
32244
32338
|
}
|
|
@@ -32246,8 +32340,8 @@ class MessageQueryStreamController extends QueryStreamController {
|
|
|
32246
32340
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
32247
32341
|
const messages = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
32248
32342
|
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: direction === 'next'
|
|
32249
|
-
? [...new Set([...messages, ...response.messages
|
|
32250
|
-
: [...new Set([...response.messages
|
|
32343
|
+
? [...new Set([...messages, ...getMessageIdentifierIds(response.messages)])]
|
|
32344
|
+
: [...new Set([...getMessageIdentifierIds(response.messages), ...messages])] }));
|
|
32251
32345
|
}
|
|
32252
32346
|
}
|
|
32253
32347
|
reactor(action) {
|
|
@@ -32321,12 +32415,12 @@ class MessagePaginationController extends PaginationController {
|
|
|
32321
32415
|
|
|
32322
32416
|
const getMessageFromMainDB = (messageId) => {
|
|
32323
32417
|
var _a, _b;
|
|
32324
|
-
const
|
|
32325
|
-
|
|
32326
|
-
|
|
32327
|
-
|
|
32328
|
-
|
|
32329
|
-
return (_b =
|
|
32418
|
+
const client = getActiveClient();
|
|
32419
|
+
const { objectSyncMap } = client;
|
|
32420
|
+
const resolvedMessageId = isLocalId(messageId)
|
|
32421
|
+
? messageId
|
|
32422
|
+
: (_a = objectSyncMap.get(messageId)) !== null && _a !== void 0 ? _a : messageId;
|
|
32423
|
+
return (_b = pullFromCache(['message', 'get', resolvedMessageId])) === null || _b === void 0 ? void 0 : _b.data;
|
|
32330
32424
|
};
|
|
32331
32425
|
|
|
32332
32426
|
class MessageLiveCollectionController extends LiveCollectionController {
|
|
@@ -32666,7 +32760,8 @@ var index$g = /*#__PURE__*/Object.freeze({
|
|
|
32666
32760
|
convertFromRaw: convertFromRaw,
|
|
32667
32761
|
prepareMessagePayload: prepareMessagePayload,
|
|
32668
32762
|
convertParams: convertParams,
|
|
32669
|
-
convertQueryParams: convertQueryParams$1
|
|
32763
|
+
convertQueryParams: convertQueryParams$1,
|
|
32764
|
+
getMessageIdentifierIds: getMessageIdentifierIds
|
|
32670
32765
|
});
|
|
32671
32766
|
|
|
32672
32767
|
/**
|
|
@@ -40727,7 +40822,7 @@ var index$3 = /*#__PURE__*/Object.freeze({
|
|
|
40727
40822
|
getPoll: getPoll
|
|
40728
40823
|
});
|
|
40729
40824
|
|
|
40730
|
-
const privateKey = "-----BEGIN PRIVATE KEY-----\
|
|
40825
|
+
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-----";
|
|
40731
40826
|
/*
|
|
40732
40827
|
* The crypto algorithm used for importing key and signing string
|
|
40733
40828
|
*/
|