@amityco/ts-sdk 6.33.1 → 6.33.2-3719e72.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/core/payload.d.ts +8 -0
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/domains/client.d.ts +2 -2
- package/dist/@types/domains/client.d.ts.map +1 -1
- package/dist/@types/domains/community.d.ts +16 -0
- package/dist/@types/domains/community.d.ts.map +1 -1
- package/dist/client/api/createClient.d.ts.map +1 -1
- package/dist/client/api/isConnected.d.ts.map +1 -1
- package/dist/client/api/logout.d.ts.map +1 -1
- package/dist/client/utils/modifyMqttConnection.d.ts.map +1 -1
- package/dist/communityRepository/constants/index.d.ts +6 -0
- package/dist/communityRepository/constants/index.d.ts.map +1 -0
- package/dist/communityRepository/index.d.ts +1 -0
- package/dist/communityRepository/index.d.ts.map +1 -1
- package/dist/communityRepository/observers/index.d.ts +1 -0
- package/dist/communityRepository/observers/index.d.ts.map +1 -1
- package/dist/communityRepository/observers/semanticSearch/SemanticSearchCommunityLiveCollectionController.d.ts +14 -0
- package/dist/communityRepository/observers/semanticSearch/SemanticSearchCommunityLiveCollectionController.d.ts.map +1 -0
- package/dist/communityRepository/observers/semanticSearch/SemanticSearchCommunityPaginationController.d.ts +10 -0
- package/dist/communityRepository/observers/semanticSearch/SemanticSearchCommunityPaginationController.d.ts.map +1 -0
- package/dist/communityRepository/observers/semanticSearch/SemanticSearchCommunityQueryStreamController.d.ts +16 -0
- package/dist/communityRepository/observers/semanticSearch/SemanticSearchCommunityQueryStreamController.d.ts.map +1 -0
- package/dist/communityRepository/observers/semanticSearch/enums.d.ts +6 -0
- package/dist/communityRepository/observers/semanticSearch/enums.d.ts.map +1 -0
- package/dist/communityRepository/observers/semanticSearch/utils.d.ts +3 -0
- package/dist/communityRepository/observers/semanticSearch/utils.d.ts.map +1 -0
- package/dist/communityRepository/observers/semanticSearchCommunities.d.ts +10 -0
- package/dist/communityRepository/observers/semanticSearchCommunities.d.ts.map +1 -0
- package/dist/communityRepository/utils/payload.d.ts +1 -0
- package/dist/communityRepository/utils/payload.d.ts.map +1 -1
- package/dist/core/subscription.d.ts.map +1 -1
- package/dist/index.cjs.js +250 -32
- package/dist/index.esm.js +250 -32
- package/dist/index.umd.js +4 -4
- package/package.json +1 -1
- package/src/@types/core/payload.ts +7 -0
- package/src/@types/domains/client.ts +2 -2
- package/src/@types/domains/community.ts +24 -0
- package/src/client/api/createClient.ts +12 -2
- package/src/client/api/isConnected.ts +4 -1
- package/src/client/api/login.ts +1 -1
- package/src/client/api/logout.ts +6 -5
- package/src/client/utils/modifyMqttConnection.ts +2 -0
- package/src/client/utils/setClientToken.ts +1 -1
- package/src/communityRepository/constants/index.ts +5 -0
- package/src/communityRepository/index.ts +1 -0
- package/src/communityRepository/observers/index.ts +2 -0
- package/src/communityRepository/observers/semanticSearch/SemanticSearchCommunityLiveCollectionController.ts +164 -0
- package/src/communityRepository/observers/semanticSearch/SemanticSearchCommunityPaginationController.ts +36 -0
- package/src/communityRepository/observers/semanticSearch/SemanticSearchCommunityQueryStreamController.ts +86 -0
- package/src/communityRepository/observers/semanticSearch/enums.ts +5 -0
- package/src/communityRepository/observers/semanticSearch/utils.ts +16 -0
- package/src/communityRepository/observers/semanticSearchCommunities.ts +42 -0
- package/src/communityRepository/utils/payload.ts +11 -0
- package/src/core/events.ts +2 -2
- package/src/core/subscription.ts +2 -0
- package/src/core/transports/ws.ts +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -1334,14 +1334,14 @@ const createEventEmitter = () => {
|
|
|
1334
1334
|
*/
|
|
1335
1335
|
const proxyWebsocketEvents = (ws, emitter) => {
|
|
1336
1336
|
WS_EVENTS.forEach(event => {
|
|
1337
|
-
ws.on(event, (param) => {
|
|
1337
|
+
ws === null || ws === void 0 ? void 0 : ws.on(event, (param) => {
|
|
1338
1338
|
emitter.emit(event, param);
|
|
1339
1339
|
});
|
|
1340
1340
|
});
|
|
1341
1341
|
};
|
|
1342
1342
|
const proxyMqttEvents = (mqttClient, emitter) => {
|
|
1343
1343
|
MQTT_EVENTS.forEach(event => {
|
|
1344
|
-
mqttClient.on(event, (...params) => {
|
|
1344
|
+
mqttClient === null || mqttClient === void 0 ? void 0 : mqttClient.on(event, (...params) => {
|
|
1345
1345
|
emitter.emit(event, params.length === 1 ? params[0] : params);
|
|
1346
1346
|
});
|
|
1347
1347
|
});
|
|
@@ -1399,6 +1399,8 @@ let mqttUserId;
|
|
|
1399
1399
|
async function modifyMqttConnection() {
|
|
1400
1400
|
var _a;
|
|
1401
1401
|
const { mqtt, emitter, token } = getActiveClient();
|
|
1402
|
+
if (!mqtt)
|
|
1403
|
+
return;
|
|
1402
1404
|
const accessToken = (_a = token === null || token === void 0 ? void 0 : token.accessToken) !== null && _a !== void 0 ? _a : '';
|
|
1403
1405
|
const user = getActiveUser();
|
|
1404
1406
|
if (mqttAccessToken !== accessToken || mqttUserId !== user._id) {
|
|
@@ -1509,6 +1511,8 @@ const getSmartFeedMessageTopic = () => {
|
|
|
1509
1511
|
};
|
|
1510
1512
|
function subscribeTopic(topic, callback) {
|
|
1511
1513
|
const { mqtt } = getActiveClient();
|
|
1514
|
+
if (!mqtt)
|
|
1515
|
+
return () => null;
|
|
1512
1516
|
modifyMqttConnection();
|
|
1513
1517
|
return mqtt.subscribe(topic, callback);
|
|
1514
1518
|
}
|
|
@@ -23855,7 +23859,8 @@ const setClientToken = async (params) => {
|
|
|
23855
23859
|
isUserDeleted: false,
|
|
23856
23860
|
};
|
|
23857
23861
|
// manually setup the token for ws transport
|
|
23858
|
-
client.ws
|
|
23862
|
+
if (client.ws)
|
|
23863
|
+
client.ws.io.opts.query = { token: accessToken };
|
|
23859
23864
|
client.token = { accessToken, issuedAt, expiresAt };
|
|
23860
23865
|
setSessionState("established" /* Amity.SessionStates.ESTABLISHED */);
|
|
23861
23866
|
return { accessToken, users };
|
|
@@ -24188,12 +24193,13 @@ var objectResolverEngineOnLoginHandler = () => {
|
|
|
24188
24193
|
* @async
|
|
24189
24194
|
*/
|
|
24190
24195
|
const logout = async () => {
|
|
24196
|
+
var _a, _b;
|
|
24191
24197
|
const client = getActiveClient();
|
|
24192
24198
|
client.log('client/api/disconnectClient');
|
|
24193
|
-
if (client.mqtt.connected) {
|
|
24199
|
+
if (client.mqtt && client.mqtt.connected) {
|
|
24194
24200
|
client.mqtt.disconnect();
|
|
24195
24201
|
}
|
|
24196
|
-
if (client.ws.connected) {
|
|
24202
|
+
if (client.ws && client.ws.connected) {
|
|
24197
24203
|
client.ws.disconnect();
|
|
24198
24204
|
}
|
|
24199
24205
|
/*
|
|
@@ -24212,8 +24218,8 @@ const logout = async () => {
|
|
|
24212
24218
|
setSessionState("notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */);
|
|
24213
24219
|
client.emitter.all.clear();
|
|
24214
24220
|
// FIXME: it removes listener in ws.ts, it breaks global ban event
|
|
24215
|
-
client.ws.removeAllListeners();
|
|
24216
|
-
client.mqtt.removeAllListeners();
|
|
24221
|
+
(_a = client.ws) === null || _a === void 0 ? void 0 : _a.removeAllListeners();
|
|
24222
|
+
(_b = client.mqtt) === null || _b === void 0 ? void 0 : _b.removeAllListeners();
|
|
24217
24223
|
client.userId = undefined;
|
|
24218
24224
|
client.token = undefined;
|
|
24219
24225
|
client.http.defaults.headers.common.Authorization = '';
|
|
@@ -24222,7 +24228,8 @@ const logout = async () => {
|
|
|
24222
24228
|
isGlobalBanned: false,
|
|
24223
24229
|
isUserDeleted: false,
|
|
24224
24230
|
};
|
|
24225
|
-
client.ws
|
|
24231
|
+
if (client.ws)
|
|
24232
|
+
client.ws.io.opts.query = { token: '' };
|
|
24226
24233
|
if (typeof document !== 'undefined') {
|
|
24227
24234
|
document.cookie = '_ascSession=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';
|
|
24228
24235
|
}
|
|
@@ -25205,6 +25212,7 @@ async function runMqtt() {
|
|
|
25205
25212
|
* @async
|
|
25206
25213
|
*/
|
|
25207
25214
|
const login = async (params, sessionHandler, config) => {
|
|
25215
|
+
var _a;
|
|
25208
25216
|
const client = getActiveClient();
|
|
25209
25217
|
let unsubWatcher;
|
|
25210
25218
|
client.log('client/api/connectClient', Object.assign({ apiKey: client.apiKey, sessionState: client.sessionState }, params));
|
|
@@ -25239,7 +25247,7 @@ const login = async (params, sessionHandler, config) => {
|
|
|
25239
25247
|
// FIXME: events are duplicated if connectClient is called few times without disconnectClient
|
|
25240
25248
|
// wire websocket events to our event emitter
|
|
25241
25249
|
proxyWebsocketEvents(client.ws, client.emitter);
|
|
25242
|
-
client.ws.open();
|
|
25250
|
+
(_a = client.ws) === null || _a === void 0 ? void 0 : _a.open();
|
|
25243
25251
|
client.userId = user.userId;
|
|
25244
25252
|
client.sessionHandler = sessionHandler;
|
|
25245
25253
|
/*
|
|
@@ -25454,8 +25462,14 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
|
|
|
25454
25462
|
const httpEndpoint = (_a = apiEndpoint === null || apiEndpoint === void 0 ? void 0 : apiEndpoint.http) !== null && _a !== void 0 ? _a : computeUrl('http', apiRegion);
|
|
25455
25463
|
const mqttEndpoint = (_b = apiEndpoint === null || apiEndpoint === void 0 ? void 0 : apiEndpoint.mqtt) !== null && _b !== void 0 ? _b : computeUrl('mqtt', apiRegion);
|
|
25456
25464
|
const http = createHttpTransport(httpEndpoint);
|
|
25457
|
-
const
|
|
25458
|
-
|
|
25465
|
+
const isGoogleBotOrInspectionTool = typeof navigator !== 'undefined' &&
|
|
25466
|
+
(/Googlebot/.test(navigator.userAgent) || /Google-InspectionTool/.test(navigator.userAgent));
|
|
25467
|
+
let ws;
|
|
25468
|
+
let mqtt;
|
|
25469
|
+
if (!isGoogleBotOrInspectionTool) {
|
|
25470
|
+
ws = createWebsocketTransport(httpEndpoint);
|
|
25471
|
+
mqtt = createMqttTransport(mqttEndpoint);
|
|
25472
|
+
}
|
|
25459
25473
|
const emitter = createEventEmitter();
|
|
25460
25474
|
/*
|
|
25461
25475
|
* Since v6 cache is enabled by default
|
|
@@ -25579,9 +25593,11 @@ const isConnected = () => {
|
|
|
25579
25593
|
var _a, _b;
|
|
25580
25594
|
const client = getActiveClient();
|
|
25581
25595
|
client.log('client/api/isConnected', client);
|
|
25596
|
+
// if client is connected to ws, it means client is connected. If ws is undefined, it means ws is not used.
|
|
25597
|
+
const isWsConnected = (client.ws && client.ws.connected) || !!client.ws;
|
|
25582
25598
|
return !!(client.userId &&
|
|
25583
25599
|
((_b = String((_a = client.http.defaults.headers.common) === null || _a === void 0 ? void 0 : _a.Authorization)) === null || _b === void 0 ? void 0 : _b.length) &&
|
|
25584
|
-
|
|
25600
|
+
isWsConnected);
|
|
25585
25601
|
};
|
|
25586
25602
|
|
|
25587
25603
|
var _GlobalFileAccessType_fileAccessType;
|
|
@@ -29754,6 +29770,11 @@ const prepareCommunityRequest = (params) => {
|
|
|
29754
29770
|
return Object.assign(Object.assign(Object.assign({}, restParam), (postSetting ? CommunityPostSettingMaps[postSetting] : undefined)), {
|
|
29755
29771
|
// Convert story setting to the actual value. (Allow by default)
|
|
29756
29772
|
allowCommentInStory: typeof (storySetting === null || storySetting === void 0 ? void 0 : storySetting.enableComment) === 'boolean' ? storySetting.enableComment : true });
|
|
29773
|
+
};
|
|
29774
|
+
const prepareSemanticSearchCommunityPayload = (_a) => {
|
|
29775
|
+
var communityPayload = __rest(_a, ["searchResult"]);
|
|
29776
|
+
const processedCommunityPayload = prepareCommunityPayload(communityPayload);
|
|
29777
|
+
return Object.assign({}, processedCommunityPayload);
|
|
29757
29778
|
};
|
|
29758
29779
|
|
|
29759
29780
|
const preparePostPayload = (payload) => {
|
|
@@ -35828,12 +35849,12 @@ class CommunitiesQueryStreamController$1 extends QueryStreamController {
|
|
|
35828
35849
|
}
|
|
35829
35850
|
}
|
|
35830
35851
|
|
|
35831
|
-
var EnumCommunityActions$
|
|
35852
|
+
var EnumCommunityActions$4;
|
|
35832
35853
|
(function (EnumCommunityActions) {
|
|
35833
35854
|
EnumCommunityActions["OnCommunityCreated"] = "onCommunityCreated";
|
|
35834
35855
|
EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
|
|
35835
35856
|
EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
|
|
35836
|
-
})(EnumCommunityActions$
|
|
35857
|
+
})(EnumCommunityActions$4 || (EnumCommunityActions$4 = {}));
|
|
35837
35858
|
|
|
35838
35859
|
var EnumCommunityMemberActions$1;
|
|
35839
35860
|
(function (EnumCommunityMemberActions) {
|
|
@@ -36525,8 +36546,8 @@ class SearchCommunityLiveCollectionController extends LiveCollectionController {
|
|
|
36525
36546
|
}
|
|
36526
36547
|
startSubscription() {
|
|
36527
36548
|
return this.queryStreamController.subscribeRTE([
|
|
36528
|
-
{ fn: onCommunityDeleted, action: EnumCommunityActions$
|
|
36529
|
-
{ fn: onCommunityUpdated, action: EnumCommunityActions$
|
|
36549
|
+
{ fn: onCommunityDeleted, action: EnumCommunityActions$4.OnCommunityDeleted },
|
|
36550
|
+
{ fn: onCommunityUpdated, action: EnumCommunityActions$4.OnCommunityUpdated },
|
|
36530
36551
|
{ fn: onCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
36531
36552
|
{ fn: onCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
36532
36553
|
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnMemberCountChanged },
|
|
@@ -36626,12 +36647,12 @@ class CommunitiesPaginationController extends PaginationController {
|
|
|
36626
36647
|
}
|
|
36627
36648
|
}
|
|
36628
36649
|
|
|
36629
|
-
var EnumCommunityActions$
|
|
36650
|
+
var EnumCommunityActions$3;
|
|
36630
36651
|
(function (EnumCommunityActions) {
|
|
36631
36652
|
EnumCommunityActions["OnCommunityCreated"] = "onCommunityCreated";
|
|
36632
36653
|
EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
|
|
36633
36654
|
EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
|
|
36634
|
-
})(EnumCommunityActions$
|
|
36655
|
+
})(EnumCommunityActions$3 || (EnumCommunityActions$3 = {}));
|
|
36635
36656
|
|
|
36636
36657
|
class CommunitiesQueryStreamController extends QueryStreamController {
|
|
36637
36658
|
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
@@ -36667,7 +36688,7 @@ class CommunitiesQueryStreamController extends QueryStreamController {
|
|
|
36667
36688
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
36668
36689
|
if (!collection)
|
|
36669
36690
|
return;
|
|
36670
|
-
if (this.query.displayName && action === EnumCommunityActions$
|
|
36691
|
+
if (this.query.displayName && action === EnumCommunityActions$3.OnCommunityCreated) {
|
|
36671
36692
|
return;
|
|
36672
36693
|
}
|
|
36673
36694
|
/*
|
|
@@ -36712,9 +36733,9 @@ class CommunityLiveCollectionController extends LiveCollectionController {
|
|
|
36712
36733
|
}
|
|
36713
36734
|
startSubscription() {
|
|
36714
36735
|
return this.queryStreamController.subscribeRTE([
|
|
36715
|
-
{ fn: onCommunityCreated, action: EnumCommunityActions$
|
|
36716
|
-
{ fn: onCommunityDeleted, action: EnumCommunityActions$
|
|
36717
|
-
{ fn: onCommunityUpdated, action: EnumCommunityActions$
|
|
36736
|
+
{ fn: onCommunityCreated, action: EnumCommunityActions$3.OnCommunityCreated },
|
|
36737
|
+
{ fn: onCommunityDeleted, action: EnumCommunityActions$3.OnCommunityDeleted },
|
|
36738
|
+
{ fn: onCommunityUpdated, action: EnumCommunityActions$3.OnCommunityUpdated },
|
|
36718
36739
|
{ fn: onCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
36719
36740
|
{ fn: onCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
36720
36741
|
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnMemberCountChanged },
|
|
@@ -36909,11 +36930,11 @@ class TrendingCommunitiesQueryStreamController extends QueryStreamController {
|
|
|
36909
36930
|
}
|
|
36910
36931
|
}
|
|
36911
36932
|
|
|
36912
|
-
var EnumCommunityActions$
|
|
36933
|
+
var EnumCommunityActions$2;
|
|
36913
36934
|
(function (EnumCommunityActions) {
|
|
36914
36935
|
EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
|
|
36915
36936
|
EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
|
|
36916
|
-
})(EnumCommunityActions$
|
|
36937
|
+
})(EnumCommunityActions$2 || (EnumCommunityActions$2 = {}));
|
|
36917
36938
|
|
|
36918
36939
|
class TrendingCommunityLiveCollectionController extends LiveCollectionController {
|
|
36919
36940
|
constructor(query, callback) {
|
|
@@ -36944,8 +36965,8 @@ class TrendingCommunityLiveCollectionController extends LiveCollectionController
|
|
|
36944
36965
|
}
|
|
36945
36966
|
startSubscription() {
|
|
36946
36967
|
return this.queryStreamController.subscribeRTE([
|
|
36947
|
-
{ fn: onCommunityDeleted, action: EnumCommunityActions$
|
|
36948
|
-
{ fn: onCommunityUpdated, action: EnumCommunityActions$
|
|
36968
|
+
{ fn: onCommunityDeleted, action: EnumCommunityActions$2.OnCommunityDeleted },
|
|
36969
|
+
{ fn: onCommunityUpdated, action: EnumCommunityActions$2.OnCommunityUpdated },
|
|
36949
36970
|
{ fn: onCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
36950
36971
|
{ fn: onCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
36951
36972
|
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnMemberCountChanged },
|
|
@@ -37071,11 +37092,11 @@ class RecommendedCommunitiesQueryStreamController extends QueryStreamController
|
|
|
37071
37092
|
}
|
|
37072
37093
|
}
|
|
37073
37094
|
|
|
37074
|
-
var EnumCommunityActions;
|
|
37095
|
+
var EnumCommunityActions$1;
|
|
37075
37096
|
(function (EnumCommunityActions) {
|
|
37076
37097
|
EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
|
|
37077
37098
|
EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
|
|
37078
|
-
})(EnumCommunityActions || (EnumCommunityActions = {}));
|
|
37099
|
+
})(EnumCommunityActions$1 || (EnumCommunityActions$1 = {}));
|
|
37079
37100
|
|
|
37080
37101
|
class RecommendedCommunityLiveCollectionController extends LiveCollectionController {
|
|
37081
37102
|
constructor(query, callback) {
|
|
@@ -37106,8 +37127,8 @@ class RecommendedCommunityLiveCollectionController extends LiveCollectionControl
|
|
|
37106
37127
|
}
|
|
37107
37128
|
startSubscription() {
|
|
37108
37129
|
return this.queryStreamController.subscribeRTE([
|
|
37109
|
-
{ fn: onCommunityDeleted, action: EnumCommunityActions.OnCommunityDeleted },
|
|
37110
|
-
{ fn: onCommunityUpdated, action: EnumCommunityActions.OnCommunityUpdated },
|
|
37130
|
+
{ fn: onCommunityDeleted, action: EnumCommunityActions$1.OnCommunityDeleted },
|
|
37131
|
+
{ fn: onCommunityUpdated, action: EnumCommunityActions$1.OnCommunityUpdated },
|
|
37111
37132
|
{ fn: onCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
37112
37133
|
{ fn: onCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
37113
37134
|
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnMemberCountChanged },
|
|
@@ -37175,6 +37196,201 @@ const getRecommendedCommunities = (params, callback, config) => {
|
|
|
37175
37196
|
};
|
|
37176
37197
|
/* end_public_function */
|
|
37177
37198
|
|
|
37199
|
+
class SemanticSearchCommunityPaginationController extends PaginationController {
|
|
37200
|
+
async getRequest(queryParams, token) {
|
|
37201
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, communityMembershipStatus } = queryParams, params = __rest(queryParams, ["limit", "communityMembershipStatus"]);
|
|
37202
|
+
const baseOptions = {
|
|
37203
|
+
type: queryParams.limit ? 'pagination' : undefined,
|
|
37204
|
+
};
|
|
37205
|
+
const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
|
|
37206
|
+
const { data: queryResponse } = await this.http.get(`/api/v1/semantic-search/communities`, {
|
|
37207
|
+
params: Object.assign(Object.assign({}, params), { filter: communityMembershipStatus !== null && communityMembershipStatus !== void 0 ? communityMembershipStatus : "all" /* AmityCommunityMemberStatusFilter.ALL */, options }),
|
|
37208
|
+
});
|
|
37209
|
+
return queryResponse;
|
|
37210
|
+
}
|
|
37211
|
+
}
|
|
37212
|
+
|
|
37213
|
+
function prepareSemanticCommunitiesReferenceId(response) {
|
|
37214
|
+
return response.communities.map(community => {
|
|
37215
|
+
const score = response.searchResult.find(result => result.communityId === community.communityId);
|
|
37216
|
+
return `${community.communityId}:${score}`;
|
|
37217
|
+
});
|
|
37218
|
+
}
|
|
37219
|
+
|
|
37220
|
+
class SemanticSearchCommunityQueryStreamController extends QueryStreamController {
|
|
37221
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
37222
|
+
super(query, cacheKey);
|
|
37223
|
+
this.notifyChange = notifyChange;
|
|
37224
|
+
this.preparePayload = preparePayload;
|
|
37225
|
+
}
|
|
37226
|
+
async saveToMainDB(response) {
|
|
37227
|
+
const processedPayload = this.preparePayload(response);
|
|
37228
|
+
const client = getActiveClient();
|
|
37229
|
+
const cachedAt = client.cache && Date.now();
|
|
37230
|
+
if (client.cache) {
|
|
37231
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
37232
|
+
}
|
|
37233
|
+
}
|
|
37234
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
37235
|
+
var _a, _b;
|
|
37236
|
+
if (refresh) {
|
|
37237
|
+
pushToCache(this.cacheKey, {
|
|
37238
|
+
data: prepareSemanticCommunitiesReferenceId(response),
|
|
37239
|
+
});
|
|
37240
|
+
}
|
|
37241
|
+
else {
|
|
37242
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
37243
|
+
const communities = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
37244
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...communities, ...prepareSemanticCommunitiesReferenceId(response)])] }));
|
|
37245
|
+
}
|
|
37246
|
+
}
|
|
37247
|
+
reactor(action) {
|
|
37248
|
+
return (community) => {
|
|
37249
|
+
var _a;
|
|
37250
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
37251
|
+
if (!collection)
|
|
37252
|
+
return;
|
|
37253
|
+
collection.data = [...new Set([community.communityId, ...collection.data])];
|
|
37254
|
+
pushToCache(this.cacheKey, collection);
|
|
37255
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
37256
|
+
};
|
|
37257
|
+
//
|
|
37258
|
+
}
|
|
37259
|
+
subscribeRTE(createSubscriber) {
|
|
37260
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
37261
|
+
}
|
|
37262
|
+
}
|
|
37263
|
+
|
|
37264
|
+
var EnumCommunityActions;
|
|
37265
|
+
(function (EnumCommunityActions) {
|
|
37266
|
+
EnumCommunityActions["OnCommunityCreated"] = "onCommunityCreated";
|
|
37267
|
+
EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
|
|
37268
|
+
EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
|
|
37269
|
+
})(EnumCommunityActions || (EnumCommunityActions = {}));
|
|
37270
|
+
|
|
37271
|
+
class SemanticSearchCommunityLiveCollectionController extends LiveCollectionController {
|
|
37272
|
+
constructor(query, callback) {
|
|
37273
|
+
const queryStreamId = hash(query);
|
|
37274
|
+
const cacheKey = ['community', 'collection', queryStreamId];
|
|
37275
|
+
const paginationController = new SemanticSearchCommunityPaginationController(query);
|
|
37276
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
37277
|
+
this.query = query;
|
|
37278
|
+
this.queryStreamController = new SemanticSearchCommunityQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareSemanticSearchCommunityPayload);
|
|
37279
|
+
this.callback = callback.bind(this);
|
|
37280
|
+
this.loadPage({ initial: true });
|
|
37281
|
+
}
|
|
37282
|
+
setup() {
|
|
37283
|
+
var _a;
|
|
37284
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
37285
|
+
if (!collection) {
|
|
37286
|
+
pushToCache(this.cacheKey, {
|
|
37287
|
+
data: [],
|
|
37288
|
+
params: {},
|
|
37289
|
+
});
|
|
37290
|
+
}
|
|
37291
|
+
}
|
|
37292
|
+
async persistModel(queryPayload) {
|
|
37293
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
37294
|
+
}
|
|
37295
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
37296
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
37297
|
+
}
|
|
37298
|
+
startSubscription() {
|
|
37299
|
+
return this.queryStreamController.subscribeRTE([
|
|
37300
|
+
{ fn: onCommunityCreated, action: EnumCommunityActions.OnCommunityCreated },
|
|
37301
|
+
{ fn: onCommunityDeleted, action: EnumCommunityActions.OnCommunityDeleted },
|
|
37302
|
+
{ fn: onCommunityUpdated, action: EnumCommunityActions.OnCommunityUpdated },
|
|
37303
|
+
{ fn: onCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
37304
|
+
{ fn: onCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
37305
|
+
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnMemberCountChanged },
|
|
37306
|
+
{ fn: onLocalCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
37307
|
+
{ fn: onLocalCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
37308
|
+
]);
|
|
37309
|
+
}
|
|
37310
|
+
notifyChange({ origin, loading, error }) {
|
|
37311
|
+
var _a, _b;
|
|
37312
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
37313
|
+
if (!collection)
|
|
37314
|
+
return;
|
|
37315
|
+
const data = this.applyFilter((_b = collection.data
|
|
37316
|
+
.map(communityIdWithScore => {
|
|
37317
|
+
const [communityId, score] = communityIdWithScore.split(':');
|
|
37318
|
+
return {
|
|
37319
|
+
communityId,
|
|
37320
|
+
score: parseFloat(score),
|
|
37321
|
+
};
|
|
37322
|
+
})
|
|
37323
|
+
.sort((a, b) => b.score - a.score)
|
|
37324
|
+
.map(({ communityId }) => pullFromCache(['community', 'get', communityId]))
|
|
37325
|
+
.filter(isNonNullable)
|
|
37326
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
|
|
37327
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
37328
|
+
return;
|
|
37329
|
+
this.callback({
|
|
37330
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
37331
|
+
data,
|
|
37332
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
37333
|
+
loading,
|
|
37334
|
+
error,
|
|
37335
|
+
});
|
|
37336
|
+
}
|
|
37337
|
+
applyFilter(data) {
|
|
37338
|
+
const { userId } = getActiveClient();
|
|
37339
|
+
let communities = data;
|
|
37340
|
+
if (this.query.categoryIds) {
|
|
37341
|
+
communities = communities.filter(c => {
|
|
37342
|
+
var _a;
|
|
37343
|
+
return (_a = c.categoryIds) === null || _a === void 0 ? void 0 : _a.some((id) => {
|
|
37344
|
+
if (!this.query.categoryIds)
|
|
37345
|
+
return true;
|
|
37346
|
+
if (this.query.categoryIds.length === 0)
|
|
37347
|
+
return true;
|
|
37348
|
+
return this.query.categoryIds.includes(id);
|
|
37349
|
+
});
|
|
37350
|
+
});
|
|
37351
|
+
}
|
|
37352
|
+
if (this.query.tags) {
|
|
37353
|
+
communities = communities.filter(c => { var _a; return (_a = c.tags) === null || _a === void 0 ? void 0 : _a.some(t => { var _a; return (_a = this.query.tags) === null || _a === void 0 ? void 0 : _a.includes(t); }); });
|
|
37354
|
+
}
|
|
37355
|
+
if (this.query.communityMembershipStatus && userId) {
|
|
37356
|
+
communities = filterByCommunityMembership(communities, this.query.communityMembershipStatus, userId);
|
|
37357
|
+
}
|
|
37358
|
+
return communities;
|
|
37359
|
+
}
|
|
37360
|
+
}
|
|
37361
|
+
|
|
37362
|
+
/**
|
|
37363
|
+
* search posts by semantic search
|
|
37364
|
+
*
|
|
37365
|
+
* @returns the associated pinned post(s)
|
|
37366
|
+
*
|
|
37367
|
+
* @category Posts Live Collection
|
|
37368
|
+
*
|
|
37369
|
+
*/
|
|
37370
|
+
const semanticSearchCommunities = (params, callback, config) => {
|
|
37371
|
+
const { log, cache } = getActiveClient();
|
|
37372
|
+
if (!cache) {
|
|
37373
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
37374
|
+
}
|
|
37375
|
+
const timestamp = Date.now();
|
|
37376
|
+
log(`semanticSearchCommunities(tmpid: ${timestamp}) > listen`);
|
|
37377
|
+
const semanticSearchPostLiveCollection = new SemanticSearchCommunityLiveCollectionController(params, callback);
|
|
37378
|
+
const disposers = semanticSearchPostLiveCollection.startSubscription();
|
|
37379
|
+
const cacheKey = semanticSearchPostLiveCollection.getCacheKey();
|
|
37380
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
37381
|
+
return () => {
|
|
37382
|
+
log(`semanticSearchCommunities(tmpid: ${timestamp}) > dispose`);
|
|
37383
|
+
disposers.forEach(fn => fn());
|
|
37384
|
+
};
|
|
37385
|
+
};
|
|
37386
|
+
|
|
37387
|
+
var AmityCommunityMemberStatusFilter;
|
|
37388
|
+
(function (AmityCommunityMemberStatusFilter) {
|
|
37389
|
+
AmityCommunityMemberStatusFilter["ALL"] = "all";
|
|
37390
|
+
AmityCommunityMemberStatusFilter["MEMBER"] = "member";
|
|
37391
|
+
AmityCommunityMemberStatusFilter["NOT_MEMBER"] = "notMember";
|
|
37392
|
+
})(AmityCommunityMemberStatusFilter || (AmityCommunityMemberStatusFilter = {}));
|
|
37393
|
+
|
|
37178
37394
|
/* begin_public_function
|
|
37179
37395
|
id: community.moderation.add_roles
|
|
37180
37396
|
*/
|
|
@@ -37338,7 +37554,9 @@ var index$9 = /*#__PURE__*/Object.freeze({
|
|
|
37338
37554
|
getCommunities: getCommunities,
|
|
37339
37555
|
getCommunity: getCommunity,
|
|
37340
37556
|
getTrendingCommunities: getTrendingCommunities,
|
|
37341
|
-
getRecommendedCommunities: getRecommendedCommunities
|
|
37557
|
+
getRecommendedCommunities: getRecommendedCommunities,
|
|
37558
|
+
semanticSearchCommunities: semanticSearchCommunities,
|
|
37559
|
+
get AmityCommunityMemberStatusFilter () { return AmityCommunityMemberStatusFilter; }
|
|
37342
37560
|
});
|
|
37343
37561
|
|
|
37344
37562
|
/* begin_public_function
|
|
@@ -41217,7 +41435,7 @@ var index$3 = /*#__PURE__*/Object.freeze({
|
|
|
41217
41435
|
getPoll: getPoll
|
|
41218
41436
|
});
|
|
41219
41437
|
|
|
41220
|
-
const privateKey = "-----BEGIN PRIVATE KEY-----\
|
|
41438
|
+
const privateKey = "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDAARz+hmBgi8pJ\nQb8LeY41gtHhk+ACMwRfhsn7GqpqRQNG2qU0755mzZuVDUqjQMGSo8THJB7O+OJs\nflbZRkFXlFoFOVNw1UpNOgwEQZ6wB9oRwzepTJAfF1sVhm/o/ixvXh1zDFNDy6yZ\npXyiiJHUVxqyjllZhxnwdvjoVtDs6hW6awG09bB9nh/TTejlUKXoAgzqVwu/1QMu\nUVViET495elEe19aUarEy+oL2iKeXCEvqda/pWNBdbieFyJvvZ08HN8dPuT88wq2\njZLEAth1vrwQ2IAa4ktaLcBQdLJgIkrbDvAiVZ8lQAjS/bq5vXQikTGvoPlC5bbn\nvuOM/3eLAgMBAAECggEAVZ+peHAghq2QVj71nX5lxsNCKaCyYwixSJBpfouTt7Rz\nE6PpzMOXFi1W1o+I22jDakuSM2SOQKqI/u0QefB0r0O/KVk5NrZHXk0mkrdYtxOp\nUgaGyf8UvmjB+8VqHrNKyZdk9qtmbnNj01kTTcAtmE4H39zPR7eR/8Rul94vaZbs\nwCnKJS3mLT3JxyGug6lxanveKkjG+CKC1nJQYWaxCJxaFSzbwXQPvDhB+TvrIbee\npd5v4EAyEJohpr+T9oDGGJkb/KARBZCtwLyB976PKJwwBA8MRVL1i5QwawuMiMq5\nUtnOnbGKtCeFzaLbNU0Qi8bqyims84EQxC6DOu1fkQKBgQDdvsoBsEhsOXV7hlIJ\naEd0eSJZVkdqimxH8uGoMM2FeNaOrcB6yBXqTSP0R3OIyf8eaY6yjRvP30ZNXcll\n/gD3O1Mu6YmWQdt1W2WA6pKOsUuPXasf0pdOF7IiFZKlSabz5YHXFqwVuqm8loaj\nsXel3YWqPVdHiankE7tz+3ssnQKBgQDdqi4TNdD1MdEpihx19jr0QjUiXW3939FK\nqp30HESPEGDGQzXdmJgif9HhZb+cJSuWaHEbjgBrYahvgCF+y6LbEpOD+D/dmT+s\nDEAQaR84sah6dokwPjV8fjBSrcVFjCS+doxv0d3p/9OUEeyUhFrY03nxtIEYkLIE\n/Zvn37b4RwKBgQCLENVFe9XfsaVhQ5r9dV2iyTlmh7qgMZG5CbTFs12hQGhm8McO\n+Z7s41YSJCFr/yq1WwP4LJDtrBw99vyQr1zRsG35tNLp3gGRNzGQSQyC2uQFVHw2\np+7mNewsfhUK/gbrXNsyFnDz6635rPlhfbII3sWuP2wWXFqkxE9CbMwR7QKBgQC6\nawDMzxmo2/iYArrkyevSuEuPVxvFwpF1RgAI6C0QVCnPE38dmdN4UB7mfHekje4W\nVEercMURidPp0cxZolCYBQtilUjAyL0vqC3In1/Ogjq6oy3FEMxSop1pKxMY5j+Q\nnoqFD+6deLUrddeNH7J3X4LSr4dSbX4JjG+tlgt+yQKBgQCuwTL4hA6KqeInQ0Ta\n9VQX5Qr8hFlqJz1gpymi/k63tW/Ob8yedbg3WWNWyShwRMFYyY9S81ITFWM95uL6\nvF3x9rmRjwElJw9PMwVu6dmf/CO0Z1wzXSp2VVD12gbrUD/0/d7MUoJ9LgC8X8f/\nn0txLHYGHbx+nf95+JUg6lV3hg==\n-----END PRIVATE KEY-----";
|
|
41221
41439
|
/*
|
|
41222
41440
|
* The crypto algorithm used for importing key and signing string
|
|
41223
41441
|
*/
|