@amityco/ts-sdk 7.0.1-7547014.0 → 7.0.1
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 +0 -1
- 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 +0 -1
- package/dist/core/model/index.d.ts.map +1 -1
- package/dist/index.cjs.js +26 -123
- package/dist/index.esm.js +26 -123
- 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/domains/client.ts +0 -2
- package/src/client/api/createClient.ts +0 -26
- 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
|
|
@@ -22509,26 +22497,20 @@ function convertFromRaw$2(_a) {
|
|
|
22509
22497
|
} }, rest), { channelId: channelPublicId, creatorId: creatorPublicId, displayName: name, lastActivity: lastMessageTimestamp, latestMessageId: lastMessageId, messageCount: childCount, subChannelId: messageFeedId, isUnreadCountSupport: isUnreadCountSupport$2({ channelType }) });
|
|
22510
22498
|
}
|
|
22511
22499
|
|
|
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) });
|
|
22500
|
+
const mergePayloadWithLocal = (payload) => {
|
|
22501
|
+
var _a, _b, _c;
|
|
22502
|
+
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;
|
|
22503
|
+
if (localMessage) {
|
|
22504
|
+
return Object.assign(Object.assign(Object.assign({}, localMessage), payload), {
|
|
22505
|
+
// NOTE: referenceId is missing in the some payload event. If we have local message data with referenceId, use it instead.
|
|
22506
|
+
referenceId: (_c = localMessage.referenceId) !== null && _c !== void 0 ? _c : payload.referenceId });
|
|
22507
|
+
}
|
|
22508
|
+
return payload;
|
|
22527
22509
|
};
|
|
22528
22510
|
function convertFromRaw$1(message, reactors, event) {
|
|
22529
22511
|
var _a;
|
|
22530
|
-
const
|
|
22531
|
-
const { channelPublicId, childCount, creatorPublicId, mentionedUsers, messageFeedId, myReactions, reactionCount, reactions, referenceId, segment, messageId, creatorId } =
|
|
22512
|
+
const mergeMessage = mergePayloadWithLocal(message);
|
|
22513
|
+
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
22514
|
let cache;
|
|
22533
22515
|
if (referenceId) {
|
|
22534
22516
|
cache = pullFromCache(['message', 'get', referenceId]);
|
|
@@ -24686,42 +24668,6 @@ const updateSubChannelUnreadFromMessage = (message) => {
|
|
|
24686
24668
|
pushToCache(cacheKeyUnreadCount, updatedCachedUnreadCount);
|
|
24687
24669
|
};
|
|
24688
24670
|
|
|
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
24671
|
/**
|
|
24726
24672
|
* ```js
|
|
24727
24673
|
* import { onMessageCreated } from '@amityco/ts-sdk'
|
|
@@ -25421,7 +25367,6 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
|
|
|
25421
25367
|
const sessionState = "notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */;
|
|
25422
25368
|
const sessionHandler = undefined;
|
|
25423
25369
|
const isUnreadCountEnabled = false;
|
|
25424
|
-
const objectSyncMap = new Map();
|
|
25425
25370
|
const client = {
|
|
25426
25371
|
version: `${VERSION}`,
|
|
25427
25372
|
apiKey,
|
|
@@ -25457,29 +25402,6 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
|
|
|
25457
25402
|
* This is allow user to have multiple SDK client and Mqtt client within the same app.
|
|
25458
25403
|
*/
|
|
25459
25404
|
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
25405
|
};
|
|
25484
25406
|
try {
|
|
25485
25407
|
const activeClient = getActiveClient();
|
|
@@ -27789,24 +27711,12 @@ function prepareBlockedUserPayload(response) {
|
|
|
27789
27711
|
}
|
|
27790
27712
|
|
|
27791
27713
|
const convertEventPayload = (eventHandler, sourceModelProp, destinationDomain) => (callback) => eventHandler(sourceModel => {
|
|
27792
|
-
var _a
|
|
27714
|
+
var _a;
|
|
27793
27715
|
if (!sourceModel) {
|
|
27794
27716
|
return sourceModel;
|
|
27795
27717
|
}
|
|
27796
|
-
const
|
|
27797
|
-
const
|
|
27798
|
-
/*
|
|
27799
|
-
* 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.
|
|
27800
|
-
* 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.
|
|
27801
|
-
*/
|
|
27802
|
-
const resolvedId = isLocalId(sourceModel[sourceModelProp])
|
|
27803
|
-
? sourceModel[sourceModelProp]
|
|
27804
|
-
: (_a = objectSyncMap.get(sourceModel[sourceModelProp])) !== null && _a !== void 0 ? _a : sourceModel[sourceModelProp];
|
|
27805
|
-
const model = (_b = pullFromCache([
|
|
27806
|
-
destinationDomain,
|
|
27807
|
-
'get',
|
|
27808
|
-
`${resolvedId}`,
|
|
27809
|
-
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
27718
|
+
const cacheKey = [destinationDomain, 'get', `${sourceModel[sourceModelProp]}`];
|
|
27719
|
+
const model = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27810
27720
|
if (!model)
|
|
27811
27721
|
return;
|
|
27812
27722
|
return callback(model);
|
|
@@ -31034,7 +30944,6 @@ let uniqueId;
|
|
|
31034
30944
|
const createMessageOptimistic = (bundle) => {
|
|
31035
30945
|
var _a, _b;
|
|
31036
30946
|
const client = getActiveClient();
|
|
31037
|
-
const { objectSyncMap } = client;
|
|
31038
30947
|
if (!client.cache)
|
|
31039
30948
|
return;
|
|
31040
30949
|
/*
|
|
@@ -31067,7 +30976,6 @@ const createMessageOptimistic = (bundle) => {
|
|
|
31067
30976
|
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);
|
|
31068
30977
|
const cachedAt = UNSYNCED_OBJECT_CACHED_AT_VALUE;
|
|
31069
30978
|
pushToCache(['message', 'get', message.messageId], message, { cachedAt });
|
|
31070
|
-
objectSyncMap.set(message.messageId, undefined);
|
|
31071
30979
|
fireEvent('local.message.created', { messages: [message] });
|
|
31072
30980
|
return message;
|
|
31073
30981
|
};
|
|
@@ -31095,15 +31003,12 @@ const createMessageOptimistic = (bundle) => {
|
|
|
31095
31003
|
*/
|
|
31096
31004
|
const createMessage = async (bundle) => {
|
|
31097
31005
|
const client = getActiveClient();
|
|
31098
|
-
const { objectSyncMap } = client;
|
|
31099
31006
|
client.log('message/createMessage', bundle);
|
|
31100
31007
|
const optimisticData = createMessageOptimistic(bundle);
|
|
31101
31008
|
const referenceId = bundle.referenceId || uniqueId || getLocalId();
|
|
31102
31009
|
uniqueId = undefined;
|
|
31103
31010
|
try {
|
|
31104
31011
|
const { data: payload } = await client.http.post('/api/v5/messages', Object.assign(Object.assign({}, convertParams(bundle)), { referenceId }));
|
|
31105
|
-
objectSyncMap.set(referenceId, payload.messages[0].messageId);
|
|
31106
|
-
objectSyncMap.set(payload.messages[0].messageId, referenceId);
|
|
31107
31012
|
const data = await prepareMessagePayload(payload);
|
|
31108
31013
|
const { messages } = data;
|
|
31109
31014
|
const cachedAt = client.cache && Date.now();
|
|
@@ -31858,7 +31763,7 @@ class MessageQueryStreamController extends QueryStreamController {
|
|
|
31858
31763
|
var _a, _b;
|
|
31859
31764
|
if (refresh) {
|
|
31860
31765
|
pushToCache(this.cacheKey, {
|
|
31861
|
-
data:
|
|
31766
|
+
data: response.messages.map(getResolver('message')),
|
|
31862
31767
|
query: this.query,
|
|
31863
31768
|
});
|
|
31864
31769
|
}
|
|
@@ -31866,8 +31771,8 @@ class MessageQueryStreamController extends QueryStreamController {
|
|
|
31866
31771
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
31867
31772
|
const messages = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
31868
31773
|
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: direction === 'next'
|
|
31869
|
-
? [...new Set([...messages, ...
|
|
31870
|
-
: [...new Set([...
|
|
31774
|
+
? [...new Set([...messages, ...response.messages.map(getResolver('message'))])]
|
|
31775
|
+
: [...new Set([...response.messages.map(getResolver('message')), ...messages])] }));
|
|
31871
31776
|
}
|
|
31872
31777
|
}
|
|
31873
31778
|
reactor(action) {
|
|
@@ -31934,12 +31839,11 @@ class MessagePaginationController extends PaginationController {
|
|
|
31934
31839
|
|
|
31935
31840
|
const getMessageFromMainDB = (messageId) => {
|
|
31936
31841
|
var _a, _b;
|
|
31937
|
-
const
|
|
31938
|
-
|
|
31939
|
-
|
|
31940
|
-
|
|
31941
|
-
|
|
31942
|
-
return (_b = pullFromCache(['message', 'get', resolvedMessageId])) === null || _b === void 0 ? void 0 : _b.data;
|
|
31842
|
+
const message = (_a = pullFromCache(['message', 'get', messageId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
31843
|
+
if (message)
|
|
31844
|
+
return message;
|
|
31845
|
+
const messages = queryCache(['message', 'get']);
|
|
31846
|
+
return (_b = messages === null || messages === void 0 ? void 0 : messages.find(({ data }) => data.messageId === messageId)) === null || _b === void 0 ? void 0 : _b.data;
|
|
31943
31847
|
};
|
|
31944
31848
|
|
|
31945
31849
|
class MessageLiveCollectionController extends LiveCollectionController {
|
|
@@ -32100,8 +32004,7 @@ var index$g = /*#__PURE__*/Object.freeze({
|
|
|
32100
32004
|
convertFromRaw: convertFromRaw$1,
|
|
32101
32005
|
prepareMessagePayload: prepareMessagePayload,
|
|
32102
32006
|
convertParams: convertParams,
|
|
32103
|
-
convertQueryParams: convertQueryParams$1
|
|
32104
|
-
getMessageIdentifierIds: getMessageIdentifierIds
|
|
32007
|
+
convertQueryParams: convertQueryParams$1
|
|
32105
32008
|
});
|
|
32106
32009
|
|
|
32107
32010
|
/**
|
|
@@ -39962,7 +39865,7 @@ var index$3 = /*#__PURE__*/Object.freeze({
|
|
|
39962
39865
|
getPoll: getPoll
|
|
39963
39866
|
});
|
|
39964
39867
|
|
|
39965
|
-
const privateKey = "-----BEGIN PRIVATE KEY-----\
|
|
39868
|
+
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-----";
|
|
39966
39869
|
/*
|
|
39967
39870
|
* The crypto algorithm used for importing key and signing string
|
|
39968
39871
|
*/
|