@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.cjs.js
CHANGED
|
@@ -1349,14 +1349,14 @@ const createEventEmitter = () => {
|
|
|
1349
1349
|
*/
|
|
1350
1350
|
const proxyWebsocketEvents = (ws, emitter) => {
|
|
1351
1351
|
WS_EVENTS.forEach(event => {
|
|
1352
|
-
ws.on(event, (param) => {
|
|
1352
|
+
ws === null || ws === void 0 ? void 0 : ws.on(event, (param) => {
|
|
1353
1353
|
emitter.emit(event, param);
|
|
1354
1354
|
});
|
|
1355
1355
|
});
|
|
1356
1356
|
};
|
|
1357
1357
|
const proxyMqttEvents = (mqttClient, emitter) => {
|
|
1358
1358
|
MQTT_EVENTS.forEach(event => {
|
|
1359
|
-
mqttClient.on(event, (...params) => {
|
|
1359
|
+
mqttClient === null || mqttClient === void 0 ? void 0 : mqttClient.on(event, (...params) => {
|
|
1360
1360
|
emitter.emit(event, params.length === 1 ? params[0] : params);
|
|
1361
1361
|
});
|
|
1362
1362
|
});
|
|
@@ -1414,6 +1414,8 @@ let mqttUserId;
|
|
|
1414
1414
|
async function modifyMqttConnection() {
|
|
1415
1415
|
var _a;
|
|
1416
1416
|
const { mqtt, emitter, token } = getActiveClient();
|
|
1417
|
+
if (!mqtt)
|
|
1418
|
+
return;
|
|
1417
1419
|
const accessToken = (_a = token === null || token === void 0 ? void 0 : token.accessToken) !== null && _a !== void 0 ? _a : '';
|
|
1418
1420
|
const user = getActiveUser();
|
|
1419
1421
|
if (mqttAccessToken !== accessToken || mqttUserId !== user._id) {
|
|
@@ -1524,6 +1526,8 @@ const getSmartFeedMessageTopic = () => {
|
|
|
1524
1526
|
};
|
|
1525
1527
|
function subscribeTopic(topic, callback) {
|
|
1526
1528
|
const { mqtt } = getActiveClient();
|
|
1529
|
+
if (!mqtt)
|
|
1530
|
+
return () => null;
|
|
1527
1531
|
modifyMqttConnection();
|
|
1528
1532
|
return mqtt.subscribe(topic, callback);
|
|
1529
1533
|
}
|
|
@@ -7763,7 +7767,8 @@ const setClientToken = async (params) => {
|
|
|
7763
7767
|
isUserDeleted: false,
|
|
7764
7768
|
};
|
|
7765
7769
|
// manually setup the token for ws transport
|
|
7766
|
-
client.ws
|
|
7770
|
+
if (client.ws)
|
|
7771
|
+
client.ws.io.opts.query = { token: accessToken };
|
|
7767
7772
|
client.token = { accessToken, issuedAt, expiresAt };
|
|
7768
7773
|
setSessionState("established" /* Amity.SessionStates.ESTABLISHED */);
|
|
7769
7774
|
return { accessToken, users };
|
|
@@ -8096,12 +8101,13 @@ var objectResolverEngineOnLoginHandler = () => {
|
|
|
8096
8101
|
* @async
|
|
8097
8102
|
*/
|
|
8098
8103
|
const logout = async () => {
|
|
8104
|
+
var _a, _b;
|
|
8099
8105
|
const client = getActiveClient();
|
|
8100
8106
|
client.log('client/api/disconnectClient');
|
|
8101
|
-
if (client.mqtt.connected) {
|
|
8107
|
+
if (client.mqtt && client.mqtt.connected) {
|
|
8102
8108
|
client.mqtt.disconnect();
|
|
8103
8109
|
}
|
|
8104
|
-
if (client.ws.connected) {
|
|
8110
|
+
if (client.ws && client.ws.connected) {
|
|
8105
8111
|
client.ws.disconnect();
|
|
8106
8112
|
}
|
|
8107
8113
|
/*
|
|
@@ -8120,8 +8126,8 @@ const logout = async () => {
|
|
|
8120
8126
|
setSessionState("notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */);
|
|
8121
8127
|
client.emitter.all.clear();
|
|
8122
8128
|
// FIXME: it removes listener in ws.ts, it breaks global ban event
|
|
8123
|
-
client.ws.removeAllListeners();
|
|
8124
|
-
client.mqtt.removeAllListeners();
|
|
8129
|
+
(_a = client.ws) === null || _a === void 0 ? void 0 : _a.removeAllListeners();
|
|
8130
|
+
(_b = client.mqtt) === null || _b === void 0 ? void 0 : _b.removeAllListeners();
|
|
8125
8131
|
client.userId = undefined;
|
|
8126
8132
|
client.token = undefined;
|
|
8127
8133
|
client.http.defaults.headers.common.Authorization = '';
|
|
@@ -8130,7 +8136,8 @@ const logout = async () => {
|
|
|
8130
8136
|
isGlobalBanned: false,
|
|
8131
8137
|
isUserDeleted: false,
|
|
8132
8138
|
};
|
|
8133
|
-
client.ws
|
|
8139
|
+
if (client.ws)
|
|
8140
|
+
client.ws.io.opts.query = { token: '' };
|
|
8134
8141
|
if (typeof document !== 'undefined') {
|
|
8135
8142
|
document.cookie = '_ascSession=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';
|
|
8136
8143
|
}
|
|
@@ -9113,6 +9120,7 @@ async function runMqtt() {
|
|
|
9113
9120
|
* @async
|
|
9114
9121
|
*/
|
|
9115
9122
|
const login = async (params, sessionHandler, config) => {
|
|
9123
|
+
var _a;
|
|
9116
9124
|
const client = getActiveClient();
|
|
9117
9125
|
let unsubWatcher;
|
|
9118
9126
|
client.log('client/api/connectClient', Object.assign({ apiKey: client.apiKey, sessionState: client.sessionState }, params));
|
|
@@ -9147,7 +9155,7 @@ const login = async (params, sessionHandler, config) => {
|
|
|
9147
9155
|
// FIXME: events are duplicated if connectClient is called few times without disconnectClient
|
|
9148
9156
|
// wire websocket events to our event emitter
|
|
9149
9157
|
proxyWebsocketEvents(client.ws, client.emitter);
|
|
9150
|
-
client.ws.open();
|
|
9158
|
+
(_a = client.ws) === null || _a === void 0 ? void 0 : _a.open();
|
|
9151
9159
|
client.userId = user.userId;
|
|
9152
9160
|
client.sessionHandler = sessionHandler;
|
|
9153
9161
|
/*
|
|
@@ -9362,8 +9370,14 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
|
|
|
9362
9370
|
const httpEndpoint = (_a = apiEndpoint === null || apiEndpoint === void 0 ? void 0 : apiEndpoint.http) !== null && _a !== void 0 ? _a : computeUrl('http', apiRegion);
|
|
9363
9371
|
const mqttEndpoint = (_b = apiEndpoint === null || apiEndpoint === void 0 ? void 0 : apiEndpoint.mqtt) !== null && _b !== void 0 ? _b : computeUrl('mqtt', apiRegion);
|
|
9364
9372
|
const http = createHttpTransport(httpEndpoint);
|
|
9365
|
-
const
|
|
9366
|
-
|
|
9373
|
+
const isGoogleBotOrInspectionTool = typeof navigator !== 'undefined' &&
|
|
9374
|
+
(/Googlebot/.test(navigator.userAgent) || /Google-InspectionTool/.test(navigator.userAgent));
|
|
9375
|
+
let ws;
|
|
9376
|
+
let mqtt;
|
|
9377
|
+
if (!isGoogleBotOrInspectionTool) {
|
|
9378
|
+
ws = createWebsocketTransport(httpEndpoint);
|
|
9379
|
+
mqtt = createMqttTransport(mqttEndpoint);
|
|
9380
|
+
}
|
|
9367
9381
|
const emitter = createEventEmitter();
|
|
9368
9382
|
/*
|
|
9369
9383
|
* Since v6 cache is enabled by default
|
|
@@ -9487,9 +9501,11 @@ const isConnected = () => {
|
|
|
9487
9501
|
var _a, _b;
|
|
9488
9502
|
const client = getActiveClient();
|
|
9489
9503
|
client.log('client/api/isConnected', client);
|
|
9504
|
+
// if client is connected to ws, it means client is connected. If ws is undefined, it means ws is not used.
|
|
9505
|
+
const isWsConnected = (client.ws && client.ws.connected) || !!client.ws;
|
|
9490
9506
|
return !!(client.userId &&
|
|
9491
9507
|
((_b = String((_a = client.http.defaults.headers.common) === null || _a === void 0 ? void 0 : _a.Authorization)) === null || _b === void 0 ? void 0 : _b.length) &&
|
|
9492
|
-
|
|
9508
|
+
isWsConnected);
|
|
9493
9509
|
};
|
|
9494
9510
|
|
|
9495
9511
|
var _GlobalFileAccessType_fileAccessType;
|
|
@@ -13662,6 +13678,11 @@ const prepareCommunityRequest = (params) => {
|
|
|
13662
13678
|
return Object.assign(Object.assign(Object.assign({}, restParam), (postSetting ? CommunityPostSettingMaps[postSetting] : undefined)), {
|
|
13663
13679
|
// Convert story setting to the actual value. (Allow by default)
|
|
13664
13680
|
allowCommentInStory: typeof (storySetting === null || storySetting === void 0 ? void 0 : storySetting.enableComment) === 'boolean' ? storySetting.enableComment : true });
|
|
13681
|
+
};
|
|
13682
|
+
const prepareSemanticSearchCommunityPayload = (_a) => {
|
|
13683
|
+
var communityPayload = __rest(_a, ["searchResult"]);
|
|
13684
|
+
const processedCommunityPayload = prepareCommunityPayload(communityPayload);
|
|
13685
|
+
return Object.assign({}, processedCommunityPayload);
|
|
13665
13686
|
};
|
|
13666
13687
|
|
|
13667
13688
|
const preparePostPayload = (payload) => {
|
|
@@ -19736,12 +19757,12 @@ class CommunitiesQueryStreamController$1 extends QueryStreamController {
|
|
|
19736
19757
|
}
|
|
19737
19758
|
}
|
|
19738
19759
|
|
|
19739
|
-
var EnumCommunityActions$
|
|
19760
|
+
var EnumCommunityActions$4;
|
|
19740
19761
|
(function (EnumCommunityActions) {
|
|
19741
19762
|
EnumCommunityActions["OnCommunityCreated"] = "onCommunityCreated";
|
|
19742
19763
|
EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
|
|
19743
19764
|
EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
|
|
19744
|
-
})(EnumCommunityActions$
|
|
19765
|
+
})(EnumCommunityActions$4 || (EnumCommunityActions$4 = {}));
|
|
19745
19766
|
|
|
19746
19767
|
var EnumCommunityMemberActions$1;
|
|
19747
19768
|
(function (EnumCommunityMemberActions) {
|
|
@@ -20433,8 +20454,8 @@ class SearchCommunityLiveCollectionController extends LiveCollectionController {
|
|
|
20433
20454
|
}
|
|
20434
20455
|
startSubscription() {
|
|
20435
20456
|
return this.queryStreamController.subscribeRTE([
|
|
20436
|
-
{ fn: onCommunityDeleted, action: EnumCommunityActions$
|
|
20437
|
-
{ fn: onCommunityUpdated, action: EnumCommunityActions$
|
|
20457
|
+
{ fn: onCommunityDeleted, action: EnumCommunityActions$4.OnCommunityDeleted },
|
|
20458
|
+
{ fn: onCommunityUpdated, action: EnumCommunityActions$4.OnCommunityUpdated },
|
|
20438
20459
|
{ fn: onCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
20439
20460
|
{ fn: onCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
20440
20461
|
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnMemberCountChanged },
|
|
@@ -20534,12 +20555,12 @@ class CommunitiesPaginationController extends PaginationController {
|
|
|
20534
20555
|
}
|
|
20535
20556
|
}
|
|
20536
20557
|
|
|
20537
|
-
var EnumCommunityActions$
|
|
20558
|
+
var EnumCommunityActions$3;
|
|
20538
20559
|
(function (EnumCommunityActions) {
|
|
20539
20560
|
EnumCommunityActions["OnCommunityCreated"] = "onCommunityCreated";
|
|
20540
20561
|
EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
|
|
20541
20562
|
EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
|
|
20542
|
-
})(EnumCommunityActions$
|
|
20563
|
+
})(EnumCommunityActions$3 || (EnumCommunityActions$3 = {}));
|
|
20543
20564
|
|
|
20544
20565
|
class CommunitiesQueryStreamController extends QueryStreamController {
|
|
20545
20566
|
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
@@ -20575,7 +20596,7 @@ class CommunitiesQueryStreamController extends QueryStreamController {
|
|
|
20575
20596
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
20576
20597
|
if (!collection)
|
|
20577
20598
|
return;
|
|
20578
|
-
if (this.query.displayName && action === EnumCommunityActions$
|
|
20599
|
+
if (this.query.displayName && action === EnumCommunityActions$3.OnCommunityCreated) {
|
|
20579
20600
|
return;
|
|
20580
20601
|
}
|
|
20581
20602
|
/*
|
|
@@ -20620,9 +20641,9 @@ class CommunityLiveCollectionController extends LiveCollectionController {
|
|
|
20620
20641
|
}
|
|
20621
20642
|
startSubscription() {
|
|
20622
20643
|
return this.queryStreamController.subscribeRTE([
|
|
20623
|
-
{ fn: onCommunityCreated, action: EnumCommunityActions$
|
|
20624
|
-
{ fn: onCommunityDeleted, action: EnumCommunityActions$
|
|
20625
|
-
{ fn: onCommunityUpdated, action: EnumCommunityActions$
|
|
20644
|
+
{ fn: onCommunityCreated, action: EnumCommunityActions$3.OnCommunityCreated },
|
|
20645
|
+
{ fn: onCommunityDeleted, action: EnumCommunityActions$3.OnCommunityDeleted },
|
|
20646
|
+
{ fn: onCommunityUpdated, action: EnumCommunityActions$3.OnCommunityUpdated },
|
|
20626
20647
|
{ fn: onCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
20627
20648
|
{ fn: onCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
20628
20649
|
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnMemberCountChanged },
|
|
@@ -20817,11 +20838,11 @@ class TrendingCommunitiesQueryStreamController extends QueryStreamController {
|
|
|
20817
20838
|
}
|
|
20818
20839
|
}
|
|
20819
20840
|
|
|
20820
|
-
var EnumCommunityActions$
|
|
20841
|
+
var EnumCommunityActions$2;
|
|
20821
20842
|
(function (EnumCommunityActions) {
|
|
20822
20843
|
EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
|
|
20823
20844
|
EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
|
|
20824
|
-
})(EnumCommunityActions$
|
|
20845
|
+
})(EnumCommunityActions$2 || (EnumCommunityActions$2 = {}));
|
|
20825
20846
|
|
|
20826
20847
|
class TrendingCommunityLiveCollectionController extends LiveCollectionController {
|
|
20827
20848
|
constructor(query, callback) {
|
|
@@ -20852,8 +20873,8 @@ class TrendingCommunityLiveCollectionController extends LiveCollectionController
|
|
|
20852
20873
|
}
|
|
20853
20874
|
startSubscription() {
|
|
20854
20875
|
return this.queryStreamController.subscribeRTE([
|
|
20855
|
-
{ fn: onCommunityDeleted, action: EnumCommunityActions$
|
|
20856
|
-
{ fn: onCommunityUpdated, action: EnumCommunityActions$
|
|
20876
|
+
{ fn: onCommunityDeleted, action: EnumCommunityActions$2.OnCommunityDeleted },
|
|
20877
|
+
{ fn: onCommunityUpdated, action: EnumCommunityActions$2.OnCommunityUpdated },
|
|
20857
20878
|
{ fn: onCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
20858
20879
|
{ fn: onCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
20859
20880
|
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnMemberCountChanged },
|
|
@@ -20979,11 +21000,11 @@ class RecommendedCommunitiesQueryStreamController extends QueryStreamController
|
|
|
20979
21000
|
}
|
|
20980
21001
|
}
|
|
20981
21002
|
|
|
20982
|
-
var EnumCommunityActions;
|
|
21003
|
+
var EnumCommunityActions$1;
|
|
20983
21004
|
(function (EnumCommunityActions) {
|
|
20984
21005
|
EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
|
|
20985
21006
|
EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
|
|
20986
|
-
})(EnumCommunityActions || (EnumCommunityActions = {}));
|
|
21007
|
+
})(EnumCommunityActions$1 || (EnumCommunityActions$1 = {}));
|
|
20987
21008
|
|
|
20988
21009
|
class RecommendedCommunityLiveCollectionController extends LiveCollectionController {
|
|
20989
21010
|
constructor(query, callback) {
|
|
@@ -21014,8 +21035,8 @@ class RecommendedCommunityLiveCollectionController extends LiveCollectionControl
|
|
|
21014
21035
|
}
|
|
21015
21036
|
startSubscription() {
|
|
21016
21037
|
return this.queryStreamController.subscribeRTE([
|
|
21017
|
-
{ fn: onCommunityDeleted, action: EnumCommunityActions.OnCommunityDeleted },
|
|
21018
|
-
{ fn: onCommunityUpdated, action: EnumCommunityActions.OnCommunityUpdated },
|
|
21038
|
+
{ fn: onCommunityDeleted, action: EnumCommunityActions$1.OnCommunityDeleted },
|
|
21039
|
+
{ fn: onCommunityUpdated, action: EnumCommunityActions$1.OnCommunityUpdated },
|
|
21019
21040
|
{ fn: onCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
21020
21041
|
{ fn: onCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
21021
21042
|
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnMemberCountChanged },
|
|
@@ -21083,6 +21104,201 @@ const getRecommendedCommunities = (params, callback, config) => {
|
|
|
21083
21104
|
};
|
|
21084
21105
|
/* end_public_function */
|
|
21085
21106
|
|
|
21107
|
+
class SemanticSearchCommunityPaginationController extends PaginationController {
|
|
21108
|
+
async getRequest(queryParams, token) {
|
|
21109
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, communityMembershipStatus } = queryParams, params = __rest(queryParams, ["limit", "communityMembershipStatus"]);
|
|
21110
|
+
const baseOptions = {
|
|
21111
|
+
type: queryParams.limit ? 'pagination' : undefined,
|
|
21112
|
+
};
|
|
21113
|
+
const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
|
|
21114
|
+
const { data: queryResponse } = await this.http.get(`/api/v1/semantic-search/communities`, {
|
|
21115
|
+
params: Object.assign(Object.assign({}, params), { filter: communityMembershipStatus !== null && communityMembershipStatus !== void 0 ? communityMembershipStatus : "all" /* AmityCommunityMemberStatusFilter.ALL */, options }),
|
|
21116
|
+
});
|
|
21117
|
+
return queryResponse;
|
|
21118
|
+
}
|
|
21119
|
+
}
|
|
21120
|
+
|
|
21121
|
+
function prepareSemanticCommunitiesReferenceId(response) {
|
|
21122
|
+
return response.communities.map(community => {
|
|
21123
|
+
const score = response.searchResult.find(result => result.communityId === community.communityId);
|
|
21124
|
+
return `${community.communityId}:${score}`;
|
|
21125
|
+
});
|
|
21126
|
+
}
|
|
21127
|
+
|
|
21128
|
+
class SemanticSearchCommunityQueryStreamController extends QueryStreamController {
|
|
21129
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
21130
|
+
super(query, cacheKey);
|
|
21131
|
+
this.notifyChange = notifyChange;
|
|
21132
|
+
this.preparePayload = preparePayload;
|
|
21133
|
+
}
|
|
21134
|
+
async saveToMainDB(response) {
|
|
21135
|
+
const processedPayload = this.preparePayload(response);
|
|
21136
|
+
const client = getActiveClient();
|
|
21137
|
+
const cachedAt = client.cache && Date.now();
|
|
21138
|
+
if (client.cache) {
|
|
21139
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
21140
|
+
}
|
|
21141
|
+
}
|
|
21142
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
21143
|
+
var _a, _b;
|
|
21144
|
+
if (refresh) {
|
|
21145
|
+
pushToCache(this.cacheKey, {
|
|
21146
|
+
data: prepareSemanticCommunitiesReferenceId(response),
|
|
21147
|
+
});
|
|
21148
|
+
}
|
|
21149
|
+
else {
|
|
21150
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
21151
|
+
const communities = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
21152
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...communities, ...prepareSemanticCommunitiesReferenceId(response)])] }));
|
|
21153
|
+
}
|
|
21154
|
+
}
|
|
21155
|
+
reactor(action) {
|
|
21156
|
+
return (community) => {
|
|
21157
|
+
var _a;
|
|
21158
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
21159
|
+
if (!collection)
|
|
21160
|
+
return;
|
|
21161
|
+
collection.data = [...new Set([community.communityId, ...collection.data])];
|
|
21162
|
+
pushToCache(this.cacheKey, collection);
|
|
21163
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
21164
|
+
};
|
|
21165
|
+
//
|
|
21166
|
+
}
|
|
21167
|
+
subscribeRTE(createSubscriber) {
|
|
21168
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
21169
|
+
}
|
|
21170
|
+
}
|
|
21171
|
+
|
|
21172
|
+
var EnumCommunityActions;
|
|
21173
|
+
(function (EnumCommunityActions) {
|
|
21174
|
+
EnumCommunityActions["OnCommunityCreated"] = "onCommunityCreated";
|
|
21175
|
+
EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
|
|
21176
|
+
EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
|
|
21177
|
+
})(EnumCommunityActions || (EnumCommunityActions = {}));
|
|
21178
|
+
|
|
21179
|
+
class SemanticSearchCommunityLiveCollectionController extends LiveCollectionController {
|
|
21180
|
+
constructor(query, callback) {
|
|
21181
|
+
const queryStreamId = hash__default["default"](query);
|
|
21182
|
+
const cacheKey = ['community', 'collection', queryStreamId];
|
|
21183
|
+
const paginationController = new SemanticSearchCommunityPaginationController(query);
|
|
21184
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
21185
|
+
this.query = query;
|
|
21186
|
+
this.queryStreamController = new SemanticSearchCommunityQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareSemanticSearchCommunityPayload);
|
|
21187
|
+
this.callback = callback.bind(this);
|
|
21188
|
+
this.loadPage({ initial: true });
|
|
21189
|
+
}
|
|
21190
|
+
setup() {
|
|
21191
|
+
var _a;
|
|
21192
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
21193
|
+
if (!collection) {
|
|
21194
|
+
pushToCache(this.cacheKey, {
|
|
21195
|
+
data: [],
|
|
21196
|
+
params: {},
|
|
21197
|
+
});
|
|
21198
|
+
}
|
|
21199
|
+
}
|
|
21200
|
+
async persistModel(queryPayload) {
|
|
21201
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
21202
|
+
}
|
|
21203
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
21204
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
21205
|
+
}
|
|
21206
|
+
startSubscription() {
|
|
21207
|
+
return this.queryStreamController.subscribeRTE([
|
|
21208
|
+
{ fn: onCommunityCreated, action: EnumCommunityActions.OnCommunityCreated },
|
|
21209
|
+
{ fn: onCommunityDeleted, action: EnumCommunityActions.OnCommunityDeleted },
|
|
21210
|
+
{ fn: onCommunityUpdated, action: EnumCommunityActions.OnCommunityUpdated },
|
|
21211
|
+
{ fn: onCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
21212
|
+
{ fn: onCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
21213
|
+
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnMemberCountChanged },
|
|
21214
|
+
{ fn: onLocalCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
21215
|
+
{ fn: onLocalCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
21216
|
+
]);
|
|
21217
|
+
}
|
|
21218
|
+
notifyChange({ origin, loading, error }) {
|
|
21219
|
+
var _a, _b;
|
|
21220
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
21221
|
+
if (!collection)
|
|
21222
|
+
return;
|
|
21223
|
+
const data = this.applyFilter((_b = collection.data
|
|
21224
|
+
.map(communityIdWithScore => {
|
|
21225
|
+
const [communityId, score] = communityIdWithScore.split(':');
|
|
21226
|
+
return {
|
|
21227
|
+
communityId,
|
|
21228
|
+
score: parseFloat(score),
|
|
21229
|
+
};
|
|
21230
|
+
})
|
|
21231
|
+
.sort((a, b) => b.score - a.score)
|
|
21232
|
+
.map(({ communityId }) => pullFromCache(['community', 'get', communityId]))
|
|
21233
|
+
.filter(isNonNullable)
|
|
21234
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
|
|
21235
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
21236
|
+
return;
|
|
21237
|
+
this.callback({
|
|
21238
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
21239
|
+
data,
|
|
21240
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
21241
|
+
loading,
|
|
21242
|
+
error,
|
|
21243
|
+
});
|
|
21244
|
+
}
|
|
21245
|
+
applyFilter(data) {
|
|
21246
|
+
const { userId } = getActiveClient();
|
|
21247
|
+
let communities = data;
|
|
21248
|
+
if (this.query.categoryIds) {
|
|
21249
|
+
communities = communities.filter(c => {
|
|
21250
|
+
var _a;
|
|
21251
|
+
return (_a = c.categoryIds) === null || _a === void 0 ? void 0 : _a.some((id) => {
|
|
21252
|
+
if (!this.query.categoryIds)
|
|
21253
|
+
return true;
|
|
21254
|
+
if (this.query.categoryIds.length === 0)
|
|
21255
|
+
return true;
|
|
21256
|
+
return this.query.categoryIds.includes(id);
|
|
21257
|
+
});
|
|
21258
|
+
});
|
|
21259
|
+
}
|
|
21260
|
+
if (this.query.tags) {
|
|
21261
|
+
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); }); });
|
|
21262
|
+
}
|
|
21263
|
+
if (this.query.communityMembershipStatus && userId) {
|
|
21264
|
+
communities = filterByCommunityMembership(communities, this.query.communityMembershipStatus, userId);
|
|
21265
|
+
}
|
|
21266
|
+
return communities;
|
|
21267
|
+
}
|
|
21268
|
+
}
|
|
21269
|
+
|
|
21270
|
+
/**
|
|
21271
|
+
* search posts by semantic search
|
|
21272
|
+
*
|
|
21273
|
+
* @returns the associated pinned post(s)
|
|
21274
|
+
*
|
|
21275
|
+
* @category Posts Live Collection
|
|
21276
|
+
*
|
|
21277
|
+
*/
|
|
21278
|
+
const semanticSearchCommunities = (params, callback, config) => {
|
|
21279
|
+
const { log, cache } = getActiveClient();
|
|
21280
|
+
if (!cache) {
|
|
21281
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
21282
|
+
}
|
|
21283
|
+
const timestamp = Date.now();
|
|
21284
|
+
log(`semanticSearchCommunities(tmpid: ${timestamp}) > listen`);
|
|
21285
|
+
const semanticSearchPostLiveCollection = new SemanticSearchCommunityLiveCollectionController(params, callback);
|
|
21286
|
+
const disposers = semanticSearchPostLiveCollection.startSubscription();
|
|
21287
|
+
const cacheKey = semanticSearchPostLiveCollection.getCacheKey();
|
|
21288
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
21289
|
+
return () => {
|
|
21290
|
+
log(`semanticSearchCommunities(tmpid: ${timestamp}) > dispose`);
|
|
21291
|
+
disposers.forEach(fn => fn());
|
|
21292
|
+
};
|
|
21293
|
+
};
|
|
21294
|
+
|
|
21295
|
+
var AmityCommunityMemberStatusFilter;
|
|
21296
|
+
(function (AmityCommunityMemberStatusFilter) {
|
|
21297
|
+
AmityCommunityMemberStatusFilter["ALL"] = "all";
|
|
21298
|
+
AmityCommunityMemberStatusFilter["MEMBER"] = "member";
|
|
21299
|
+
AmityCommunityMemberStatusFilter["NOT_MEMBER"] = "notMember";
|
|
21300
|
+
})(AmityCommunityMemberStatusFilter || (AmityCommunityMemberStatusFilter = {}));
|
|
21301
|
+
|
|
21086
21302
|
/* begin_public_function
|
|
21087
21303
|
id: community.moderation.add_roles
|
|
21088
21304
|
*/
|
|
@@ -21246,7 +21462,9 @@ var index$9 = /*#__PURE__*/Object.freeze({
|
|
|
21246
21462
|
getCommunities: getCommunities,
|
|
21247
21463
|
getCommunity: getCommunity,
|
|
21248
21464
|
getTrendingCommunities: getTrendingCommunities,
|
|
21249
|
-
getRecommendedCommunities: getRecommendedCommunities
|
|
21465
|
+
getRecommendedCommunities: getRecommendedCommunities,
|
|
21466
|
+
semanticSearchCommunities: semanticSearchCommunities,
|
|
21467
|
+
get AmityCommunityMemberStatusFilter () { return AmityCommunityMemberStatusFilter; }
|
|
21250
21468
|
});
|
|
21251
21469
|
|
|
21252
21470
|
/* begin_public_function
|
|
@@ -25125,7 +25343,7 @@ var index$3 = /*#__PURE__*/Object.freeze({
|
|
|
25125
25343
|
getPoll: getPoll
|
|
25126
25344
|
});
|
|
25127
25345
|
|
|
25128
|
-
const privateKey = "-----BEGIN PRIVATE KEY-----\
|
|
25346
|
+
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-----";
|
|
25129
25347
|
/*
|
|
25130
25348
|
* The crypto algorithm used for importing key and signing string
|
|
25131
25349
|
*/
|